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/>.
9 * @file timer_window.cpp
10 * This file implements the timer logic for the Window system.
13 #include "../stdafx.h"
15 #include "timer_window.h"
17 #include "../safeguards.h"
20 void IntervalTimer
<TimerWindow
>::Elapsed(TimerWindow::TElapsed delta
)
22 if (this->period
== std::chrono::milliseconds::zero()) return;
24 this->storage
.elapsed
+= delta
;
27 while (this->storage
.elapsed
>= this->period
) {
28 this->storage
.elapsed
-= this->period
;
33 this->callback(count
);
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
) {
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
);
66 void TimerManager
<TimerWindow
>::Validate(TimerWindow::TPeriod
)
69 #endif /* WITH_ASSERT */