CRM64Pro GDK v0.11.0
A free cross-platform game development kit built on top of SDL 3.0
|
v1.00 (22 June 2023)
The Timer interface manages all timing related stuff: timer control, Render Frame Rate, Logic Frame Rate and microbenchmarks.
The Timer must be initiated with Timer::init().
One of the most important features is the fixed virtual logic frame rate with interpolation which is implemented on this interface and in Main::update() method:
By default, no preferred Render and Logic Frame Rate are set (they are equal to 0) so if you want to use specific values, you must use setRate().
The rates can be adjusted (throttle down) but the upper limit is imposed by the underlying hardware where the application is executed, there is also a synergy between upper limits and ConfigMgr::iMTFriendly value.
It is important to say that the Render Frame Rate (if enabled) will be used for all enabled and visible screens.
There is a micro-benchmarking system. It is used for benchmarking small snippets of code. It runs your code, measures the time and then calculate some statistical analysis on those measurements.
Although the system is not fully thread-safe, it can easily be "thread-safe" following the below steps:
It can be used on several ways but the most commons are for testing a function in a deterministic way as the following example:
Or for measuring the behaviour of your application and getting a final report once the application exists as shown below:
Only a single instance of the Timer interface exists which is created once Main is instantiated.
You can get a reference to this interface using Main::ITimer() method.
Classes | |
class | CRM64Pro::Timer |
Timer class. More... | |
Enumerations | |
enum | CRM64Pro::eTimerState { CRM64Pro::TS_INIT = 0 , CRM64Pro::TS_RESET = 1 } |
Timer init state. More... | |
Functions | |
Sint32 | CRM64Pro::Timer::info (Sint32 iMode=0) |
Request Timer Interface information. | |
Sint32 | CRM64Pro::Timer::init (eTimerState tsOpt=TS_INIT) |
Initialize the timer system. | |
Sint32 | CRM64Pro::Timer::setRate (Uint16 iR, Uint16 iL) |
Set preferred Render and Logic Frame Rate. | |
Sint32 | CRM64Pro::Timer::getLFR () |
Get the preferred Logic Frame Rate. | |
Sint32 | CRM64Pro::Timer::getRFR () |
Get the preferred Render Frame Rate. | |
float | CRM64Pro::Timer::getAverageRFR () |
Get the average Render Frame Rate since the last timer init or reset. | |
float | CRM64Pro::Timer::getAverageLFR () |
Get the average Logic Frame Rate since the last timer init or reset. | |
Uint32 | CRM64Pro::Timer::getCurrentRFR () |
Get current Render Frame Rate during last recent second. | |
Uint32 | CRM64Pro::Timer::getCurrentLFR () |
Get current Logic Frame Rate during last recent second. | |
Uint32 | CRM64Pro::Timer::getRenderFrames () |
Get total render frames since the last timer init or reset. | |
Uint32 | CRM64Pro::Timer::getLogicFrames () |
Get total logic frames since the last timer init or reset. | |
float | CRM64Pro::Timer::getTime () |
Get the execution time (in seconds) since the last timer init or reset. | |
Uint64 | CRM64Pro::Timer::getTicks () |
Get the execution time (in milliseconds) since the last timer init or reset. | |
Uint64 | CRM64Pro::Timer::getTicksNow () |
Get the execution time (in milliseconds) since the last timer init or reset. | |
Uint64 | CRM64Pro::Timer::getHiResTime () |
Get the execution time (in nanoseconds) since the last timer init or reset. | |
Sint32 | CRM64Pro::Timer::benchBegin (const string &sName, Sint32 iRuns=0) |
Create and begin a microbenchmark test. | |
Sint32 | CRM64Pro::Timer::benchBegin (Sint32 idBench) |
Begin a microbenchmark test. | |
Sint32 | CRM64Pro::Timer::benchEnd (Sint32 idBench) |
End a microbenchmark test. | |
Sint32 | CRM64Pro::Timer::benchClose (Sint32 idBench) |
Close a microbenchmark test. | |
Sint32 | CRM64Pro::Timer::benchStats (Sint32 idBench, Stats &stats) |
Calculate the statistical analysis given the current measurements. | |
Timer init state.
Enumerator | |
---|---|
TS_INIT | 'tsOpt' parameter in Timer::init(), initializes or resets all timer settings. |
TS_RESET | 'tsOpt' parameter in Timer::init(), only resets the timer if it was previously initialized keeping RFR and LFR rates. |
Sint32 CRM64Pro::Timer::info | ( | Sint32 | iMode = 0 | ) |
Request Timer Interface information.
For displaying the information, it uses the default log.
iMode | -1 for displaying only Manager information. 0 for displaying Manager and all Objects information. This is the default value. |
Sint32 CRM64Pro::Timer::init | ( | eTimerState | tsOpt = TS_INIT | ) |
Initialize the timer system.
The first call to this method, SDL timer subsystem will be initialized.
tsOpt | Check eTimerState enum for further information. By default TS_INIT is set. |
Sint32 CRM64Pro::Timer::setRate | ( | Uint16 | iR, |
Uint16 | iL | ||
) |
Set preferred Render and Logic Frame Rate.
iR | an integer value with preferred Render Frame Rate. By default it is set to 0 which does not limit this rate. Maximum value is 500. |
iL | an integer value with preferred Logic Frame Rate. By default it is set to 0 which does not limit this rate. Maximum value is 20000. |
Sint32 CRM64Pro::Timer::getLFR | ( | ) |
Get the preferred Logic Frame Rate.
Sint32 CRM64Pro::Timer::getRFR | ( | ) |
Get the preferred Render Frame Rate.
float CRM64Pro::Timer::getAverageRFR | ( | ) |
Get the average Render Frame Rate since the last timer init or reset.
float CRM64Pro::Timer::getAverageLFR | ( | ) |
Get the average Logic Frame Rate since the last timer init or reset.
Uint32 CRM64Pro::Timer::getCurrentRFR | ( | ) |
Get current Render Frame Rate during last recent second.
Uint32 CRM64Pro::Timer::getCurrentLFR | ( | ) |
Get current Logic Frame Rate during last recent second.
Uint32 CRM64Pro::Timer::getRenderFrames | ( | ) |
Get total render frames since the last timer init or reset.
Uint32 CRM64Pro::Timer::getLogicFrames | ( | ) |
Get total logic frames since the last timer init or reset.
float CRM64Pro::Timer::getTime | ( | ) |
Get the execution time (in seconds) since the last timer init or reset.
This time will be constant inside the same Logic Frame iteration and will be updated on Main::update() if a new Logic Frame must be produced.
Uint64 CRM64Pro::Timer::getTicks | ( | ) |
Get the execution time (in milliseconds) since the last timer init or reset.
This time will be constant inside the same Logic Frame iteration and will be updated on Main::update() if a new Logic Frame must be produced.
Uint64 CRM64Pro::Timer::getTicksNow | ( | ) |
Get the execution time (in milliseconds) since the last timer init or reset.
This time will be exactly the "now" time, on other words, it is not linked anyway to the Logic Frame iteration.
Uint64 CRM64Pro::Timer::getHiResTime | ( | ) |
Get the execution time (in nanoseconds) since the last timer init or reset.
This is the high resolution timer when you need more accurate time precision.
Sint32 CRM64Pro::Timer::benchBegin | ( | const string & | sName, |
Sint32 | iRuns = 0 |
||
) |
Create and begin a microbenchmark test.
sName | string with the name of this benchmark. |
iRuns | estimated number of runs. By default it is set to 0. In any case, it is automatically managed. |
Sint32 CRM64Pro::Timer::benchBegin | ( | Sint32 | idBench | ) |
Begin a microbenchmark test.
idBench | Bench id. |
Sint32 CRM64Pro::Timer::benchEnd | ( | Sint32 | idBench | ) |
End a microbenchmark test.
idBench | Bench id. |
Sint32 CRM64Pro::Timer::benchClose | ( | Sint32 | idBench | ) |
Close a microbenchmark test.
Free the resources of the test and the stats.
idBench | Bench id. |
Sint32 CRM64Pro::Timer::benchStats | ( | Sint32 | idBench, |
Stats & | stats | ||
) |
Calculate the statistical analysis given the current measurements.
idBench | Bench id. |
stats | a Stats struct to be filled with current stats. The values are given in milliseconds. |