FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
FIFE::Timer Class Reference

Simple Timer class. More...

#include <timer.h>

+ Inheritance diagram for FIFE::Timer:
+ Collaboration diagram for FIFE::Timer:

Public Types

typedef boost::function0< void > type_callback
 

Public Member Functions

 Timer ()
 Default constructor. More...
 
virtual ~Timer ()
 Destructor. More...
 
void setInterval (int32_t msec)
 Set the interval in milliseconds. More...
 
void start ()
 Start the timer. More...
 
void stop ()
 Stop the timer. More...
 
void setCallback (const type_callback &callback)
 Set the callback that will be called. More...
 

Protected Member Functions

void updateEvent (uint32_t)
 Update function to be overridden by client. More...
 
- Protected Member Functions inherited from FIFE::TimeEvent
 TimeEvent (int32_t period=-1)
 Default constructor. More...
 
virtual ~TimeEvent ()
 Destructor. More...
 
void managerUpdateEvent (uint32_t time)
 Called by TimeManager to update the event. More...
 
void setPeriod (int32_t period)
 Set the period of the event. More...
 
int32_t getPeriod ()
 Get the period of the event. More...
 
uint32_t getLastUpdateTime ()
 Get the last time the event was updated. More...
 
void setLastUpdateTime (uint32_t ms)
 Set the last time the event was updated. More...
 

Protected Attributes

bool m_active
 
type_callback m_callback
 

Detailed Description

Simple Timer class.

This is a simple wrapper around the TimeEvent, which makes the later usable without having to subclass it every time.

m_timer.setInterval(1000);
m_timer.setCallback( boost::bind(&Class::update, this) );
m_timer.start();
Warning
Note that the callback must be available when it is triggered. If your called function is a bound member function and it goes out of scope, when the callback is called you'll most likely have a segfault. So this is best used as a member calling an update function.
Note
You don't have to call TimeManager::registerEvent ever
See also
Console

Definition at line 61 of file timer.h.

Member Typedef Documentation

typedef boost::function0<void> FIFE::Timer::type_callback

Definition at line 63 of file timer.h.

Constructor & Destructor Documentation

FIFE::Timer::Timer ( )

Default constructor.

Constructs an idle timer, use

See also
setInterval and
setCallback to set it up for use.

Definition at line 36 of file timer.cpp.

FIFE::Timer::~Timer ( )
virtual

Destructor.

Stops and destroys the timer.

Definition at line 41 of file timer.cpp.

References stop().

Member Function Documentation

void FIFE::Timer::setCallback ( const type_callback callback)

Set the callback that will be called.

Parameters
callbackA boost::function0 returning void

Definition at line 64 of file timer.cpp.

References m_callback.

Referenced by FIFE::CommandLine::CommandLine(), FIFE::Console::Console(), FIFE::DAT2::DAT2(), FIFE::InstanceRenderer::InstanceRenderer(), and FIFE::TextRenderPool::TextRenderPool().

+ Here is the caller graph for this function:

void FIFE::Timer::setInterval ( int32_t  msec)

Set the interval in milliseconds.

Parameters
msecThe interval If you use an intervall 0 the timer will fire every frame.

Definition at line 60 of file timer.cpp.

References FIFE::TimeEvent::setPeriod(), and stop().

Referenced by FIFE::CommandLine::CommandLine(), FIFE::Console::Console(), FIFE::DAT2::DAT2(), FIFE::InstanceRenderer::InstanceRenderer(), FIFE::InstanceRenderer::setRemoveInterval(), and FIFE::TextRenderPool::TextRenderPool().

+ Here is the caller graph for this function:

void FIFE::Timer::updateEvent ( uint32_t  time)
protectedvirtual

Update function to be overridden by client.

Parameters
timeTime delta.

Implements FIFE::TimeEvent.

Definition at line 68 of file timer.cpp.

References m_active, and m_callback.

Member Data Documentation

bool FIFE::Timer::m_active
protected

Definition at line 106 of file timer.h.

Referenced by start(), stop(), and updateEvent().

type_callback FIFE::Timer::m_callback
protected

Definition at line 107 of file timer.h.

Referenced by setCallback(), and updateEvent().


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