Skip to content

Instantly share code, notes, and snippets.

@michicc
Last active January 10, 2021 18:08
Show Gist options
  • Save michicc/2536e5d15bd268cde4d365205a6f61ff to your computer and use it in GitHub Desktop.
Save michicc/2536e5d15bd268cde4d365205a6f61ff to your computer and use it in GitHub Desktop.
OSX std::chrono
diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm
index 8a43945f5..a455ccb76 100644
--- a/src/video/cocoa/event.mm
+++ b/src/video/cocoa/event.mm
@@ -619,10 +619,6 @@ static bool QZ_PollEvent()
void VideoDriver_Cocoa::GameLoop()
{
- uint32 cur_ticks = GetTick();
- uint32 last_cur_ticks = cur_ticks;
- uint32 next_tick = cur_ticks + MILLISECONDS_PER_TICK;
-
#ifdef _DEBUG
uint32 et0 = GetTick();
uint32 st = 0;
@@ -646,8 +642,11 @@ void VideoDriver_Cocoa::GameLoop()
QZ_CheckPaletteAnim();
_cocoa_subdriver->Draw(true);
+ auto cur_ticks = std::chrono::steady_clock::now();
+ auto last_cur_ticks = cur_ticks;
+ auto next_tick = cur_ticks + std::chrono::milliseconds(MILLISECONDS_PER_TICK);
+
for (;;) {
- uint32 prev_cur_ticks = cur_ticks; // to check for wrapping
InteractiveRandom(); // randomness
while (QZ_PollEvent()) {}
@@ -669,11 +668,11 @@ void VideoDriver_Cocoa::GameLoop()
_fast_forward = 0;
}
- cur_ticks = GetTick();
- if (cur_ticks >= next_tick || (_fast_forward && !_pause_mode) || cur_ticks < prev_cur_ticks) {
- _realtime_tick += cur_ticks - last_cur_ticks;
+ cur_ticks = std::chrono::steady_clock::now();
+ if (cur_ticks >= next_tick || (_fast_forward && !_pause_mode)) {
+ _realtime_tick += std::chrono::duration_cast<std::chrono::milliseconds>(cur_ticks - last_cur_ticks).count();
last_cur_ticks = cur_ticks;
- next_tick = cur_ticks + MILLISECONDS_PER_TICK;
+ next_tick = cur_ticks + std::chrono::milliseconds(MILLISECONDS_PER_TICK);
bool old_ctrl_pressed = _ctrl_pressed;
diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm
index 8a43945f5..0c71adb9b 100644
--- a/src/video/cocoa/event.mm
+++ b/src/video/cocoa/event.mm
@@ -686,7 +685,7 @@ void VideoDriver_Cocoa::GameLoop()
UpdateWindows();
QZ_CheckPaletteAnim();
- _cocoa_subdriver->Draw();
+ _cocoa_subdriver->Draw(_fullscreen);
} else {
#ifdef _DEBUG
uint32 st0 = GetTick();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment