From: Holger Schemel Date: Tue, 2 Feb 2016 23:34:17 +0000 (+0100) Subject: improved synchronization of main game loop X-Git-Tag: 4.0.0.0-rc1~90 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=0229cbe9c9f7d6969ac5ca96eb6b525a9fe3ccf4;p=rocksndiamonds.git improved synchronization of main game loop --- diff --git a/src/events.c b/src/events.c index 7282236f..952f8995 100644 --- a/src/events.c +++ b/src/events.c @@ -154,6 +154,9 @@ boolean NextValidEvent(Event *event) void EventLoop(void) { + static unsigned int sync_frame_delay = 0; + unsigned int sync_frame_delay_value = GAME_FRAME_DELAY; + while (1) { if (PendingEvent()) /* got event */ @@ -247,18 +250,14 @@ void EventLoop(void) has its own synchronization and is CPU friendly, too */ if (game_status == GAME_MODE_PLAYING) - { HandleGameActions(); - } - else - { - if (!PendingEvent()) /* delay only if no pending events */ - Delay(10); - } /* refresh window contents from drawing buffer, if needed */ BackToFront(); + if (game_status != GAME_MODE_PLAYING) + WaitUntilDelayReached(&sync_frame_delay, sync_frame_delay_value); + if (game_status == GAME_MODE_QUIT) return; }