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

@@ -98,3 +98,20 @@ void TimerManager<TimerGameCalendar>::Elapsed(TimerGameCalendar::TElapsed delta)
for (LinkGraph *lg : LinkGraph::Iterate()) lg->ShiftDates(-days_this_year);
}
}
#ifdef WITH_ASSERT
template<>
void TimerManager<TimerGameCalendar>::Validate(TimerGameCalendar::TPeriod period)
{
if (period.priority == TimerGameCalendar::Priority::NONE) return;
/* Validate we didn't make a developer error and scheduled more than one
* entry on the same priority/trigger. There can only be one timer on
* a specific trigger/priority, to ensure we are deterministic. */
for (const auto &timer : TimerManager<TimerGameCalendar>::GetTimers()) {
if (timer->period.trigger != period.trigger) continue;
assert(timer->period.priority != period.priority);
}
}
#endif /* WITH_ASSERT */