Util::FPSLimiter Class Reference

Handles data about frame rate and allow current thread to be put to sleep in order to keep CPU left for other processes on the computer. More...

#include <FPSLimiter.h>

List of all members.

Public Member Functions

 FPSLimiter (UINT nbFrameTypes=1)
void frame (double time, UINT type=0)
 Tells the object that a frame begins.
bool testFrameNeeded (double time, UINT type=0)
 Tells if a frame has to be computed.
bool frameNeeded (double time, UINT type=0)
 Convinience method that calls testFrameNeeded() and frame() if the first one answered true.
void operator() (double time) const
 Actually do the limitation by putting the current thread to sleep if necessary.
void setMinDelay (double delay, UINT type=0)
 Sets the minimum time between two frames, or <=0 for unlimited.
void setMaxFPS (double fps, UINT type=0)
 Sets the maximum number of frames per seconds, or <=0 for unlimited.

Protected Attributes

const UINT nbFrameTypes
double * lastFrame
 Time of last frame for each type.
double * minDelay
 Minimum time between two frames, for each type, or <=0 for unlimited.


Detailed Description

Handles data about frame rate and allow current thread to be put to sleep in order to keep CPU left for other processes on the computer.

You need an instance for each thread you want to limit. You can use any number of frame types on each thread; that is to say you can have a thread that computes 3D and physics for instance.

Version:
0.2.0 - Currently limits only time between two frames, which is not the same as limiting the average number of FPS. You should set the setting much higher that the average you want to reach.
Author:
Sukender

Definition at line 43 of file FPSLimiter.h.


Constructor & Destructor Documentation

Util::FPSLimiter::FPSLimiter ( UINT  nbFrameTypes = 1  ) 

Definition at line 38 of file FPSLimiter.cpp.

References ASSERT, lastFrame, and minDelay.


Member Function Documentation

void Util::FPSLimiter::frame ( double  time,
UINT  type = 0 
) [inline]

Tells the object that a frame begins.

Definition at line 48 of file FPSLimiter.h.

References ASSERT.

bool Util::FPSLimiter::frameNeeded ( double  time,
UINT  type = 0 
) [inline]

Convinience method that calls testFrameNeeded() and frame() if the first one answered true.

Definition at line 57 of file FPSLimiter.h.

void Util::FPSLimiter::operator() ( double  time  )  const

Actually do the limitation by putting the current thread to sleep if necessary.

Definition at line 55 of file FPSLimiter.cpp.

References lastFrame, MIN_SLEEP_DELAY, minDelay, and nbFrameTypes.

void Util::FPSLimiter::setMaxFPS ( double  fps,
UINT  type = 0 
) [inline]

Sets the maximum number of frames per seconds, or <=0 for unlimited.

Warning:
Currently it is like setMinDelay(1/fps), but this should change in future versions (it should affect the averaged count over a specified period).

Definition at line 73 of file FPSLimiter.h.

References ASSERT.

void Util::FPSLimiter::setMinDelay ( double  delay,
UINT  type = 0 
) [inline]

Sets the minimum time between two frames, or <=0 for unlimited.

Definition at line 67 of file FPSLimiter.h.

References ASSERT.

bool Util::FPSLimiter::testFrameNeeded ( double  time,
UINT  type = 0 
)

Tells if a frame has to be computed.

Definition at line 47 of file FPSLimiter.cpp.

References ASSERT, lastFrame, minDelay, and nbFrameTypes.


Member Data Documentation

double* Util::FPSLimiter::lastFrame [protected]

Time of last frame for each type.

Definition at line 80 of file FPSLimiter.h.

Referenced by FPSLimiter(), operator()(), and testFrameNeeded().

double* Util::FPSLimiter::minDelay [protected]

Minimum time between two frames, for each type, or <=0 for unlimited.

Definition at line 81 of file FPSLimiter.h.

Referenced by FPSLimiter(), operator()(), and testFrameNeeded().

Definition at line 79 of file FPSLimiter.h.

Referenced by operator()(), and testFrameNeeded().


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

Generated on Sun Jan 17 11:39:37 2010 for PVLE (Pro-Vocation Light Engine) by  doxygen 1.5.9