Odyssey::Timer Class Reference

Tracks the passage of time with high precision. More...

#include <Timer.h>

Inheritance diagram for Odyssey::Timer:

Odyssey::Clock List of all members.

Public Types

typedef std::set< TimerListener * > ListenerSet
typedef ContainerIterator<
ListenerSet
ListenerIterator
typedef std::pair< float32,
TimerEventListener * > 
EventPair
typedef std::list< EventPairEventQueue

Public Member Functions

 Timer ()
 Constructs a new, empty timer.
virtual ~Timer ()
void reset ()
 Reset the timer, including its internal timing info and counters.
void tick ()
 Updates the internal counters with the time since the last tick/reset.
float32 getDeltaTime () const
 Returns the time between the last tick/resets.
float64 getTotalTime () const
 Returns the total time since the last reset.
void setScale (float32 scale)
 Sets time scaling. This scales the delta times recorded.
float32 getScale () const
 Returns the current time scaling value.
void setActive (bool active=true)
 Sets the active state of the timer.
bool getActive () const
 Returns the current active state.
void addTimerListener (TimerListener *listener)
 Adds a new callback to be updated during timer operations.
void removeTimerListener (TimerListener *listener)
 Removes a registered callback listener.
void _fireTickEvent (float32 time) const
 Internal method for firing a timer tick event.
void _fireResetEvent () const
 Internal method for firing a reset timer event.
void addEvent (float32 delta, TimerEventListener *listener)
 Adds a new event to the timer.
void clearEvents ()
 Removes all of the previously registered events.

Protected Attributes

bool _active
float32 _delta
float32 _scale
float64 _total
bool _perfCounter
int64 _freq
union {
   int64   _count64
   int32   _count32
_count
ListenerSet _listeners
EventQueue _events

Detailed Description

Tracks the passage of time with high precision.

This class is able to track timing information with very high precision. It also supports callbacks as well as events that are tied with expired time.


Member Typedef Documentation

typedef std::pair<float32,TimerEventListener*> Odyssey::Timer::EventPair
 

typedef std::list<EventPair> Odyssey::Timer::EventQueue
 

typedef ContainerIterator<ListenerSet> Odyssey::Timer::ListenerIterator
 

typedef std::set<TimerListener*> Odyssey::Timer::ListenerSet
 


Constructor & Destructor Documentation

Odyssey::Timer::Timer  ) 
 

Constructs a new, empty timer.

virtual Odyssey::Timer::~Timer  )  [virtual]
 


Member Function Documentation

void Odyssey::Timer::_fireResetEvent  )  const
 

Internal method for firing a reset timer event.

void Odyssey::Timer::_fireTickEvent float32  time  )  const
 

Internal method for firing a timer tick event.

void Odyssey::Timer::addEvent float32  delta,
TimerEventListener listener
 

Adds a new event to the timer.

Events are stored in a queue. The delta parameter refers to the time until the event occur. When an event is triggered the event is destroyed. This means that events are one-time. In order to have repeating events (e.g. every 1 second) you need to re-register the event each time.

Parameters:
delta the time until the event should fire
listener the event callback that should be called

void Odyssey::Timer::addTimerListener TimerListener listener  ) 
 

Adds a new callback to be updated during timer operations.

void Odyssey::Timer::clearEvents  ) 
 

Removes all of the previously registered events.

bool Odyssey::Timer::getActive  )  const
 

Returns the current active state.

float32 Odyssey::Timer::getDeltaTime  )  const
 

Returns the time between the last tick/resets.

float32 Odyssey::Timer::getScale  )  const
 

Returns the current time scaling value.

float64 Odyssey::Timer::getTotalTime  )  const
 

Returns the total time since the last reset.

void Odyssey::Timer::removeTimerListener TimerListener listener  ) 
 

Removes a registered callback listener.

void Odyssey::Timer::reset  ) 
 

Reset the timer, including its internal timing info and counters.

This performs a fill reset, which means both the counters and the timing info used internally is reset and reaquired.

void Odyssey::Timer::setActive bool  active = true  ) 
 

Sets the active state of the timer.

An inactive timer does nothing when tick is called. Internal counters aren't updated, no callbacks are called, and no events are triggered.

void Odyssey::Timer::setScale float32  scale  ) 
 

Sets time scaling. This scales the delta times recorded.

void Odyssey::Timer::tick  ) 
 

Updates the internal counters with the time since the last tick/reset.

This is the counting function, which will update the internal counters with the passage of time. This function also calls the callbacks that are registered as well as handling time-based events.


Member Data Documentation

bool Odyssey::Timer::_active [protected]
 

union { ... } Odyssey::Timer::_count [protected]
 

int32 Odyssey::Timer::_count32 [protected]
 

int64 Odyssey::Timer::_count64 [protected]
 

float32 Odyssey::Timer::_delta [protected]
 

EventQueue Odyssey::Timer::_events [protected]
 

int64 Odyssey::Timer::_freq [protected]
 

ListenerSet Odyssey::Timer::_listeners [protected]
 

bool Odyssey::Timer::_perfCounter [protected]
 

float32 Odyssey::Timer::_scale [protected]
 

float64 Odyssey::Timer::_total [protected]
 


The documentation for this class was generated from the following file:
Generated on Sun Jan 7 01:18:53 2007 for Odyssey Meta-Engine by  doxygen 1.4.6-NO