mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
Timer: Add utility to ensure safe iteration of timers
This commit is contained in:
parent
5eae56fd23
commit
a56efeb609
@ -51,7 +51,7 @@ void TimeoutTimer<TimerGameTick>::Elapsed(TimerGameTick::TElapsed delta)
|
|||||||
template<>
|
template<>
|
||||||
void TimerManager<TimerGameTick>::Elapsed(TimerGameTick::TElapsed delta)
|
void TimerManager<TimerGameTick>::Elapsed(TimerGameTick::TElapsed delta)
|
||||||
{
|
{
|
||||||
for (auto timer : TimerManager<TimerGameTick>::GetTimers()) {
|
for (auto timer : TimerManager<TimerGameTick>::GetTimerVector()) {
|
||||||
timer->Elapsed(delta);
|
timer->Elapsed(delta);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -117,6 +117,19 @@ private:
|
|||||||
static btree::btree_set<BaseTimer<TTimerType> *, base_timer_sorter> timers;
|
static btree::btree_set<BaseTimer<TTimerType> *, base_timer_sorter> timers;
|
||||||
return timers;
|
return timers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** List of active timers, as a std::vector, to allow for timers to be added/removed during iteration. */
|
||||||
|
static std::vector<BaseTimer<TTimerType> *> GetTimerVector()
|
||||||
|
{
|
||||||
|
std::vector<BaseTimer<TTimerType> *> result;
|
||||||
|
|
||||||
|
const auto &timers = TimerManager::GetTimers();
|
||||||
|
result.reserve(timers.size());
|
||||||
|
for (BaseTimer<TTimerType> * timer : timers) {
|
||||||
|
result.push_back(timer);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* TIMER_MANAGER_H */
|
#endif /* TIMER_MANAGER_H */
|
||||||
|
Loading…
Reference in New Issue
Block a user