OpenXcom  1.0
Open-source clone of the original X-Com
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Public Member Functions | List of all members
OpenXcom::Timer Class Reference

Timer used to run code in fixed intervals. More...

#include <Timer.h>

Public Member Functions

 Timer (Uint32 interval, bool frameSkipping=false)
 Creates a stopped timer. More...
 
 ~Timer ()
 Cleans up the timer.
 
void start ()
 Starts the timer. More...
 
void stop ()
 Stops the timer. More...
 
Uint32 getTime () const
 Gets the current time interval. More...
 
bool isRunning () const
 Gets if the timer's running. More...
 
void think (State *state, Surface *surface)
 Advances the timer. More...
 
void setInterval (Uint32 interval)
 Sets the timer's interval. More...
 
void onTimer (StateHandler handler)
 Hooks a state action handler to the timer interval. More...
 
void onTimer (SurfaceHandler handler)
 Hooks a surface action handler to the timer interval. More...
 
void setFrameSkipping (bool skip)
 Turns frame skipping on or off. More...
 

Detailed Description

Timer used to run code in fixed intervals.

Used for code that should run at the same fixed interval in various machines, based on miliseconds instead of CPU cycles.

Constructor & Destructor Documentation

OpenXcom::Timer::Timer ( Uint32  interval,
bool  frameSkipping = false 
)

Creates a stopped timer.

Initializes a new timer with a set interval.

Parameters
intervalTime interval in milliseconds.
frameSkippingUse frameskipping.

Member Function Documentation

Uint32 OpenXcom::Timer::getTime ( ) const

Gets the current time interval.

Returns the time passed since the last interval.

Returns
Time in milliseconds.
bool OpenXcom::Timer::isRunning ( ) const

Gets if the timer's running.

Returns if the timer has been started.

Returns
Running state.
void OpenXcom::Timer::onTimer ( StateHandler  handler)

Hooks a state action handler to the timer interval.

Sets a state function for the timer to call every interval.

Parameters
handlerEvent handler.
void OpenXcom::Timer::onTimer ( SurfaceHandler  handler)

Hooks a surface action handler to the timer interval.

Sets a surface function for the timer to call every interval.

Parameters
handlerEvent handler.
void OpenXcom::Timer::setFrameSkipping ( bool  skip)

Turns frame skipping on or off.

Sets frame skipping on or off.

Parameters
skipEnable frameskipping.
void OpenXcom::Timer::setInterval ( Uint32  interval)

Sets the timer's interval.

Changes the timer's interval to a new value.

Parameters
intervalInterval in milliseconds.
void OpenXcom::Timer::start ( )

Starts the timer.

Starts the timer running and counting time.

void OpenXcom::Timer::stop ( )

Stops the timer.

Stops the timer from running.

void OpenXcom::Timer::think ( State state,
Surface surface 
)

Advances the timer.

The timer keeps calculating the passed time while it's running, calling the respective action handler whenever the set interval passes.

Parameters
stateState that the action handler belongs to.
surfaceSurface that the action handler belongs to.

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