|
GREM 3.12.0
Game/Rendering Engine Modules for C++
|
Main application base class. More...
#include <GREM/application/Application.hpp>
Public Member Functions | |
| Application (const ApplicationOptions &options={}) | |
| Construct the base of the main application. | |
| virtual | ~Application ()=default |
| Virtual destructor which must be overridden by the concrete application class in order to perform any application-specific cleanup before shutdown. | |
| void | run () |
| Start the main loop of the application and keep running until the application quits or an unhandled exception is thrown. | |
| virtual void | quit () noexcept |
| Initiate the shutdown process, meaning that the current frame will be the last to be processed before the main loop ends. | |
| bool | isRunning () const noexcept |
| Check if the application is currently running, meaning that it is fully initialized, that run() has been called and has started the main loop, and that it is not in the process of shutting down. | |
| bool | isQuitting () const noexcept |
| Check if the application is in the process of shutting down. | |
| size_t | getLastSecondFrameCount () const noexcept |
| Get the number of frames displayed during the last measured second of the application's run time, which approximates the average frame rate. | |
| Duration | getTickInterval () const noexcept |
| Get the tick interval of the application. | |
| Duration | getMaxAccumulatedTickTime () const noexcept |
| Get the maximum accumulated tick time of the application. | |
| Duration | getMinFrameTime () const noexcept |
| Get the minimum frame time of the application. | |
| Duration | getMaxFrameTime () const noexcept |
| Get the maximum frame time of the application. | |
| void | resetTickTimer () noexcept |
| Reset the internal tick accumulator, causing the next tick to start exactly one tick interval into the future. | |
| void | setTickInterval (Duration newTickInterval) noexcept |
| Set the tick interval of the application. | |
| void | setMaxAccumulatedTickTime (Duration newMaxAccumulatedTickTime) noexcept |
| Set the maximum accumulated tick time of the application. | |
| void | setMinFrameTime (Duration newMinFrameTime) noexcept |
| Set the minimum frame time of the application. | |
| void | setMaxFrameTime (Duration newMaxFrameTime) noexcept |
| Set the maximum frame time of the application. | |
| void | setFrameRateLimiterSleepEnabled (bool newFrameRateLimiterSleepEnabled) noexcept |
| Enable or disable frame rate limiter sleep. | |
| TickInfo | getLatestTickInfo () const noexcept |
| Get the latest available tick information, including any configuration changes since the last tick. | |
| FrameInfo | getLatestFrameInfo () const noexcept |
| Get the latest available frame information, including any configuration changes since the last frame. | |
Protected Member Functions | |
| virtual void | update (FrameInfo frameInfo) |
| Per-frame update callback, called in the main loop once at the beginning of each frame, before processing ticks. | |
| virtual void | tick (TickInfo tickInfo) |
| Fixed-rate tick callback, called in the main loop 0 or more times during tick processing, which happens on each frame after calling update() and before calling display(). | |
| virtual void | skipTick (Duration tickInterval) |
| Callback for ticks that were skipped due to the accumulated tick time exceeding ApplicationOptions::maxAccumulatedTickTime. | |
| virtual void | display (FrameInfo frameInfo) |
| Frame rendering callback, called in the main loop once at the end of each frame after processing ticks, in order to render the latest state of the application. | |
Main application base class.
Deriving from this class provides a platform-agnostic wrapper for the main loop that includes a built-in frame rate limiter and fixed-interval frame rate-independent tick callbacks.
|
explicit |
Construct the base of the main application.
| options | initial configuration of the application, see ApplicationOptions. |
|
virtualdefault |
Virtual destructor which must be overridden by the concrete application class in order to perform any application-specific cleanup before shutdown.
May also be overridden implicitly by the compiler-generated destructor of the derived class.
| void grem::application::Application::run | ( | ) |
Start the main loop of the application and keep running until the application quits or an unhandled exception is thrown.
| any | unhandled exception which was thrown during the execution of the main loop, unless running under emscripten, in which case exceptions are simply printed before shutting down. |
|
virtualnoexcept |
Initiate the shutdown process, meaning that the current frame will be the last to be processed before the main loop ends.
If called during update(), no ticks will be processed afterwards, and the final frame will not be displayed.
This method may be overridden by the concrete application to intercept requests to quit and perform application-specific processing before deciding whether to actually quit or not by either calling the base implementation or choosing to ignore the request.
| any | exception thrown by the concrete implementation. |
|
inlinenodiscardnoexcept |
Check if the application is currently running, meaning that it is fully initialized, that run() has been called and has started the main loop, and that it is not in the process of shutting down.
|
inlinenodiscardnoexcept |
Check if the application is in the process of shutting down.
|
inlinenodiscardnoexcept |
Get the number of frames displayed during the last measured second of the application's run time, which approximates the average frame rate.
This is measured automatically by counting the number of frames displayed between each second that passes while the application is running.
|
inlinenodiscardnoexcept |
Get the tick interval of the application.
|
inlinenodiscardnoexcept |
Get the maximum accumulated tick time of the application.
|
inlinenodiscardnoexcept |
Get the minimum frame time of the application.
|
inlinenodiscardnoexcept |
Get the maximum frame time of the application.
|
noexcept |
Reset the internal tick accumulator, causing the next tick to start exactly one tick interval into the future.
|
noexcept |
Set the tick interval of the application.
| newTickInterval | desired tick interval of the application. Set to zero or lower for no ticks. |
|
noexcept |
Set the maximum accumulated tick time of the application.
| newMaxAccumulatedTickTime | maximum time to process accumulated ticks for before starting to skip ticks. |
|
noexcept |
Set the minimum frame time of the application.
| newMinFrameTime | minimum frame time of the application before frames are delayed. Set to zero or lower for no frame rate limit. |
|
noexcept |
Set the maximum frame time of the application.
| newMaxFrameTime | maximum frame time of the application before tick slowdown occurs. |
|
noexcept |
Enable or disable frame rate limiter sleep.
| newFrameRateLimiterSleepEnabled | true to enable frame rate limiter sleep, false to disable. |
|
inlinenodiscardnoexcept |
Get the latest available tick information, including any configuration changes since the last tick.
|
inlinenodiscardnoexcept |
Get the latest available frame information, including any configuration changes since the last frame.
|
inlineprotectedvirtual |
Per-frame update callback, called in the main loop once at the beginning of each frame, before processing ticks.
This is the best time to poll events using an EventPump and apply any changes to interactive application state that depends on user input and is used by tick(), since it minimizes the average latency between processing an input event and it affecting the result of a subsequent tick.
| frameInfo | information about the current frame, see FrameInfo. |
|
inlineprotectedvirtual |
Fixed-rate tick callback, called in the main loop 0 or more times during tick processing, which happens on each frame after calling update() and before calling display().
See the documentation of TickInfo::tickInterval for an explanation of what this function may be useful for.
| tickInfo | information about the current tick, see TickInfo. |
|
inlineprotectedvirtual |
Callback for ticks that were skipped due to the accumulated tick time exceeding ApplicationOptions::maxAccumulatedTickTime.
| tickInterval | the average time that would have elapsed for this tick if it hadn't been skipped. |
|
inlineprotectedvirtual |
Frame rendering callback, called in the main loop once at the end of each frame after processing ticks, in order to render the latest state of the application.
Before rendering, this is also the best time to apply any final cosmetic changes to the state of the application that is about to be presented, such as interpolation of data that is updated in tick().
| frameInfo | information about the current frame, see FrameInfo. |