mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2026-07-24 03:56:43 +00:00
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:
committed by
rubidium42
parent
57f5d27427
commit
11ec156b64
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user