Skip to content

Commit

Permalink
Merge pull request SFTtech#1061 from TheJJ/events-no-unistd
Browse files Browse the repository at this point in the history
event: remove usage of unistd.h
  • Loading branch information
TheJJ authored Oct 19, 2018
2 parents c45f897 + 23e67a0 commit 6768a3a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
2 changes: 0 additions & 2 deletions libopenage/event/demo/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
#include <ncurses.h>
#include <vector>

#include <unistd.h>


namespace openage::event::demo {

Expand Down
14 changes: 7 additions & 7 deletions libopenage/event/demo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include <chrono>
#include <ratio>
#include <unistd.h>
#include <SDL.h>

#include "../../config.h"
#include "../event.h"
Expand Down Expand Up @@ -153,7 +153,7 @@ void curvepong(bool disable_gui, bool no_human) {

// handle timing for screen refresh and simulation advancement
using dt_s_t = std::chrono::duration<double, std::ratio<1>>;
using dt_us_t = std::chrono::duration<double, std::micro>;
using dt_ms_t = std::chrono::duration<double, std::milli>;

// microseconds per frame
// 30fps = 1s/30 = 1000000us/30 per frame
Expand All @@ -162,16 +162,16 @@ void curvepong(bool disable_gui, bool no_human) {

if (speed == timescale::NOSLEEP) {
// increase the simulation loop time a bit
usleep(5000);
SDL_Delay(5);
}

dt_us_t dt_us = Clock::now() - loop_start;
dt_ms_t dt_us = Clock::now() - loop_start;

if (speed != timescale::NOSLEEP) {
dt_us_t wait_time = per_frame - dt_us;
dt_ms_t wait_time = per_frame - dt_us;

if (wait_time > dt_us_t::zero()) {
usleep(wait_time.count());
if (wait_time > dt_ms_t::zero()) {
SDL_Delay(wait_time.count());
}
}

Expand Down

0 comments on commit 6768a3a

Please sign in to comment.