added delay counter data type and adjusted related functions
authorHolger Schemel <info@artsoft.org>
Thu, 21 Jul 2022 13:51:43 +0000 (15:51 +0200)
committerHolger Schemel <info@artsoft.org>
Thu, 21 Jul 2022 13:51:43 +0000 (15:51 +0200)
20 files changed:
src/anim.c
src/editor.c
src/events.c
src/game.c
src/game.h
src/game_mm/export.h
src/game_mm/mm_game.c
src/game_mm/mm_tools.c
src/init.c
src/libgame/gadgets.c
src/libgame/misc.c
src/libgame/misc.h
src/libgame/sdl.c
src/libgame/sound.c
src/libgame/system.c
src/libgame/system.h
src/libgame/types.h
src/screens.c
src/tape.c
src/tools.c

index 7f6691f0fac1f6c82a4fc7909fa457c97b3b9175..aa005263a2f03c0feb619382b0ebdd60398fb5ad 100644 (file)
@@ -124,7 +124,8 @@ struct GlobalAnimPartControlInfo
 
   unsigned int initial_anim_sync_frame;
   unsigned int anim_random_frame;
-  unsigned int step_delay, step_delay_value;
+
+  DelayCounter step_delay;
 
   int init_delay_counter;
   int anim_delay_counter;
@@ -436,8 +437,8 @@ static void InitToonControls(void)
     part->initial_anim_sync_frame = 0;
     part->anim_random_frame = -1;
 
-    part->step_delay = 0;
-    part->step_delay_value = graphic_info[control].step_delay;
+    part->step_delay.count = 0;
+    part->step_delay.value = graphic_info[control].step_delay;
 
     part->state = ANIM_STATE_INACTIVE;
     part->last_anim_status = -1;
@@ -543,8 +544,8 @@ static void InitGlobalAnimControls(void)
        part->initial_anim_sync_frame = 0;
        part->anim_random_frame = -1;
 
-       part->step_delay = 0;
-       part->step_delay_value = graphic_info[control].step_delay;
+       part->step_delay.count = 0;
+       part->step_delay.value = graphic_info[control].step_delay;
 
        part->state = ANIM_STATE_INACTIVE;
        part->last_anim_status = -1;
@@ -1531,8 +1532,7 @@ static int HandleGlobalAnim_Part(struct GlobalAnimPartControlInfo *part,
   // special case to prevent expiring loop sounds when playing
   PlayGlobalAnimSoundIfLoop(part);
 
-  if (!DelayReachedExt(&part->step_delay, part->step_delay_value,
-                      anim_sync_frame))
+  if (!DelayReachedExt(&part->step_delay, anim_sync_frame))
     return ANIM_STATE_RUNNING;
 
 #if 0
index e5d956709d9408f9c96090a185d2677de2669727..bf16751ffef420bdfb72948c17e2fd6daffd1502 100644 (file)
@@ -14524,11 +14524,12 @@ static void HandleLevelEditorIdle_Properties(void)
   int element_border = graphic_info[IMG_EDITOR_ELEMENT_BORDER].border_size;
   int x = editor.settings.element_graphic.x + element_border;
   int y = editor.settings.element_graphic.y + element_border;
-  static unsigned int action_delay = 0;
-  unsigned int action_delay_value = GameFrameDelay;
+  static DelayCounter action_delay = { 0 };
   int i;
 
-  if (!DelayReached(&action_delay, action_delay_value))
+  action_delay.value = GameFrameDelay;
+
+  if (!DelayReached(&action_delay))
     return;
 
   for (i = 0; i < ED_NUM_SELECTBOX; i++)
index 4a31bcd6539140624d9e8f0c25f1f7523dc40fc7..f73e48847f172907b7eaadae7134d812405f613b 100644 (file)
@@ -36,8 +36,7 @@
 
 static boolean cursor_inside_playfield = FALSE;
 static int cursor_mode_last = CURSOR_DEFAULT;
-static unsigned int special_cursor_delay = 0;
-static unsigned int special_cursor_delay_value = 1000;
+static DelayCounter special_cursor_delay = { 1000 };
 static boolean special_cursor_enabled = FALSE;
 
 static boolean stop_processing_events = FALSE;
@@ -211,8 +210,7 @@ void StopProcessingEvents(void)
 static void HandleEvents(void)
 {
   Event event;
-  unsigned int event_frame_delay = 0;
-  unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
+  DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
 
   ResetDelayCounter(&event_frame_delay);
 
@@ -277,7 +275,7 @@ static void HandleEvents(void)
       ResetDelayCounter(&event_frame_delay);
 
     // do not handle events for longer than standard frame delay period
-    if (DelayReached(&event_frame_delay, event_frame_delay_value))
+    if (DelayReached(&event_frame_delay))
       break;
 
     // do not handle any further events if triggered by a special flag
@@ -330,7 +328,7 @@ static void HandleMouseCursor(void)
     // when showing title screens, hide mouse pointer (if not moved)
 
     if (gfx.cursor_mode != CURSOR_NONE &&
-       DelayReached(&special_cursor_delay, special_cursor_delay_value))
+       DelayReached(&special_cursor_delay))
     {
       SetMouseCursor(CURSOR_NONE);
     }
@@ -347,7 +345,7 @@ static void HandleMouseCursor(void)
     if (gfx.cursor_mode != CURSOR_PLAYFIELD &&
        cursor_inside_playfield &&
        special_cursor_enabled &&
-       DelayReached(&special_cursor_delay, special_cursor_delay_value))
+       DelayReached(&special_cursor_delay))
     {
       SetMouseCursor(CURSOR_PLAYFIELD);
     }
