![]() |
CRM64Pro GDK v0.13.0
A free cross-platform game development kit built on top of SDL 3.0
|
Timer interface for timing control, frame rates and micro-benchmarking [v25.12.0].
The Timer interface manages all timing-related functionality including timer control, Render Frame Rate, Logic Frame Rate and micro-benchmarks. 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 in this interface and in Main::update() method.
By default, no preferred Render and Logic Frame Rate are set (both equal to 0). Use setRate() to configure specific values. Rates can be throttled down, but upper limits are imposed by the underlying hardware and ConfigMgr::iMTFriendly value.
| Render Frame Rate (RFR) | Asynchronous rate that does not stop your main loop. Renders all enabled and visible screens at the preferred rate. This rate is not guaranteed as some render frames may be dropped to maintain stable LFR. When vsync is enabled, set RFR to 0 for smoothest output |
|---|---|
| Logic Frame Rate (LFR) | Synchronous rate that slows down your main loop to accommodate this rate. Under normal conditions (hardware can execute at preferred ratio), this rate remains quite stable |
The micro-benchmarking system measures small code snippets, capturing execution time and calculating statistical analysis on those measurements.
Thread safety
Although the system is not fully thread-safe, it can be made thread-safe by following these steps:
Benchmark workflow
| benchBegin() | Create a named benchmark with estimated run count, or start a measurement cycle |
|---|---|
| benchEnd() | End the current measurement cycle |
| benchStats() | Retrieve statistical results into a Timer::Stats structure |
| benchClose() | Close the benchmark and release resources |
Deterministic function testing
Testing a function with a known number of iterations:
Application behavior profiling
Measuring logic and render performance throughout application lifetime:
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.
Writes information to the default log.
| iMode | -1 for displaying only Manager information. 0 (default) for displaying Manager and all Objects information. |
| Sint32 CRM64Pro::Timer::init | ( | eTimerState | tsOpt = TS_INIT | ) |
Initialize the timer system.
The first call to this method initializes the SDL timer subsystem.
| tsOpt | Check ::eTimerState enum for further information. Default is TS_INIT. |
| Sint32 CRM64Pro::Timer::setRate | ( | Uint16 | iR, |
| Uint16 | iL ) |
Set preferred Render and Logic Frame Rate.
| iR | preferred Render Frame Rate. Default 0 means unlimited. Maximum value is 500. |
| iL | preferred Logic Frame Rate. Default 0 means unlimited. 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. Default 0 (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. |