Engine
The Game Engine for Ian Parberry's "Introduction to Game Physics with Box2D"
 All Classes Files Functions Variables Pages
Public Member Functions | List of all members
CTimer Class Reference

The timer. More...

#include <Timer.h>

Public Member Functions

 CTimer ()
 Constructor.
 
void start ()
 Start the timer.
 
int time ()
 Return the time in ms.
 
BOOL elapsed (int &start, int interval)
 Has interval ms elapsed since start?
 
void beginframe ()
 Freeze the time returned for the duration of this frame.
 
int GetLevelStartTime ()
 Get time that the level started.
 
int GetLevelElapsedTime ()
 Get elapsed time since the level started.
 
void StartLevelTimer ()
 Start the level timer.
 
void StopLevelTimer ()
 Stop the level timer.
 

Detailed Description

The timer.

The timer allows you to manage game events by duration, rather than on a frame-by-frame basis. This simple version of the timer is based on the Windows API function timeGetTime, which is notoriously inaccurate but perfectly adequate for a simple game demo.

Member Function Documentation

void CTimer::beginframe ( void  )

Freeze the time returned for the duration of this frame.

This is the signal that a new animation frame has begun, so that the timer can return the same time value for the duration of this frame.

int CTimer::elapsed ( int &  start,
int  interval 
)

Has interval ms elapsed since start?

The elapsed function is a useful function for measuring repeating time intervals. Given the start and duration times, this function returns TRUE if the interval is over, and has the side-effect of resetting the start time when that happens, thus setting things up for the next interval.

Parameters
startstart of time interval
intervalduration of time interval
Returns
TRUE if time interval is over
int CTimer::GetLevelElapsedTime ( )

Get elapsed time since the level started.

Returns
Level elapsed time.
int CTimer::GetLevelStartTime ( )

Get time that the level started.

Returns
Level start time.
int CTimer::time ( )

Return the time in ms.

Get current time.

Returns
Current time since start in milliseconds.

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