Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
orxonox::Timer Class Reference

Timer is a helper class that executes a function after a given amount of seconds in game-time. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/libraries/tools/Timer.h>

Inheritance diagram for orxonox::Timer:
orxonox::Listable orxonox::Identifiable orxonox::RealTimer

Public Member Functions

 Timer ()
 Constructor: Sets the default-values. More...
 
 Timer (float interval, bool bLoop, const ExecutorPtr &executor, bool bKillAfterCall=false)
 Constructor: Initializes and starts the timer, which will call an executor after some time. More...
 
 Timer (float interval, bool bLoop, std::function< void(void)> func, bool bKillAfterCall=false)
 
void addTime (float time)
 Increases the remaining time of the timer by the given amount of time (in seconds). More...
 
float getRemainingTime () const
 Returns the remaining time until the timer calls the executor. More...
 
bool isActive () const
 Returns true if the timer is active (neither stopped nor paused). More...
 
void pauseTimer ()
 Pauses the timer - it will continue with the actual state if you call unpauseTimer(). More...
 
void removeTime (float time)
 Decreases the remaining time of the timer by the given amount of time (in seconds) More...
 
void run ()
 Calls the executor and destroys the timer if requested. More...
 
void setInterval (float interval)
 Changes the calling interval. More...
 
void setLoop (bool bLoop)
 Defines if the timer call the executor every interval seconds or only once. More...
 
void setTimer (float interval, bool bLoop, const ExecutorPtr &executor, bool bKillAfterCall=false)
 Initializes and starts the timer, which will call an executor after some time. More...
 
void setTimer (float interval, bool bLoop, std::function< void(void)> func, bool bKillAfterCall=false)
 
void startTimer ()
 Re-starts the timer: The executor will be called after interval seconds. More...
 
void stopTimer ()
 Stops the timer. More...
 
void tick (const Clock &time)
 Updates the timer before the frames are rendered. More...
 
void unpauseTimer ()
 Unpauses the timer - continues with the given state. More...
 
- Public Member Functions inherited from orxonox::Listable
 Listable ()
 Constructor: Allocates space in the element list. More...
 
 Listable (Context *context)
 Constructor: Allocates space in the element list and assigns the context. More...
 
virtual ~Listable ()
 Destructor: Removes the object from the object-lists. More...
 
ContextgetContext () const
 
void setContext (Context *context)
 Changes the context. More...
 
void unregisterObject ()
 Removes this object from the object-lists. More...
 
- Public Member Functions inherited from orxonox::Identifiable
 Identifiable ()
 Constructor: Sets the default values. More...
 
virtual ~Identifiable ()
 
ORX_FORCEINLINE voidgetDerivedPointer (unsigned int classID)
 Returns a valid pointer of any derived type that is registered in the class hierarchy. More...
 
template<class T >
ORX_FORCEINLINE T * getDerivedPointer (unsigned int classID)
 Version of getDerivedPointer with template. More...
 
template<class T >
ORX_FORCEINLINE const T * getDerivedPointer (unsigned int classID) const
 Const version of getDerivedPointer with template. More...
 
IdentifiergetIdentifier () const
 Returns the Identifier of the object. More...
 
