Cytopia  0.3
A city building simulation game
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GameClock.inl.hxx
Go to the documentation of this file.
1 #include <cassert>
2 #include "LOG.hxx"
3 
4 template <typename DelayType, typename PeriodType>
5 inline GameClock::ClockTaskHndl GameClock::addRealTimeClockTask(ClockCbk cbk, DelayType delay, PeriodType period)
6 {
7  assert((cbk != nullptr) && (TimePoint(delay) >= TimePointZero) && (TimePoint(period) >= TimePointZero));
8 
9  std::lock_guard<std::mutex> lock(m_lock);
10  TimePoint delayConverted = (TimePoint)delay;
11 
12  // If no delay required call callback immediately
13  if (delayConverted == TimePointZero)
14  {
15  const bool isCanceled = cbk();
16 
17  if (isCanceled || ((TimePoint)period == TimePointZero))
18  {
19  return ClockTaskHndlInvalid;
20  }
21 
22  delayConverted = (TimePoint)period;
23  }
24 
25  m_realTimeTasks.push(RealTimeClockTask(cbk, Clock::now() + (delayConverted - TimePointZero), (TimePoint)period - TimePointZero,
26  ++m_unique_handle));
27  return m_unique_handle;
28 }
GameClock::m_unique_handle
ClockTaskHndl m_unique_handle
Definition: GameClock.hxx:135
GameClock::m_lock
std::mutex m_lock
Definition: GameClock.hxx:133
GameClock::m_realTimeTasks
PriorityQueue< RealTimeClockTask, std::greater< RealTimeClockTask > > m_realTimeTasks
Definition: GameClock.hxx:131
GameClock::ClockTaskHndlInvalid
static constexpr ClockTaskHndl ClockTaskHndlInvalid
Invalid task handler. In case that clock is not added.
Definition: GameClock.hxx:107
GameClock::ClockTaskHndl
unsigned long ClockTaskHndl
Definition: GameClock.hxx:28
GameClock::RealTimeClockTask
ClockTask< TimePoint, TimeDuration > RealTimeClockTask
Definition: GameClock.hxx:128
LOG.hxx
GameClock::TimePoint
std::chrono::time_point< Clock > TimePoint
Definition: GameClock.hxx:25
GameClock::TimePointZero
static constexpr TimePoint TimePointZero
Definition: GameClock.hxx:103
GameClock::addRealTimeClockTask
GameClock::ClockTaskHndl addRealTimeClockTask(ClockCbk cbk, DelayType delay, PeriodType period=TimePointZero)
Add new real time clock task.
Definition: GameClock.inl.hxx:5
GameClock::ClockCbk
std::function< bool(void)> ClockCbk
Definition: GameClock.hxx:27