Fix #10490: Allow ships to exit depots if another is not moving at the exit point...
[openttd-github.git] / src / timer / timer_window.cpp
blob906d5e0a9f17e3e99a8a1867af58b03dfa014ddd
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
8 /**
9 * @file timer_window.cpp
10 * This file implements the timer logic for the Window system.
13 #include "../stdafx.h"
14 #include "timer.h"
15 #include "timer_window.h"
17 #include "../safeguards.h"
19 template<>
20 void IntervalTimer<TimerWindow>::Elapsed(TimerWindow::TElapsed delta)
22 if (this->period == std::chrono::milliseconds::zero()) return;
24 this->storage.elapsed += delta;
26 uint count = 0;
27 while (this->storage.elapsed >= this->period) {
28 this->storage.elapsed -= this->period;
29 count++;
32 if (count > 0) {
33 this->callback(count);
37 template<>
38 void TimeoutTimer<TimerWindow>::Elapsed(TimerWindow::TElapsed delta)
40 if (this->fired) return;
41 if (this->period == std::chrono::milliseconds::zero()) return;
43 this->storage.elapsed += delta;
45 if (this->storage.elapsed >= this->period) {
46 this->callback();
47 this->fired = true;
51 template<>
52 bool TimerManager<TimerWindow>::Elapsed(TimerWindow::TElapsed delta)
54 /* Make a temporary copy of the timers, as a timer's callback might add/remove other timers. */
55 auto timers = TimerManager<TimerWindow>::GetTimers();
57 for (auto timer : timers) {
58 timer->Elapsed(delta);
61 return true;
64 #ifdef WITH_ASSERT
65 template<>
66 void TimerManager<TimerWindow>::Validate(TimerWindow::TPeriod)
69 #endif /* WITH_ASSERT */