libdonut
2.3.2
Application framework for cross-platform game development in C++20
|
Main application base class. More...
#include <donut/application/Application.hpp>
Public Member Functions | |
Application (const ApplicationOptions &options={}) | |
Construct the base of the main application. More... | |
virtual | ~Application ()=default |
Virtual destructor which must be overridden by the concrete application class in order to perform any application-specific cleanup before shutdown. More... | |
void | run () |
Start the main loop of the application and keep running until the application quits or an unhandled exception is thrown. More... | |
virtual void | quit () |
Initiate the shutdown process, meaning that the current frame will be the last to be processed and displayed before the main loop ends. More... | |
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. More... | |
unsigned | 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. More... | |
void | setFrameRateParameters (float tickRate, float minFrameRate, float maxFrameRate) |
Set the frame rate parameters of the application. More... | |
void | setFrameRateLimiterSleepEnabled (bool frameRateLimiterSleepEnabled) |
Enable or disable frame rate limiter sleep. More... | |
void | setFrameRateLimiterSleepBias (std::chrono::steady_clock::duration frameRateLimiterSleepBias) |
Set the frame rate limiter sleep bias. More... | |
TickInfo | getLatestTickInfo () const noexcept |
Get information about the latest tick. More... | |
FrameInfo | getLatestFrameInfo () const noexcept |
Get information about the latest frame. More... | |
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. More... | |
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(). More... | |
virtual void | display (TickInfo tickInfo, 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. More... | |
Main application base class.
The application controls the main loop, including frame pacing and fixed-interval frame rate-independent tick updates.
Concrete applications should derive from this class and implement the associated virtual functions in order to receive all of the relevant callbacks. Deriving from this class also ensures that it is constructed before any code in the concrete application is executed, which means that any global systems will be properly initialized before any code that may depend on them is able to run, assuming all user code is constrained to being called from an instance of the concrete application class.
|
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 donut::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. |
|
virtual |
Initiate the shutdown process, meaning that the current frame will be the last to be processed and displayed before the main loop ends.
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. |
|
inlinenoexcept |
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.
|
inlinenoexcept |
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.
void donut::application::Application::setFrameRateParameters | ( | float | tickRate, |
float | minFrameRate, | ||
float | maxFrameRate | ||
) |
Set the frame rate parameters of the application.
tickRate | desired tick rate of the application, in hertz (ticks per second). Set to 0 or a negative value for no ticks. |
minFrameRate | minimum frame rate of the application, in hertz (frames per second), before tick slowdown occurs. |
maxFrameRate | maximum frame rate of the application, in hertz (frames per second), before frames are delayed. Set to 0 or a negative value for no frame rate limit. |
void donut::application::Application::setFrameRateLimiterSleepEnabled | ( | bool | frameRateLimiterSleepEnabled | ) |
Enable or disable frame rate limiter sleep.
frameRateLimiterSleepEnabled | true to enable frame rate limiter sleep, false to disable. |
void donut::application::Application::setFrameRateLimiterSleepBias | ( | std::chrono::steady_clock::duration | frameRateLimiterSleepBias | ) |
Set the frame rate limiter sleep bias.
frameRateLimiterSleepBias | new bias to set. Must be non-negative. |
|
inlinenoexcept |
Get information about the latest tick.
|
inlinenoexcept |
Get information about the latest 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 |
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().
tickInfo | information about the latest tick, see TickInfo. |
frameInfo | information about the latest frame, see FrameInfo. |