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_game_realtime.cpp
10 * This file implements the timer logic for the real time game-timer.
13 #include "../stdafx.h"
14 #include "../openttd.h"
16 #include "timer_game_realtime.h"
18 #include "../safeguards.h"
21 void IntervalTimer
<TimerGameRealtime
>::Elapsed(TimerGameRealtime::TElapsed delta
)
23 if (this->period
.period
== std::chrono::milliseconds::zero()) return;
24 if (this->period
.flag
== TimerGameRealtime::PeriodFlags::AUTOSAVE
&& _pause_mode
!= PM_UNPAUSED
&& (_pause_mode
& PM_COMMAND_DURING_PAUSE
) == 0) return;
25 if (this->period
.flag
== TimerGameRealtime::PeriodFlags::UNPAUSED
&& _pause_mode
!= PM_UNPAUSED
) return;
27 this->storage
.elapsed
+= delta
;
30 while (this->storage
.elapsed
>= this->period
.period
) {
31 this->storage
.elapsed
-= this->period
.period
;
36 this->callback(count
);
41 void TimeoutTimer
<TimerGameRealtime
>::Elapsed(TimerGameRealtime::TElapsed delta
)
43 if (this->fired
) return;
44 if (this->period
.period
== std::chrono::milliseconds::zero()) return;
45 if (this->period
.flag
== TimerGameRealtime::PeriodFlags::AUTOSAVE
&& _pause_mode
!= PM_UNPAUSED
&& (_pause_mode
& PM_COMMAND_DURING_PAUSE
) == 0) return;
46 if (this->period
.flag
== TimerGameRealtime::PeriodFlags::UNPAUSED
&& _pause_mode
!= PM_UNPAUSED
) return;
48 this->storage
.elapsed
+= delta
;
50 if (this->storage
.elapsed
>= this->period
.period
) {
57 bool TimerManager
<TimerGameRealtime
>::Elapsed(TimerGameRealtime::TElapsed delta
)
59 for (auto timer
: TimerManager
<TimerGameRealtime
>::GetTimers()) {
60 timer
->Elapsed(delta
);
68 void TimerManager
<TimerGameRealtime
>::Validate(TimerGameRealtime::TPeriod
)
71 #endif /* WITH_ASSERT */