mirror of https://github.com/OpenTTD/OpenTTD.git
Fix #12509: Maintain timer sort invariants when changing period
This commit is contained in:
parent
11ec156b64
commit
9b747a173d
|
@ -98,7 +98,7 @@ public:
|
||||||
*/
|
*/
|
||||||
void SetInterval(const TPeriod interval, bool reset = true)
|
void SetInterval(const TPeriod interval, bool reset = true)
|
||||||
{
|
{
|
||||||
this->period = interval;
|
TimerManager<TTimerType>::ChangeRegisteredTimerPeriod(*this, interval);
|
||||||
if (reset) this->storage = {};
|
if (reset) this->storage = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,7 +150,7 @@ public:
|
||||||
*/
|
*/
|
||||||
void Reset(const TPeriod timeout)
|
void Reset(const TPeriod timeout)
|
||||||
{
|
{
|
||||||
this->period = timeout;
|
TimerManager<TTimerType>::ChangeRegisteredTimerPeriod(*this, timeout);
|
||||||
this->fired = false;
|
this->fired = false;
|
||||||
this->storage = {};
|
this->storage = {};
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,20 @@ public:
|
||||||
GetTimers().erase(&timer);
|
GetTimers().erase(&timer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the period of a registered timer.
|
||||||
|
*
|
||||||
|
* @param timer The timer to change the period of.
|
||||||
|
* @param new_period The new period value.
|
||||||
|
*/
|
||||||
|
static void ChangeRegisteredTimerPeriod(BaseTimer<TTimerType> &timer, TPeriod new_period)
|
||||||
|
{
|
||||||
|
/* Unregistration and re-registration is necessary because the period is used as the sort key in base_timer_sorter */
|
||||||
|
UnregisterTimer(timer);
|
||||||
|
timer.period = new_period;
|
||||||
|
RegisterTimer(timer);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WITH_ASSERT
|
#ifdef WITH_ASSERT
|
||||||
/**
|
/**
|
||||||
* Validate that a new period is actually valid.
|
* Validate that a new period is actually valid.
|
||||||
|
|
Loading…
Reference in New Issue