Codechange: Add a priority field to TimerGameTick::TPeriod

Use this as the primary sort key for TimerGameTick::TPeriod,
to avoid container sort order changes on timer period saveload.
See: #12509
This commit is contained in:
Jonathan G Rennison
2024-04-20 15:39:36 +01:00
committed by rubidium42
parent 57f5d27427
commit 11ec156b64
8 changed files with 53 additions and 17 deletions
+15 -6
View File
@@ -21,13 +21,13 @@ TimerGameTick::TickCounter TimerGameTick::counter = 0;
template<>
void IntervalTimer<TimerGameTick>::Elapsed(TimerGameTick::TElapsed delta)
{
if (this->period == 0) return;
if (this->period.value == 0) return;
this->storage.elapsed += delta;
uint count = 0;
while (this->storage.elapsed >= this->period) {
this->storage.elapsed -= this->period;
while (this->storage.elapsed >= this->period.value) {
this->storage.elapsed -= this->period.value;
count++;
}
@@ -40,11 +40,11 @@ template<>
void TimeoutTimer<TimerGameTick>::Elapsed(TimerGameTick::TElapsed delta)
{
if (this->fired) return;
if (this->period == 0) return;
if (this->period.value == 0) return;
this->storage.elapsed += delta;
if (this->storage.elapsed >= this->period) {
if (this->storage.elapsed >= this->period.value) {
this->callback();
this->fired = true;
}
@@ -64,7 +64,16 @@ bool TimerManager<TimerGameTick>::Elapsed(TimerGameTick::TElapsed delta)
#ifdef WITH_ASSERT
template<>
void TimerManager<TimerGameTick>::Validate(TimerGameTick::TPeriod)
void TimerManager<TimerGameTick>::Validate(TimerGameTick::TPeriod period)
{
if (period.priority == TimerGameTick::Priority::NONE) return;
/* Validate we didn't make a developer error and scheduled more than one
* entry on the same priority. There can only be one timer on
* a specific priority, to ensure we are deterministic, and to avoid
* container sort order invariant issues with timer period saveload. */
for (const auto &timer : TimerManager<TimerGameTick>::GetTimers()) {
assert(timer->period.priority != period.priority);
}
}
#endif /* WITH_ASSERT */