#include <FPSLimiter.h>
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. |
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.
Definition at line 43 of file FPSLimiter.h.
Util::FPSLimiter::FPSLimiter | ( | UINT | nbFrameTypes = 1 |
) |
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.
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.
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().
const UINT Util::FPSLimiter::nbFrameTypes [protected] |