Loading [MathJax]/extensions/MathMenu.js
 |
Cytopia
0.3
A city building simulation game
|
Go to the documentation of this file.
6 while (!queue.
empty() && (now >= queue.
top().m_waketime))
8 const auto task = queue.
top();
10 const bool isCanceled = task.callback();
12 if (!isCanceled && (task.m_period != decltype(task.m_period){0}))
14 queue.
push(Task(task.callback, now + task.m_period, task.m_period, task.hndl));
21 std::lock_guard<std::mutex> lock(
m_lock);
23 const auto now = Clock::now();
38 return queue.erase_if([hndl](
const typename Queue::value_type &ct) {
return ct.hndl == hndl; }) > 0;
43 std::lock_guard<std::mutex> lock(
m_lock);
55 assert(cbk !=
nullptr);
57 std::lock_guard<std::mutex> lock(
m_lock);
62 const bool isCanceled = cbk();
64 if (isCanceled || (period == 0))
79 std::lock_guard<std::mutex> lock(
m_lock);
86 std::lock_guard<std::mutex> lock(
m_lock);
float m_speedFactor
The current game tick duration on milliseconds.
void tickTask(PriorityQueue< Task, Cmp > &queue, Now now)
Tick clock for given task type.
ClockTaskHndl m_unique_handle
PriorityQueue< RealTimeClockTask, std::greater< RealTimeClockTask > > m_realTimeTasks
static constexpr ClockTaskHndl ClockTaskHndlInvalid
Invalid task handler. In case that clock is not added.
unsigned long ClockTaskHndl
bool empty() const noexcept
Check whether queue is empty.
static bool removeTaskFromQueue(const GameClock::ClockTaskHndl hndl, Queue &queue)
Priority queue with erase element functionality.
static constexpr unsigned int DefaultGameTickDuration
Duration of default game timer tick in ms.
void tick(void)
This function provides the tick for both clocks.
void pop()
Remove first element from the queue (from top).
Clock::duration m_gameTickDuration
unsigned long GameClockTime
void push(value_type &&element)
Add new element to the queue.
ClockTask< GameClockTime, GameClockDuration > GameTimeClockTask
GameClock::ClockTaskHndl addGameTimeClockTask(ClockCbk cbk, GameClockTime delay, GameClockTime period=0U)
Add new game time clock task.
TimePoint m_lastGameTickTime
Last time of the game tick.
PriorityQueue< GameTimeClockTask, std::greater< GameTimeClockTask > > m_gameTimeTasks
GameClockTime m_gameTicks
Current number of the game ticks.
bool removeClockTask(ClockTaskHndl hndl)
Remove real/game time clock. After it is removed successfully it is guaranteed it will not trigger ca...
void clear(void)
Remove all real time and game time clocks.
reference top()
Get top element from the queue.
void setGameClockSpeed(float speedFactor)
Set game clock speed.
std::function< bool(void)> ClockCbk