From: Holger Schemel Date: Tue, 2 Feb 2016 19:42:33 +0000 (+0100) Subject: added abstractions for checking and resetting frame and delay counters X-Git-Tag: 4.0.0.0-rc1~94 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=c8020d330cab48d59515e0e3b7e2f856630ef80b;p=rocksndiamonds.git added abstractions for checking and resetting frame and delay counters --- diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 4498e7f4..d57b8380 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -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) diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 8c0e4f43..36e1dfc4 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -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);