Change: Use GUITimer class instead of bare int/uints.

This commit is contained in:
2018-05-20 09:58:36 +01:00
committed by PeterN
parent 59fe4f28c8
commit 806e7d25dd
17 changed files with 140 additions and 85 deletions

View File

@@ -56,36 +56,4 @@ void DeleteWindowByClass(WindowClass cls);
bool EditBoxInGlobalFocus();
Point GetCaretPosition();
/**
* Count how many times the interval has elapsed, and update the timer.
* Use to ensure a specific amount of events happen within a timeframe, e.g. for animation.
* The timer value does not need to be initialised.
* @param timer Timer to test. Value will be increased.
* @param delta Time since last test.
* @param interval Timing interval.
* @return Number of times the interval has elapsed.
*/
static inline uint CountIntervalElapsed(uint &timer, uint delta, uint interval)
{
uint count = delta / interval;
if (timer + (delta % interval) >= interval) count++;
timer = (timer + delta) % interval;
return count;
}
/**
* Test if a timer has elapsed, and update the timer.
* Use to ensure an event happens only once within a timeframe, e.g. for window updates.
* The timer value must be initialised in order for the timer to elapsed.
* @param timer Timer to test. Value will be decreased.
* @param delta Time since last test.
* @return True iff the timer has elapsed.
*/
static inline bool TimerElapsed(int &timer, uint delta)
{
if (timer <= 0) return false;
timer -= delta;
return timer <= 0;
}
#endif /* WINDOW_FUNC_H */