added abstractions for checking and resetting frame and delay counters
authorHolger Schemel <info@artsoft.org>
Tue, 2 Feb 2016 19:42:33 +0000 (20:42 +0100)
committerHolger Schemel <info@artsoft.org>
Tue, 2 Feb 2016 19:42:45 +0000 (20:42 +0100)
src/libgame/misc.c
src/libgame/misc.h

index 4498e7f49522a8ea9bfcd9485d87ab1cd584771c..d57b83807a249e6cb9c339ae0a3d4803fedda5e1 100644 (file)
@@ -383,32 +383,42 @@ void Delay(unsigned int delay)    /* Sleep specified number of milliseconds */
   sleep_milliseconds(delay);
 }
 
-boolean FrameReached(unsigned int *frame_counter_var,
-                    unsigned int frame_delay)
+boolean DelayReachedExt(unsigned int *counter_var, unsigned int delay,
+                       unsigned int actual_counter)
 {
-  unsigned int actual_frame_counter = FrameCounter;
-
-  if (actual_frame_counter >= *frame_counter_var &&
-      actual_frame_counter < *frame_counter_var + frame_delay)
+  if (actual_counter >= *counter_var &&
+      actual_counter < *counter_var + delay)
     return FALSE;
 
-  *frame_counter_var = actual_frame_counter;
+  *counter_var = actual_counter;
 
   return TRUE;
 }
 
-boolean DelayReached(unsigned int *counter_var,
-                    unsigned int delay)
+boolean FrameReached(unsigned int *frame_counter_var, unsigned int frame_delay)
 {
-  unsigned int actual_counter = Counter();
+  return DelayReachedExt(frame_counter_var, frame_delay, FrameCounter);
+}
 
-  if (actual_counter >= *counter_var &&
-      actual_counter < *counter_var + delay)
-    return FALSE;
+boolean DelayReached(unsigned int *counter_var, unsigned int delay)
+{
+  return DelayReachedExt(counter_var, delay, Counter());
+}
 
-  *counter_var = actual_counter;
+void ResetDelayCounterExt(unsigned int *counter_var,
+                         unsigned int actual_counter)
+{
+  DelayReachedExt(counter_var, 0, actual_counter);
+}
 
-  return TRUE;
+void ResetFrameCounter(unsigned int *frame_counter_var)
+{
+  FrameReached(frame_counter_var, 0);
+}
+
+void ResetDelayCounter(unsigned int *counter_var)
+{
+  DelayReached(counter_var, 0);
 }
 
 int WaitUntilDelayReached(unsigned int *counter_var, unsigned int delay)
index 8c0e4f431974afc9540cbf2e6d009c9b7ec6ec61..36e1dfc4e1dcf4cb40cfa6cfce3b6dd1247d243b 100644 (file)
@@ -131,8 +131,12 @@ boolean getTokenValueFromString(char *, char **, char **);
 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);