Codechange: validate the developer didn't schedule two timers on the same trigger/priority

This commit is contained in:
Patric Stout
2023-04-13 19:26:17 +02:00
committed by Patric Stout
parent 3ebc7ad16e
commit 387d5eb74f
4 changed files with 44 additions and 0 deletions

View File

@@ -28,6 +28,7 @@ class BaseTimer;
template <typename TTimerType>
class TimerManager {
public:
using TPeriod = typename TTimerType::TPeriod;
using TElapsed = typename TTimerType::TElapsed;
/* Avoid copying this object; it is a singleton object. */
@@ -40,6 +41,9 @@ public:
* @param timer The timer to register.
*/
static void RegisterTimer(BaseTimer<TTimerType> &timer) {
#ifdef WITH_ASSERT
Validate(timer.period);
#endif /* WITH_ASSERT */
GetTimers().insert(&timer);
}
@@ -52,6 +56,21 @@ public:
GetTimers().erase(&timer);
}
#ifdef WITH_ASSERT
/**
* Validate that a new period is actually valid.
*
* For most timers this is not an issue, but some want to make sure their
* period is unique, to ensure deterministic game-play.
*
* This is meant purely to protect a developer from making a mistake.
* As such, assert() when validation fails.
*
* @param period The period to validate.
*/
static void Validate(TPeriod period);
#endif /* WITH_ASSERT */
/**
* Called when time for this timer elapsed.
*