improved synchronization of main game loop
authorHolger Schemel <info@artsoft.org>
Tue, 2 Feb 2016 23:34:17 +0000 (00:34 +0100)
committerHolger Schemel <info@artsoft.org>
Wed, 3 Feb 2016 00:02:51 +0000 (01:02 +0100)
src/events.c

index 7282236ff8609522682938faca0ad99c59dbf80b..952f8995f602cdec1a475dd9c4fd76211138d907 100644 (file)
@@ -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;
   }