Timer calls registered functors, pauses the program, and provides time functions. More...
#include <_src_base_timer.hh>
Public Member Functions | |
| DEFINE_GetInstance (Timer) void Enable(bool enable) | |
| Milliseconds | GetElapsedTime (void) const |
| Milliseconds | GetElapsedTimeTotal (void) const |
| void | Register (shptr< TickFunctor > functor, const Milliseconds millisecFreq, const TickFunctor::eDisablement canDisable=TickFunctor::CAN_DISABLE) |
| void | Unregister (shptr< TickFunctor > functor) |
| void | Tick (void) |
Private Member Functions | |
| Timer (void) | |
| ~Timer () | |
| void | TickUpdateTime (const Milliseconds elapsedTime) |
| void | TickDoPending (void) |
| void | TickCallFunctors (void) |
Private Attributes | |
| DECLARE_SINGLETON_CLASS_VARS(Timer) typedef std typedef std::vector< shptr < TickFunctor > > | PendingFunctors |
| bool | mEnabled |
| program will be (mostly) paused if Timer is disabled | |
| Functors | mFunctors |
| mapped by raw ptr to Functor | |
| PendingFunctors | mPendingRegister |
| pending registering | |
| PendingFunctors | mPendingUnregister |
| pending unregistering | |
| Milliseconds | mTimeTotal |
| total time since start of program | |
| Milliseconds | mTimeVirtual |
| time since start of program minus time lost while paused | |
| Milliseconds | mTimeTotalWhenPauseStarted |
| copy of mTimeTotal when pause was started | |
| Milliseconds | mTimeVirtualWhenPauseStarted |
| copy of mTimeVirtual when pause was started | |
| Milliseconds | mTimeLostWhilePaused |
| accumulated time lost while paused | |
Timer calls registered functors, pauses the program, and provides time functions.
Timer is designed to tolerate tick functors that unregister themselves or indirectly register new functors, even while Timer is busy iterating thru functors.
Disabling Timer isn't absolute. A functor that is constructed with Timer::CANNOT_DISABLE must still be called even if Timer is disabled. For example, polling keyboard should remain enabled always.
To integrate Timer: Whichever function that is called periodically must call Timer::Tick() to drive the Timer object. Otherwise Timer won't be active.
Timer must be Singleton since globals register timers.
Pausing program by disabling Timer: ----------------------------------- Time is stopped while the program is paused, except for functors that cannot be disabled (still called while paused).
GetElapsedTime() returns the elapsed time minus time lost while paused. GetElapsedTimeTotal() still counts time while Timer is disabled (paused). Functors that cannot be disabled should call GetElapsedTimeTotal() else their timing calculations will malfunction after pausing.
| base::Timer::Timer | ( | void | ) | [private] |
| base::Timer::~Timer | ( | ) | [private] |
| base::Timer::DEFINE_GetInstance | ( | Timer | ) |
| Milliseconds base::Timer::GetElapsedTime | ( | void | ) | const [inline] |
| Milliseconds base::Timer::GetElapsedTimeTotal | ( | void | ) | const [inline] |
| void base::Timer::Register | ( | shptr< TickFunctor > | functor, | |
| const Milliseconds | millisecFreq, | |||
| const TickFunctor::eDisablement | disablement = TickFunctor::CAN_DISABLE | |||
| ) |
Register a tick functor. NOTE: Don't re-register the same functor.
| functor | Tick functor. | |
| millisecFreq | How frequently to invoke the functor. If equal to MILLISECONDS_NEVER then NOP. | |
| disablement | Pass CAN_DISABLE or CANNOT_DISABLE. Default is "can disable". Implementation: Registering is done without disrupting the iteration of Tick(). |
| void base::Timer::Tick | ( | void | ) |
INTEGRATION: The Timer singleton must be pulsed externally. An external module must call Timer::Tick() periodically (such as the program's main loop).
| void base::Timer::TickCallFunctors | ( | void | ) | [private] |
| void base::Timer::TickDoPending | ( | void | ) | [private] |
| void base::Timer::TickUpdateTime | ( | const Milliseconds | elapsedTime | ) | [private] |
| void base::Timer::Unregister | ( | shptr< TickFunctor > | functor | ) |
Unregister a tick functor. A functor is allowed to unregister itself (see header comments). Implementation: Unregistering is done without disrupting the iteration of Tick().
bool base::Timer::mEnabled [private] |
program will be (mostly) paused if Timer is disabled
Functors base::Timer::mFunctors [private] |
mapped by raw ptr to Functor
PendingFunctors base::Timer::mPendingRegister [private] |
pending registering
pending unregistering
accumulated time lost while paused
Milliseconds base::Timer::mTimeTotal [private] |
total time since start of program
copy of mTimeTotal when pause was started
Milliseconds base::Timer::mTimeVirtual [private] |
time since start of program minus time lost while paused
copy of mTimeVirtual when pause was started
DECLARE_SINGLETON_CLASS_VARS ( Timer ) typedef std typedef std::vector< shptr<TickFunctor> > base::Timer::PendingFunctors [private] |
Palomino Flight Simulator documents generated by doxygen 1.7.1 on Tue May 15 2012 22:40:11