@@ -2589,8 +2587,7 @@ static int HandleJoystickForAllPlayers(void)
 
 void HandleJoystick(void)
 {
-  static unsigned int joytest_delay = 0;
-  static unsigned int joytest_delay_value = GADGET_FRAME_DELAY;
+  static DelayCounter joytest_delay = { GADGET_FRAME_DELAY };
   static int joytest_last = 0;
   int delay_value_first = GADGET_FRAME_DELAY_FIRST;
   int delay_value       = GADGET_FRAME_DELAY;
@@ -2648,7 +2645,7 @@ void HandleJoystick(void)
   if (dx || dy || button)
     SetPlayfieldMouseCursorEnabled(TRUE);
 
-  if (joytest && !button && !DelayReached(&joytest_delay, joytest_delay_value))
+  if (joytest && !button && !DelayReached(&joytest_delay))
   {
     // delay joystick/keyboard actions if axes/keys continually pressed
     newbutton = dx = dy = 0;
@@ -2656,7 +2653,7 @@ void HandleJoystick(void)
   else
   {
     // first start with longer delay, then continue with shorter delay
-    joytest_delay_value =
+    joytest_delay.value =
       (use_delay_value_first ? delay_value_first : delay_value);
   }
 
index ce452e67efc236e49f1615de39f27c00480a3809..aa7d824db483a850f1f49d0a34dc058289e8ff60 100644 (file)
@@ -3680,7 +3680,8 @@ void InitGame(void)
 
     player->can_fall_into_acid = CAN_MOVE_INTO_ACID(player->element_nr);
 
-    player->actual_frame_counter = 0;
+    player->actual_frame_counter.count = 0;
+    player->actual_frame_counter.value = 1;
 
     player->step_counter = 0;
 
@@ -9139,17 +9140,16 @@ static void AmoebaToDiamondBD(int ax, int ay, int new_element)
 
 static void AmoebaGrowing(int x, int y)
 {
-  static unsigned int sound_delay = 0;
-  static unsigned int sound_delay_value = 0;
+  static DelayCounter sound_delay = { 0 };
 
   if (!MovDelay[x][y])         // start new growing cycle
   {
     MovDelay[x][y] = 7;
 
-    if (DelayReached(&sound_delay, sound_delay_value))
+    if (DelayReached(&sound_delay))
     {
       PlayLevelSoundElementAction(x, y, Store[x][y], ACTION_GROWING);
-      sound_delay_value = 30;
+      sound_delay.value = 30;
     }
   }
 
@@ -9175,15 +9175,14 @@ static void AmoebaGrowing(int x, int y)
 
 static void AmoebaShrinking(int x, int y)
 {
-  static unsigned int sound_delay = 0;
-  static unsigned int sound_delay_value = 0;
+  static DelayCounter sound_delay = { 0 };
 
   if (!MovDelay[x][y])         // start new shrinking cycle
   {
     MovDelay[x][y] = 7;
 
-    if (DelayReached(&sound_delay, sound_delay_value))
-      sound_delay_value = 30;
+    if (DelayReached(&sound_delay))
+      sound_delay.value = 30;
   }
 
   if (MovDelay[x][y])          // wait some time before shrinking
@@ -13196,7 +13195,7 @@ void ScrollPlayer(struct PlayerInfo *player, int mode)
 
   if (mode == SCROLL_INIT)
   {
-    player->actual_frame_counter = FrameCounter;
+    player->actual_frame_counter.count = FrameCounter;
     player->GfxPos = move_stepsize * (player->MovPos / move_stepsize);
 
     if ((player->block_last_field || player->block_delay_adjustment > 0) &&
@@ -13225,7 +13224,7 @@ void ScrollPlayer(struct PlayerInfo *player, int mode)
     if (player->MovPos != 0)   // player has not yet reached destination
       return;
   }
-  else if (!FrameReached(&player->actual_frame_counter, 1))
+  else if (!FrameReached(&player->actual_frame_counter))
     return;
 
   if (player->MovPos != 0)
@@ -13348,20 +13347,22 @@ void ScrollPlayer(struct PlayerInfo *player, int mode)
 
 void ScrollScreen(struct PlayerInfo *player, int mode)
 {
-  static unsigned int screen_frame_counter = 0;
+  static DelayCounter screen_frame_counter = { 0 };
 
   if (mode == SCROLL_INIT)
   {
     // set scrolling step size according to actual player's moving speed
     ScrollStepSize = TILEX / player->move_delay_value;
 
-    screen_frame_counter = FrameCounter;
+    screen_frame_counter.count = FrameCounter;
+    screen_frame_counter.value = 1;
+
     ScreenMovDir = player->MovDir;
     ScreenMovPos = player->MovPos;
     ScreenGfxPos = ScrollStepSize * (ScreenMovPos / ScrollStepSize);
     return;
   }
-  else if (!FrameReached(&screen_frame_counter, 1))
+  else if (!FrameReached(&screen_frame_counter))
     return;
 
   if (ScreenMovPos)
index 600485eaf3d7239e9d28c9f753b14b27bc09d12c..26c186fe6df4cf457180ecdf1b7e9b6dc5f477a3 100644 (file)
@@ -379,7 +379,7 @@ struct PlayerInfo
   int push_delay;
   int push_delay_value;
 
-  unsigned int actual_frame_counter;
+  DelayCounter actual_frame_counter;
 
   int drop_delay;
   int drop_pressed_delay;
index 4a63b249eacd7d71580a27394f4db1c8b2b3d304..710d2ee9311d1abe6af475c703ae30880a12ebb9 100644 (file)
@@ -193,10 +193,10 @@ struct EngineSnapshotInfo_MM
   int hold_x, hold_y;
   int pacman_nr;
 
-  unsigned int rotate_delay;
-  unsigned int pacman_delay;
-  unsigned int energy_delay;
-  unsigned int overload_delay;
+  DelayCounter rotate_delay;
+  DelayCounter pacman_delay;
+  DelayCounter energy_delay;
+  DelayCounter overload_delay;
 };
 
 
index c97a7d3b09f0583080681e20d6bf168b080d077d..0403795fcf48c21e334e4368807ce6180626b4c0 100644 (file)
@@ -111,10 +111,10 @@ static int hold_x = -1, hold_y = -1;
 static int pacman_nr = -1;
 
 // various game engine delay counters
-static unsigned int rotate_delay = 0;
-static unsigned int pacman_delay = 0;
-static unsigned int energy_delay = 0;
-static unsigned int overload_delay = 0;
+static DelayCounter rotate_delay = { AUTO_ROTATE_DELAY };
+static DelayCounter pacman_delay = { PACMAN_MOVE_DELAY };
+static DelayCounter energy_delay = { ENERGY_DELAY };
+static DelayCounter overload_delay = { 0 };
 
 // element masks for scanning pixels of MM elements
 static const char mm_masks[10][16][16 + 1] =
@@ -637,10 +637,10 @@ void InitGameEngine_MM(void)
 
   CT = Ct = 0;
 
-  rotate_delay = 0;
-  pacman_delay = 0;
-  energy_delay = 0;
-  overload_delay = 0;
+  rotate_delay.count = 0;
+  pacman_delay.count = 0;
+  energy_delay.count = 0;
+  overload_delay.count = 0;
 
   ClickElement(-1, -1, -1);
 
@@ -2709,8 +2709,7 @@ static void ContinueMoving_MM(int x, int y)
 
 boolean ClickElement(int x, int y, int button)
 {
-  static unsigned int click_delay = 0;
-  static int click_delay_value = CLICK_DELAY;
+  static DelayCounter click_delay = { CLICK_DELAY };
   static boolean new_button = TRUE;
   boolean element_clicked = FALSE;
   int element;
@@ -2718,8 +2717,8 @@ boolean ClickElement(int x, int y, int button)
   if (button == -1)
   {
     // initialize static variables
-    click_delay = 0;
-    click_delay_value = CLICK_DELAY;
+    click_delay.count = 0;
+    click_delay.value = CLICK_DELAY;
     new_button = TRUE;
 
     return FALSE;
@@ -2732,7 +2731,7 @@ boolean ClickElement(int x, int y, int button)
   if (button == MB_RELEASED)
   {
     new_button = TRUE;
-    click_delay_value = CLICK_DELAY;
+    click_delay.value = CLICK_DELAY;
 
     // release eventually hold auto-rotating mirror
     RotateMirror(x, y, MB_RELEASED);
@@ -2740,7 +2739,7 @@ boolean ClickElement(int x, int y, int button)
     return FALSE;
   }
 
-  if (!FrameReached(&click_delay, click_delay_value) && !new_button)
+  if (!FrameReached(&click_delay) && !new_button)
     return FALSE;
 
   if (button == MB_MIDDLEBUTTON)       // middle button has no function
@@ -2827,7 +2826,7 @@ boolean ClickElement(int x, int y, int button)
     element_clicked = TRUE;
   }
 
-  click_delay_value = (new_button ? CLICK_DELAY_FIRST : CLICK_DELAY);
+  click_delay.value = (new_button ? CLICK_DELAY_FIRST : CLICK_DELAY);
   new_button = FALSE;
 
   return element_clicked;
@@ -2932,7 +2931,7 @@ static void AutoRotateMirrors(void)
 {
   int x, y;
 
-  if (!FrameReached(&rotate_delay, AUTO_ROTATE_DELAY))
+  if (!FrameReached(&rotate_delay))
     return;
 
   for (x = 0; x < lev_fieldx; x++)
@@ -3100,7 +3099,7 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
 
   CT = FrameCounter;
 
-  if (game_mm.num_pacman && FrameReached(&pacman_delay, PACMAN_MOVE_DELAY))
+  if (game_mm.num_pacman && FrameReached(&pacman_delay))
   {
     MovePacMen();
 
@@ -3111,7 +3110,7 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
     }
   }
 
-  if (FrameReached(&energy_delay, ENERGY_DELAY))
+  if (FrameReached(&energy_delay))
   {
     if (game_mm.energy_left > 0)
     {
@@ -3177,9 +3176,11 @@ static void GameActions_MM_Ext(struct MouseActionInfo action, boolean warp_mode)
       !IS_WALL_AMOEBA(element))
     return;
 
+  overload_delay.value = HEALTH_DELAY(laser.overloaded);
+
   if (((laser.overloaded && laser.overload_value < MAX_LASER_OVERLOAD) ||
        (!laser.overloaded && laser.overload_value > 0)) &&
-      FrameReached(&overload_delay, HEALTH_DELAY(laser.overloaded)))
+      FrameReached(&overload_delay))
   {
     if (laser.overloaded)
       laser.overload_value++;
index 21ad08144351dab725e4e6ec23be4330767a3056..044c83a3484aa056c22a3f8b80e688749f96ea80 100644 (file)
@@ -899,16 +899,11 @@ static void DrawTileCursor_Xsn(int draw_target)
   static boolean started = FALSE;
   static boolean active = FALSE;
   static boolean debug = FALSE;
-  static unsigned int check_delay = 0;
-  static unsigned int start_delay = 0;
-  static unsigned int growth_delay = 0;
-  static unsigned int update_delay = 0;
-  static unsigned int change_delay = 0;
-  static unsigned int check_delay_value = XSN_CHECK_DELAY * 1000;
-  static unsigned int start_delay_value = 0;
-  static unsigned int growth_delay_value = 0;
-  static unsigned int update_delay_value = 0;
-  static unsigned int change_delay_value = 0;
+  static DelayCounter check_delay = { XSN_CHECK_DELAY * 1000 };
+  static DelayCounter start_delay = { 0 };
+  static DelayCounter growth_delay = { 0 };
+  static DelayCounter update_delay = { 0 };
+  static DelayCounter change_delay = { 0 };
   static int percent = 0;
   static int debug_value = 0;
   boolean reinitialize = FALSE;
@@ -918,7 +913,7 @@ static void DrawTileCursor_Xsn(int draw_target)
   if (draw_target != DRAW_TO_SCREEN)
     return;
 
-  if (DelayReached(&check_delay, check_delay_value))
+  if (DelayReached(&check_delay))
   {
     percent = (debug ? debug_value * 100 / XSN_DEBUG_STEPS : xsn_percent());
 
@@ -996,7 +991,7 @@ static void DrawTileCursor_Xsn(int draw_target)
 
   if (!active_last)
   {
-    start_delay_value = (debug || setup.debug.xsn_mode == TRUE ? 0 :
+    start_delay.value = (debug || setup.debug.xsn_mode == TRUE ? 0 :
                         (XSN_START_DELAY + XSN_RND(XSN_START_DELAY)) * 1000);
     started = FALSE;
 
@@ -1072,12 +1067,12 @@ static void DrawTileCursor_Xsn(int draw_target)
 
   if (!started)
   {
-    if (!DelayReached(&start_delay, start_delay_value))
+    if (!DelayReached(&start_delay))
       return;
 
-    update_delay_value = XSN_UPDATE_DELAY;
-    growth_delay_value = XSN_GROWTH_DELAY * 1000;
-    change_delay_value = XSN_CHANGE_DELAY * 1000;
+    update_delay.value = XSN_UPDATE_DELAY;
+    growth_delay.value = XSN_GROWTH_DELAY * 1000;
+    change_delay.value = XSN_CHANGE_DELAY * 1000;
 
     ResetDelayCounter(&growth_delay);
     ResetDelayCounter(&update_delay);
@@ -1088,24 +1083,24 @@ static void DrawTileCursor_Xsn(int draw_target)
 
   if (xsn.num_items < xsn.max_items)
   {
-    if (DelayReached(&growth_delay, growth_delay_value))
+    if (DelayReached(&growth_delay))
     {
       xsn.num_items += XSN_RND(XSN_GROWTH_RATE * 2);
       xsn.num_items = MIN(xsn.num_items, xsn.max_items);
     }
   }
 
-  if (DelayReached(&update_delay, update_delay_value))
+  if (DelayReached(&update_delay))
   {
     for (i = 0; i < xsn.num_items; i++)
       xsn_update_item(i);
   }
 
-  if (DelayReached(&change_delay, change_delay_value))
+  if (DelayReached(&change_delay))
   {
     xsn_update_change();
 
-    change_delay_value = xsn.change_delay * 1000;
+    change_delay.value = xsn.change_delay * 1000;
   }
 
   int xsn_alpha_dx = (gfx.mouse_y > xsn.area_ysize - xsn.max_height ?
index 727dcf30be2cfe03197b82bd9d436bf4dfdb808c..7f9821bf0d1f7a2d53adf17a3c8d20fdf1ba01a5 100644 (file)
@@ -138,11 +138,12 @@ static void DrawInitAnim(boolean only_when_loading)
                              game_status == GAME_MODE_LOADING ?
                              &init_last.busy :
                              &init_last.busy_playfield);
-  static unsigned int action_delay = 0;
-  unsigned int action_delay_value = GameFrameDelay;
+  static DelayCounter action_delay = { 0 };
   int sync_frame = FrameCounter;
   int x, y;
 
+  action_delay.value = GameFrameDelay;
+
   // prevent OS (Windows) from complaining about program not responding
   CheckQuitEvent();
 
@@ -152,7 +153,7 @@ static void DrawInitAnim(boolean only_when_loading)
   if (image_initial[graphic].bitmap == NULL || window == NULL)
     return;
 
-  if (!DelayReached(&action_delay, action_delay_value))
+  if (!DelayReached(&action_delay))
     return;
 
   if (busy->x == -1)
@@ -6610,8 +6611,7 @@ void OpenAll(void)
 
 static boolean WaitForApiThreads(void)
 {
-  unsigned int thread_delay = 0;
-  unsigned int thread_delay_value = 10000;
+  DelayCounter thread_delay = { 10000 };
 
   if (program.api_thread_count == 0)
     return TRUE;
@@ -6627,7 +6627,7 @@ static boolean WaitForApiThreads(void)
   // wait for threads to finish (and fail on timeout)
   while (program.api_thread_count > 0)
   {
-    if (DelayReached(&thread_delay, thread_delay_value))
+    if (DelayReached(&thread_delay))
     {
       Error("failed waiting for threads - TIMEOUT");
 
index e788b754366263ee773818a0f8362cba0880f7a2..94fe74551cdd58ed60a001afd742c412cc2e1735 100644 (file)
@@ -1629,8 +1629,7 @@ void ClickOnGadget(struct GadgetInfo *gi, int button)
 
 boolean HandleGadgets(int mx, int my, int button)
 {
-  static unsigned int pressed_delay = 0;
-  static unsigned int pressed_delay_value = GADGET_FRAME_DELAY;
+  static DelayCounter pressed_delay = { GADGET_FRAME_DELAY };
   static int last_button = 0;
   static int last_mx = 0, last_my = 0;
   static int pressed_mx = 0, pressed_my = 0;
@@ -1756,7 +1755,7 @@ boolean HandleGadgets(int mx, int my, int button)
     (button != 0 && last_gi != NULL && new_gi == last_gi);
 
   gadget_pressed_delay_reached =
-    DelayReached(&pressed_delay, pressed_delay_value);
+    DelayReached(&pressed_delay);
 
   gadget_released =            (release_event && last_gi != NULL);
   gadget_released_inside =     (gadget_released && new_gi == last_gi);
@@ -1937,12 +1936,12 @@ boolean HandleGadgets(int mx, int my, int button)
       ResetDelayCounter(&pressed_delay);
 
       // start gadget delay with longer delay after first click on gadget
-      pressed_delay_value = GADGET_FRAME_DELAY_FIRST;
+      pressed_delay.value = GADGET_FRAME_DELAY_FIRST;
     }
     else                       // gadget hold pressed for some time
     {
       // after first repeated gadget click, continue with shorter delay value
-      pressed_delay_value = GADGET_FRAME_DELAY;
+      pressed_delay.value = GADGET_FRAME_DELAY;
     }
 
     if (gi->type & GD_TYPE_SCROLLBAR && !gadget_dragging)
index 7b82420cf6dade4071cbc3a4571ecfcf1b0ac408..7c3e04fca21eaa297b0a5398bfb98b1c604c2618 100644 (file)
@@ -641,8 +641,8 @@ void Delay(unsigned int delay)      // Sleep specified number of milliseconds
   sleep_milliseconds(delay);
 }
 
-boolean DelayReachedExt(unsigned int *counter_var, unsigned int delay,
-                       unsigned int actual_counter)
+boolean DelayReachedExt2(unsigned int *counter_var, unsigned int delay,
+                        unsigned int actual_counter)
 {
   if (actual_counter >= *counter_var &&
       actual_counter < *counter_var + delay)
@@ -653,34 +653,40 @@ boolean DelayReachedExt(unsigned int *counter_var, unsigned int delay,
   return TRUE;
 }
 
-boolean FrameReached(unsigned int *frame_counter_var, unsigned int frame_delay)
+boolean DelayReachedExt(DelayCounter *counter, unsigned int actual_counter)
 {
-  return DelayReachedExt(frame_counter_var, frame_delay, FrameCounter);
+  return DelayReachedExt2(&counter->count, counter->value, actual_counter);
 }
 
-boolean DelayReached(unsigned int *counter_var, unsigned int delay)
+boolean FrameReached(DelayCounter *counter)
 {
-  return DelayReachedExt(counter_var, delay, Counter());
+  return DelayReachedExt(counter, FrameCounter);
 }
 
-void ResetDelayCounterExt(unsigned int *counter_var,
-                         unsigned int actual_counter)
+boolean DelayReached(DelayCounter *counter)
 {
-  DelayReachedExt(counter_var, 0, actual_counter);
+  return DelayReachedExt(counter, Counter());
 }
 
-void ResetFrameCounter(unsigned int *frame_counter_var)
+void ResetDelayCounterExt(DelayCounter *counter, unsigned int actual_counter)
 {
-  FrameReached(frame_counter_var, 0);
+  DelayReachedExt2(&counter->count, 0, actual_counter);
 }
 
-void ResetDelayCounter(unsigned int *counter_var)
+void ResetFrameCounter(DelayCounter *counter)
 {
-  DelayReached(counter_var, 0);
+  ResetDelayCounterExt(counter, FrameCounter);
 }
 
-int WaitUntilDelayReached(unsigned int *counter_var, unsigned int delay)
+void ResetDelayCounter(DelayCounter *counter)
 {
+  ResetDelayCounterExt(counter, Counter());
+}
+
+int WaitUntilDelayReached(DelayCounter *counter)
+{
+  unsigned int *counter_var = &counter->count;
+  unsigned int delay = counter->value;
   unsigned int actual_counter;
   int skip_frames = 0;
 
@@ -711,22 +717,22 @@ int WaitUntilDelayReached(unsigned int *counter_var, unsigned int delay)
   return skip_frames;
 }
 
-void SkipUntilDelayReached(unsigned int *counter_var, unsigned int delay,
+void SkipUntilDelayReached(DelayCounter *counter,
                           int *loop_var, int last_loop_value)
 {
-  int skip_frames = WaitUntilDelayReached(counter_var, delay);
+  int skip_frames = WaitUntilDelayReached(counter);
 
 #if 0
 #if DEBUG
   if (skip_frames)
     Debug("internal:SkipUntilDelayReached",
          "%d: %d ms -> SKIP %d FRAME(S) [%d ms]",
-         *loop_var, delay,
-         skip_frames, skip_frames * delay);
+         *loop_var, counter->value,
+         skip_frames, skip_frames * counter->value);
   else
     Debug("internal:SkipUntilDelayReached",
          "%d: %d ms",
-         *loop_var, delay);
+         *loop_var, counter->value);
 #endif
 #endif
 
index 38e4edfa0600c72862732adc69ff286811dfd8ac..23c30e0801ac781a386ef81810f861eabae36d68 100644 (file)
@@ -134,14 +134,15 @@ char *getUUID(void);
 void InitCounter(void);
 unsigned int Counter(void);
 void Delay(unsigned int);
-boolean DelayReachedExt(unsigned int *, unsigned int, unsigned int);
-boolean FrameReached(unsigned int *, unsigned int);
-boolean DelayReached(unsigned int *, unsigned int);
-void ResetDelayCounterExt(unsigned int *, unsigned int);
-void ResetFrameCounter(unsigned int *);
-void ResetDelayCounter(unsigned int *);
-int WaitUntilDelayReached(unsigned int *, unsigned int);
-void SkipUntilDelayReached(unsigned int *, unsigned int, int *, int);
+boolean DelayReachedExt2(unsigned int *, unsigned int, unsigned int);
+boolean DelayReachedExt(DelayCounter *, unsigned int);
+boolean FrameReached(DelayCounter *);
+boolean DelayReached(DelayCounter *);
+void ResetDelayCounterExt(DelayCounter *, unsigned int);
+void ResetFrameCounter(DelayCounter *);
+void ResetDelayCounter(DelayCounter *);
+int WaitUntilDelayReached(DelayCounter *);
+void SkipUntilDelayReached(DelayCounter *, int *, int);
 
 unsigned int init_random_number(int, int);
 unsigned int get_random_number(int, int);
index 5be4c0dc173c9ea57455fcba7a3046eb8b88af36..f586bd8baaf59cad189720185aa0b0853622c310 100644 (file)
@@ -69,12 +69,11 @@ static void FinalizeScreen(int draw_target)
 
 static void UpdateScreenExt(SDL_Rect *rect, boolean with_frame_delay)
 {
-  static unsigned int update_screen_delay = 0;
-  unsigned int update_screen_delay_value = 50;         // (milliseconds)
+  static DelayCounter update_screen_delay = { 50 };    // (milliseconds)
   SDL_Surface *screen = backbuffer->surface;
 
   if (limit_screen_updates &&
-      !DelayReached(&update_screen_delay, update_screen_delay_value))
+      !DelayReached(&update_screen_delay))
     return;
 
   LimitScreenUpdates(FALSE);
@@ -154,24 +153,23 @@ static void UpdateScreenExt(SDL_Rect *rect, boolean with_frame_delay)
   SDL_Rect src_rect_up = { 0, 0,  video.width, video.height };
   SDL_Rect dst_rect_up = dst_rect_screen;
 
-  if (video.shifted_up || video.shifted_up_delay)
+  if (video.shifted_up || video.shifted_up_delay.count)
   {
     int time_current = SDL_GetTicks();
     int pos = video.shifted_up_pos;
     int pos_last = video.shifted_up_pos_last;
 
-    if (!DelayReachedExt(&video.shifted_up_delay, video.shifted_up_delay_value,
-                        time_current))
+    if (!DelayReachedExt(&video.shifted_up_delay, time_current))
     {
-      int delay = time_current - video.shifted_up_delay;
-      int delay_value = video.shifted_up_delay_value;
+      int delay_count = time_current - video.shifted_up_delay.count;
+      int delay_value = video.shifted_up_delay.value;
 
-      pos = pos_last + (pos - pos_last) * delay / delay_value;
+      pos = pos_last + (pos - pos_last) * delay_count / delay_value;
     }
     else
     {
       video.shifted_up_pos_last = pos;
-      video.shifted_up_delay = 0;
+      video.shifted_up_delay.count = 0;
     }
 
     src_rect_up.y = pos;
@@ -225,7 +223,7 @@ static void UpdateScreenExt(SDL_Rect *rect, boolean with_frame_delay)
 
   // global synchronization point of the game to align video frame delay
   if (with_frame_delay)
-    WaitUntilDelayReached(&video.frame_delay, video.frame_delay_value);
+    WaitUntilDelayReached(&video.frame_delay);
 
   video.frame_counter++;
 
index 12b01c382b8f1c50cd62403b9ce65317fa9e8840..35c0a2465457b8f34e33423aa3a91213c7e0de3d 100644 (file)
@@ -166,8 +166,8 @@ static boolean Mixer_ChannelExpired(int channel)
 
   if (expire_loop_sounds &&
       IS_LOOP(mixer[channel]) && !IS_MUSIC(mixer[channel]) &&
-      DelayReached(&mixer[channel].playing_starttime,
-                  SOUND_LOOP_EXPIRATION_TIME))
+      DelayReachedExt2(&mixer[channel].playing_starttime,
+                      SOUND_LOOP_EXPIRATION_TIME, Counter()))
     return TRUE;
 
   if (!Mix_Playing(channel))
index c41fbef27494cd40806fbd4b8567f53d801da07b..83bbe67a6c04aab4f81805b3f7fb809619eded40 100644 (file)
@@ -567,14 +567,14 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen)
   video.window_scaling_available = WINDOW_SCALING_STATUS;
 
   video.frame_counter = 0;
-  video.frame_delay = 0;
-  video.frame_delay_value = GAME_FRAME_DELAY;
+  video.frame_delay.count = 0;
+  video.frame_delay.value = GAME_FRAME_DELAY;
 
   video.shifted_up = FALSE;
   video.shifted_up_pos = 0;
   video.shifted_up_pos_last = 0;
-  video.shifted_up_delay = 0;
-  video.shifted_up_delay_value = ONE_SECOND_DELAY / 4;
+  video.shifted_up_delay.count = 0;
+  video.shifted_up_delay.value = ONE_SECOND_DELAY / 4;
 
   SDLInitVideoBuffer(fullscreen);
 
@@ -1112,12 +1112,12 @@ boolean SetVideoMode(boolean fullscreen)
 
 void SetVideoFrameDelay(unsigned int frame_delay_value)
 {
-  video.frame_delay_value = frame_delay_value;
+  video.frame_delay.value = frame_delay_value;
 }
 
 unsigned int GetVideoFrameDelay(void)
 {
-  return video.frame_delay_value;
+  return video.frame_delay.value;
 }
 
 boolean ChangeVideoModeIfNeeded(boolean fullscreen)
index d2aa685fa1c124c051037591d5c28dc40be503ee..cf2b0ca6be1ba5ee826e07ea5f2d9f7dae1a9b68 100644 (file)
@@ -1125,14 +1125,12 @@ struct VideoSystemInfo
   int vsync_mode;
 
   unsigned int frame_counter;
-  unsigned int frame_delay;
-  unsigned int frame_delay_value;
+  DelayCounter frame_delay;
 
   boolean shifted_up;
   int shifted_up_pos;
   int shifted_up_pos_last;
-  unsigned int shifted_up_delay;
-  unsigned int shifted_up_delay_value;
+  DelayCounter shifted_up_delay;
 
   boolean initialized;
 };
index 9fb00ec7f09b2719be6f79991ea4e3960bd81381..5129f1c874d1131403bfb801425048a981bedb48 100644 (file)
@@ -76,4 +76,11 @@ struct ListNode
 };
 typedef struct ListNode ListNode;
 
+struct DelayCounter
+{
+  unsigned int value;
+  unsigned int count;
+};
+typedef struct DelayCounter DelayCounter;
+
 #endif // TYPES_H
index 576f1ff0566a054f1dd9d4fc2df1345cde67da33..809d7c2d6c738811a0b58933d3b50a145852e884 100644 (file)
@@ -1872,7 +1872,7 @@ static unsigned int getAutoDelayCounter(struct TitleFadingInfo *fi)
 static boolean TitleAutoDelayReached(unsigned int *counter_var,
                                     struct TitleFadingInfo *fi)
 {
-  return DelayReachedExt(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
+  return DelayReachedExt2(counter_var, fi->auto_delay, getAutoDelayCounter(fi));
 }
 
 static void ResetTitleAutoDelay(unsigned int *counter_var,
@@ -3161,13 +3161,15 @@ static void DrawInfoScreen_Elements(void)
 
 void HandleInfoScreen_Elements(int dx, int dy, int button)
 {
-  static unsigned int info_delay = 0;
+  static DelayCounter info_delay = { 0 };
   static int num_anims;
   static int num_pages;
   static int page;
   int anims_per_page = NUM_INFO_ELEMENTS_ON_SCREEN;
   int i;
 
+  info_delay.value = GameFrameDelay;
+
   if (button == MB_MENU_INITIALIZE)
   {
     boolean new_element = TRUE;
@@ -3230,7 +3232,7 @@ void HandleInfoScreen_Elements(int dx, int dy, int button)
   }
   else
   {
-    if (DelayReached(&info_delay, GameFrameDelay))
+    if (DelayReached(&info_delay))
       if (page < num_pages)
        DrawInfoScreen_HelpAnim(page * anims_per_page, num_anims, FALSE);
 
@@ -8456,8 +8458,7 @@ static boolean CustomizeKeyboardMain(int player_nr)
   while (!finished)
   {
     Event event;
-    unsigned int event_frame_delay = 0;
-    unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
+    DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
 
     // reset frame delay counter directly after updating screen
     ResetDelayCounter(&event_frame_delay);
@@ -8535,7 +8536,7 @@ static boolean CustomizeKeyboardMain(int player_nr)
       }
 
       // do not handle events for longer than standard frame delay period
-      if (DelayReached(&event_frame_delay, event_frame_delay_value))
+      if (DelayReached(&event_frame_delay))
        break;
     }
 
@@ -8559,8 +8560,7 @@ void CustomizeKeyboard(int player_nr)
     int font_height = getFontHeight(font_nr);
     int ypos1 = SYSIZE / 2 - font_height * 2;
     int ypos2 = SYSIZE / 2 - font_height * 1;
-    unsigned int wait_frame_delay = 0;
-    unsigned int wait_frame_delay_value = 2000;
+    DelayCounter wait_frame_delay = { 2000 };
 
     ResetDelayCounter(&wait_frame_delay);
 
@@ -8569,7 +8569,7 @@ void CustomizeKeyboard(int player_nr)
     DrawTextSCentered(ypos1, font_nr, "Keyboard");
     DrawTextSCentered(ypos2, font_nr, "configured!");
 
-    while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
+    while (!DelayReached(&wait_frame_delay))
       BackToFront();
 
     ClearEventQueue();
@@ -8770,8 +8770,7 @@ static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
 
       screen_initialized = TRUE;
 
-      unsigned int event_frame_delay = 0;
-      unsigned int event_frame_delay_value = GAME_FRAME_DELAY;
+      DelayCounter event_frame_delay = { GAME_FRAME_DELAY };
 
       // reset frame delay counter directly after updating screen
       ResetDelayCounter(&event_frame_delay);
@@ -8909,7 +8908,7 @@ static boolean ConfigureJoystickMapButtonsAndAxes(SDL_Joystick *joystick)
        }
 
        // do not handle events for longer than standard frame delay period
-       if (DelayReached(&event_frame_delay, event_frame_delay_value))
+       if (DelayReached(&event_frame_delay))
          break;
       }
     }
@@ -8993,8 +8992,7 @@ void ConfigureJoystick(int player_nr)
     int font_height = getFontHeight(font_nr);
     int ypos1 = SYSIZE / 2 - font_height * 2;
     int ypos2 = SYSIZE / 2 - font_height * 1;
-    unsigned int wait_frame_delay = 0;
-    unsigned int wait_frame_delay_value = 2000;
+    DelayCounter wait_frame_delay = { 2000 };
 
     ResetDelayCounter(&wait_frame_delay);
 
@@ -9005,7 +9003,7 @@ void ConfigureJoystick(int player_nr)
     DrawTextSCentered(ypos1, font_nr, message1);
     DrawTextSCentered(ypos2, font_nr, message2);
 
-    while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
+    while (!DelayReached(&wait_frame_delay))
       BackToFront();
 
     ClearEventQueue();
@@ -9323,8 +9321,7 @@ void ConfigureVirtualButtons(void)
     int font_height = getFontHeight(font_nr);
     int ypos1 = SYSIZE / 2 - font_height * 2;
     int ypos2 = SYSIZE / 2 - font_height * 1;
-    unsigned int wait_frame_delay = 0;
-    unsigned int wait_frame_delay_value = 2000;
+    DelayCounter wait_frame_delay = { 2000 };
 
     ResetDelayCounter(&wait_frame_delay);
 
@@ -9333,7 +9330,7 @@ void ConfigureVirtualButtons(void)
     DrawTextSCentered(ypos1, font_nr, "Virtual buttons");
     DrawTextSCentered(ypos2, font_nr, "configured!");
 
-    while (!DelayReached(&wait_frame_delay, wait_frame_delay_value))
+    while (!DelayReached(&wait_frame_delay))
       BackToFront();
 
     ClearEventQueue();
index cd07263f007f2e4842c1395e13a5c17f6d6adecf..3fb22a8d598369b9f6fbb3791fa8c33317c52829 100644 (file)
@@ -1380,15 +1380,14 @@ boolean PlaySolutionTape(void)
 
 static boolean PlayScoreTape_WaitForDownload(void)
 {
-  unsigned int download_delay = 0;
-  unsigned int download_delay_value = 10000;
+  DelayCounter download_delay = { 10000 };
 
   ResetDelayCounter(&download_delay);
 
   // wait for score tape to be successfully downloaded (and fail on timeout)
   while (!server_scores.tape_downloaded)
   {
-    if (DelayReached(&download_delay, download_delay_value))
+    if (DelayReached(&download_delay))
       return FALSE;
 
     UPDATE_BUSY_STATE_NOT_LOADING();
@@ -1578,15 +1577,14 @@ static void AutoPlayTapes_SetScoreEntry(int score, int time)
 
 static boolean AutoPlayTapes_WaitForUpload(void)
 {
-  unsigned int upload_delay = 0;
-  unsigned int upload_delay_value = 10000;
+  DelayCounter upload_delay = { 10000 };
 
   ResetDelayCounter(&upload_delay);
 
   // wait for score tape to be successfully uploaded (and fail on timeout)
   while (!server_scores.uploaded)
   {
-    if (DelayReached(&upload_delay, upload_delay_value))
+    if (DelayReached(&upload_delay))
     {
       PrintNoLog("\r");
       Print("- uploading score tape to score server - TIMEOUT.\n");
index 79cf0885135681310694fdc4dc562fd40dfa5cf0..d00b01d46d74a5abd9ac177b1ae5ee62e91512c5 100644 (file)
@@ -2886,9 +2886,9 @@ static void AnimateEnvelope(int envelope_nr, int anim_mode, int action)
   int mask_mode = (src_bitmap != NULL ? BLIT_MASKED : BLIT_ON_BACKGROUND);
   boolean ffwd_delay = (tape.playing && tape.fast_forward);
   boolean no_delay = (tape.warp_forward);
-  unsigned int anim_delay = 0;
   int frame_delay_value = (ffwd_delay ? FfwdFrameDelay : GameFrameDelay);
   int anim_delay_value = MAX(1, (no_delay ? 0 : frame_delay_value) / 2);
+  DelayCounter anim_delay = { anim_delay_value };
   int font_nr = FONT_ENVELOPE_1 + envelope_nr;
   int font_width = getFontWidth(font_nr);
   int font_height = getFontHeight(font_nr);
@@ -2934,7 +2934,7 @@ static void AnimateEnvelope(int envelope_nr, int anim_mode, int action)
     redraw_mask |= REDRAW_FIELD;
     BackToFront();
 
-    SkipUntilDelayReached(&anim_delay, anim_delay_value, &i, last_frame);
+    SkipUntilDelayReached(&anim_delay, &i, last_frame);
   }
 
   ClearAutoRepeatKeyEvents();
@@ -3204,7 +3204,7 @@ static void AnimateEnvelopeRequest(int anim_mode, int action)
   boolean no_delay = (tape.warp_forward);
   int delay_value = (ffwd_delay ? delay_value_fast : delay_value_normal);
   int anim_delay_value = MAX(1, (no_delay ? 0 : delay_value + 500 * 0) / 2);
-  unsigned int anim_delay = 0;
+  DelayCounter anim_delay = { anim_delay_value };
 
   int tile_size = MAX(request.step_offset, 1);
   int max_xsize = request.width  / tile_size;
@@ -3277,7 +3277,7 @@ static void AnimateEnvelopeRequest(int anim_mode, int action)
 
     BackToFront();
 
-    SkipUntilDelayReached(&anim_delay, anim_delay_value, &i, last_frame);
+    SkipUntilDelayReached(&anim_delay, &i, last_frame);
   }
 
   ClearAutoRepeatKeyEvents();
@@ -3548,15 +3548,17 @@ static void DrawPreviewLevelInfo(int mode)
 
 static void DrawPreviewLevelExt(boolean restart)
 {
-  static unsigned int scroll_delay = 0;
-  static unsigned int label_delay = 0;
+  static DelayCounter scroll_delay = { 0 };
+  static DelayCounter label_delay = { 0 };
   static int from_x, from_y, scroll_direction;
   static int label_state, label_counter;
-  unsigned int scroll_delay_value = preview.step_delay;
   boolean show_level_border = (BorderElement != EL_EMPTY);
   int level_xsize = lev_fieldx + (show_level_border ? 2 : 0);
   int level_ysize = lev_fieldy + (show_level_border ? 2 : 0);
 
+  scroll_delay.value = preview.step_delay;
+  label_delay.value = MICROLEVEL_LABEL_DELAY;
+
   if (restart)
   {
     from_x = 0;
@@ -3610,7 +3612,7 @@ static void DrawPreviewLevelExt(boolean restart)
   // scroll preview level, if needed
   if (preview.anim_mode != ANIM_NONE &&
       (level_xsize > preview.xsize || level_ysize > preview.ysize) &&
-      DelayReached(&scroll_delay, scroll_delay_value))
+      DelayReached(&scroll_delay))
   {
     switch (scroll_direction)
     {
@@ -3668,7 +3670,7 @@ static void DrawPreviewLevelExt(boolean restart)
   if (!strEqual(level.name, NAMELESS_LEVEL_NAME) &&
       !strEqual(level.author, ANONYMOUS_NAME) &&
       !strEqual(level.author, leveldir_current->name) &&
-      DelayReached(&label_delay, MICROLEVEL_LABEL_DELAY))
+      DelayReached(&label_delay))
   {
     int max_label_counter = 23;
 
@@ -5352,8 +5354,7 @@ unsigned int MoveDoor(unsigned int door_state)
   };
   static int door1 = DOOR_CLOSE_1;
   static int door2 = DOOR_CLOSE_2;
-  unsigned int door_delay = 0;
-  unsigned int door_delay_value;
+  DelayCounter door_delay = { 0 };
   int i;
 
   if (door_state == DOOR_GET_STATE)
@@ -5468,7 +5469,7 @@ unsigned int MoveDoor(unsigned int door_state)
     num_move_steps = max_move_delay / max_step_delay;
     num_move_steps_doors_only = max_move_delay_doors_only / max_step_delay;
 
-    door_delay_value = max_step_delay;
+    door_delay.value = max_step_delay;
 
     if ((door_state & DOOR_NO_DELAY) || setup.quick_doors)
     {
@@ -5551,7 +5552,7 @@ unsigned int MoveDoor(unsigned int door_state)
        {
          int k2_door = (door_opening ? k : num_move_steps_doors_only - k - 1);
          int kk_door = MAX(0, k2_door);
-         int sync_frame = kk_door * door_delay_value;
+         int sync_frame = kk_door * door_delay.value;
          int frame = getGraphicAnimationFrame(dpc->graphic, sync_frame);
 
          getFixedGraphicSource(dpc->graphic, frame, &bitmap,
@@ -5660,7 +5661,7 @@ unsigned int MoveDoor(unsigned int door_state)
       {
        BackToFront();
 
-       SkipUntilDelayReached(&door_delay, door_delay_value, &k, last_frame);
+       SkipUntilDelayReached(&door_delay, &k, last_frame);
 
        // prevent OS (Windows) from complaining about program not responding
        CheckQuitEvent();
@@ -5674,13 +5675,13 @@ unsigned int MoveDoor(unsigned int door_state)
     {
       // wait for specified door action post delay
       if (door_state & DOOR_ACTION_1 && door_state & DOOR_ACTION_2)
-       door_delay_value = MAX(door_1.post_delay, door_2.post_delay);
+       door_delay.value = MAX(door_1.post_delay, door_2.post_delay);
       else if (door_state & DOOR_ACTION_1)
-       door_delay_value = door_1.post_delay;
+       door_delay.value = door_1.post_delay;
       else if (door_state & DOOR_ACTION_2)
-       door_delay_value = door_2.post_delay;
+       door_delay.value = door_2.post_delay;
 
-      while (!DelayReached(&door_delay, door_delay_value))
+      while (!DelayReached(&door_delay))
        BackToFront();
     }
   }