4#ifndef GREM_APPLICATION_APPLICATION_HPP
5#define GREM_APPLICATION_APPLICATION_HPP
247 return lastSecondFrameCount;
259 return latestTickInfo.tickInterval;
272 return maxAccumulatedTickTime;
371 return latestTickInfo;
381 return latestFrameInfo;
473 GREM_API(
application)
void updateMaxTicksPerFrame() noexcept;
480 Clock::rep maxTicksPerFrame{};
485 ExponentialMovingAverage<FloatMilliseconds> frameRateLimiterSleepError{};
486 size_t lastSecondFrameCount = 0;
487 size_t frameCounter = 0;
488 TickInfo latestTickInfo{};
489 FrameInfo latestFrameInfo{};
490 bool frameRateLimiterSleepEnabled =
false;
491 bool running =
false;
492 bool quitting =
false;
519 constexpr operator int() const noexcept {
void setMaxAccumulatedTickTime(Duration newMaxAccumulatedTickTime) noexcept
Set the maximum accumulated tick time of the application.
virtual void tick(TickInfo tickInfo)
Fixed-rate tick callback, called in the main loop 0 or more times during tick processing,...
Definition Application.hpp:428
virtual void display(FrameInfo frameInfo)
Frame rendering callback, called in the main loop once at the end of each frame after processing tick...
Definition Application.hpp:468
void run()
Start the main loop of the application and keep running until the application quits or an unhandled e...
Duration getMinFrameTime() const noexcept
Get the minimum frame time of the application.
Definition Application.hpp:284
FrameInfo getLatestFrameInfo() const noexcept
Get the latest available frame information, including any configuration changes since the last frame.
Definition Application.hpp:380
bool isRunning() const noexcept
Check if the application is currently running, meaning that it is fully initialized,...
Definition Application.hpp:217
virtual void quit() noexcept
Initiate the shutdown process, meaning that the current frame will be the last to be processed before...
bool isQuitting() const noexcept
Check if the application is in the process of shutting down.
Definition Application.hpp:226
Application(const ApplicationOptions &options={})
Construct the base of the main application.
void setTickInterval(Duration newTickInterval) noexcept
Set the tick interval of the application.
virtual void skipTick(Duration tickInterval)
Callback for ticks that were skipped due to the accumulated tick time exceeding ApplicationOptions::m...
Definition Application.hpp:445
virtual void update(FrameInfo frameInfo)
Per-frame update callback, called in the main loop once at the beginning of each frame,...
Definition Application.hpp:405
Duration getMaxAccumulatedTickTime() const noexcept
Get the maximum accumulated tick time of the application.
Definition Application.hpp:271
Duration getMaxFrameTime() const noexcept
Get the maximum frame time of the application.
Definition Application.hpp:297
size_t getLastSecondFrameCount() const noexcept
Get the number of frames displayed during the last measured second of the application's run time,...
Definition Application.hpp:246
void setMaxFrameTime(Duration newMaxFrameTime) noexcept
Set the maximum frame time of the application.
TickInfo getLatestTickInfo() const noexcept
Get the latest available tick information, including any configuration changes since the last tick.
Definition Application.hpp:370
virtual ~Application()=default
Virtual destructor which must be overridden by the concrete application class in order to perform any...
void resetTickTimer() noexcept
Reset the internal tick accumulator, causing the next tick to start exactly one tick interval into th...
void setFrameRateLimiterSleepEnabled(bool newFrameRateLimiterSleepEnabled) noexcept
Enable or disable frame rate limiter sleep.
void setMinFrameTime(Duration newMinFrameTime) noexcept
Set the minimum frame time of the application.
Duration getTickInterval() const noexcept
Get the tick interval of the application.
Definition Application.hpp:258
static const ExitCode SUCCESS
Standard exit code value for indicating that the program completed successfully.
Definition Application.hpp:500
constexpr ExitCode(int value) noexcept
Construct an exit code.
Definition Application.hpp:511
static const ExitCode FAILURE
Standard exit code value for indicating that the program encountered an error.
Definition Application.hpp:501
Definition Application.hpp:18
Clock::duration Duration
Definition Clock.hpp:25
Clock::time_point TimePoint
Definition Clock.hpp:26
DurationBase< float, Ratio< 1, 1 > > FloatSeconds
Definition time.hpp:60
DurationBase< int64_t, Ratio< 1, 1 > > Seconds
Definition time.hpp:53
Configuration options for an Application.
Definition Application.hpp:23
Duration tickInterval
Desired average time between ticks, i.e. the reciprocal of the application's desired tick rate.
Definition Application.hpp:53
Duration minFrameTime
Minimum frame time before frames are delayed, i.e. the reciprocal of the application's maximum frame ...
Definition Application.hpp:85
Duration maxFrameTime
Maximum frame time before tick time is accumulated and deferred to later frames, i....
Definition Application.hpp:113
Duration maxAccumulatedTickTime
Maximum time to process accumulated ticks for before starting to skip ticks.
Definition Application.hpp:69
bool frameRateLimiterSleepEnabled
Put the thread that is running the application to sleep until the next frame is supposed to begin if ...
Definition Application.hpp:126
Transient information about the current frame of an Application.
Definition FrameInfo.hpp:16
Transient information about the current tick of an Application.
Definition TickInfo.hpp:17