bool isA (const Identifier *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
template<class B >
bool isA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isA (const Identifiable *object)
 Returns true if the object's class is of the given type or a derivative. More...
 
bool isChildOf (const Identifier *identifier)
 Returns true if the object's class is a child of the given type. More...
 
template<class B >
bool isChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a child of the given type. More...
 
bool isChildOf (const Identifiable *object)
 Returns true if the object's class is a child of the given type. More...
 
bool isDirectChildOf (const Identifier *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
template<class B >
bool isDirectChildOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectChildOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isDirectParentOf (const Identifier *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
template<class B >
bool isDirectParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a direct parent of the given type. More...
 
bool isDirectParentOf (const Identifiable *object)
 Returns true if the object's class is a direct child of the given type. More...
 
bool isExactlyA (const Identifier *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
template<class B >
bool isExactlyA (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is exactly of the given type. More...
 
bool isExactlyA (const Identifiable *object)
 Returns true if the object's class is exactly of the given type. More...
 
bool isParentOf (const Identifier *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
template<class B >
bool isParentOf (const SubclassIdentifier< B > *identifier)
 Returns true if the object's class is a parent of the given type. More...
 
bool isParentOf (const Identifiable *object)
 Returns true if the object's class is a parent of the given type. More...
 

Protected Member Functions

virtual float getTimeFactor ()
 Returns the current time factor of the game. More...
 

Private Member Functions

void init ()
 Initializes the Timer. More...
 

Private Attributes

bool bActive_
 If true, the timer ticks and calls the executor if the time's up. More...
 
bool bKillAfterCall_
 If true the timer gets deleted after it expired and called the executor. More...
 
bool bLoop_
 If true, the executor gets called every interval seconds. More...
 
ExecutorPtr executor_
 The executor of the function that will be called when the time expires. More...
 
std::function< void(void)> function_
 
long long interval_
 The time-interval in micro seconds. More...
 
bool isStdFunction_
 
long long time_
 Internal variable, counting the time untill the next executor-call. More...
 

Detailed Description

Timer is a helper class that executes a function after a given amount of seconds in game-time.

See also
See Timer.h for an example.

The time interval of Timer depends on the game time, hence it stops if the game is paused or runs slower/faster if the game-speed is modified. See RealTimer for a timer class which doesn't depend on the game time.

Constructor & Destructor Documentation

orxonox::Timer::Timer ( )

Constructor: Sets the default-values.

orxonox::Timer::Timer ( float  interval,
bool  bLoop,
const ExecutorPtr executor,
bool  bKillAfterCall = false 
)

Constructor: Initializes and starts the timer, which will call an executor after some time.

Parameters
intervalThe timer-interval in seconds
bLoopIf true, the executor gets called every interval seconds
executorThe executor that will be called
bKillAfterCallIf true, the timer will be deleted after the executor was called
orxonox::Timer::Timer ( float  interval,
bool  bLoop,
std::function< void(void)>  func,
bool  bKillAfterCall = false 
)

Member Function Documentation

void orxonox::Timer::addTime ( float  time)
inline

Increases the remaining time of the timer by the given amount of time (in seconds).

float orxonox::Timer::getRemainingTime ( ) const
inline

Returns the remaining time until the timer calls the executor.

float orxonox::Timer::getTimeFactor ( )
protectedvirtual

Returns the current time factor of the game.

Reimplemented in orxonox::RealTimer.

void orxonox::Timer::init ( )
private

Initializes the Timer.

bool orxonox::Timer::isActive ( void  ) const
inline

Returns true if the timer is active (neither stopped nor paused).

void orxonox::Timer::pauseTimer ( )
inline

Pauses the timer - it will continue with the actual state if you call unpauseTimer().

void orxonox::Timer::removeTime ( float  time)
inline

Decreases the remaining time of the timer by the given amount of time (in seconds)

void orxonox::Timer::run ( )

Calls the executor and destroys the timer if requested.

void orxonox::Timer::setInterval ( float  interval)
inline

Changes the calling interval.

void orxonox::Timer::setLoop ( bool  bLoop)
inline

Defines if the timer call the executor every interval seconds or only once.

void orxonox::Timer::setTimer ( float  interval,
bool  bLoop,
const ExecutorPtr executor,
bool  bKillAfterCall = false 
)

Initializes and starts the timer, which will call an executor after some time.

Parameters
intervalThe timer-interval in seconds
bLoopIf true, the executor gets called every interval seconds
executorThe executor that will be called
bKillAfterCallIf true, the timer will be deleted after the executor was called
void orxonox::Timer::setTimer ( float  interval,
bool  bLoop,
std::function< void(void)>  func,
bool  bKillAfterCall = false 
)
void orxonox::Timer::startTimer ( )
inline

Re-starts the timer: The executor will be called after interval seconds.

void orxonox::Timer::stopTimer ( )
inline

Stops the timer.

void orxonox::Timer::tick ( const Clock time)

Updates the timer before the frames are rendered.

void orxonox::Timer::unpauseTimer ( )
inline

Unpauses the timer - continues with the given state.

Member Data Documentation

bool orxonox::Timer::bActive_
private

If true, the timer ticks and calls the executor if the time's up.

bool orxonox::Timer::bKillAfterCall_
private

If true the timer gets deleted after it expired and called the executor.

bool orxonox::Timer::bLoop_
private

If true, the executor gets called every interval seconds.

ExecutorPtr orxonox::Timer::executor_
private

The executor of the function that will be called when the time expires.

std::function<void (void)> orxonox::Timer::function_
private
long long orxonox::Timer::interval_
private

The time-interval in micro seconds.

bool orxonox::Timer::isStdFunction_
private
long long orxonox::Timer::time_
private

Internal variable, counting the time untill the next executor-call.


The documentation for this class was generated from the following files: