 |
Cytopia
0.3
A city building simulation game
|
Go to the documentation of this file. 1 #ifndef GAME_CLOCK_HXX_
2 #define GAME_CLOCK_HXX_
7 #include "../util/PriorityQueue.hxx"
8 #include "../util/Singleton.hxx"
10 using namespace std::chrono_literals;
21 using Clock = std::chrono::high_resolution_clock;
61 template <
typename DelayType,
typename PeriodType = TimePo
int>
81 void setGameClockSpeed(
float speedFactor);
96 bool removeClockTask(ClockTaskHndl hndl);
102 static constexpr
unsigned int DefaultGameTickDuration = 2000;
112 template <
typename Time,
typename Duration>
struct ClockTask
120 : callback{cbk}, m_waketime{delay}, m_period{period}, hndl{hndl}
142 float m_speedFactor = 1.f;
143 Clock::duration m_gameTickDuration = std::chrono::milliseconds(DefaultGameTickDuration);
155 #endif // GAME_CLOCK_HXX_
Game clock service. Implement two timers one real time timer and other game time timer.
PriorityQueue< RealTimeClockTask, std::greater< RealTimeClockTask > > m_realTimeTasks
unsigned long ClockTaskHndl
bool operator>(const ClockTask &task2) const
unsigned long GameClockDuration
void clear(void) noexcept
Remove all elements from queue.
Priority queue with erase element functionality.
Template structure provide base for different clock tasks.
Clock::duration TimeDuration
unsigned long GameClockTime
Abstract Singleton implementation.
PriorityQueue< GameTimeClockTask, std::greater< GameTimeClockTask > > m_gameTimeTasks
std::chrono::time_point< Clock > TimePoint
std::chrono::high_resolution_clock Clock
float getGameClockSpeed() const
bool operator==(const ClockTask &task2) const
std::function< bool(void)> ClockCbk
ClockTask(ClockCbk cbk, Time delay, Duration period, ClockTaskHndl hndl)