Antkeeper
0.0.1
|
Schedules fixed- and variable-rate updates. More...
#include <frame-scheduler.hpp>
Public Types | |
using | clock_type = std::conditional< std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock, std::chrono::steady_clock >::type |
Clock type is std::chrono::high_resolution_clock if steady, std::chrono::steady_clock otherwise. More... | |
using | duration_type = clock_type::duration |
Duration type matches the clock's duration type. More... | |
using | time_point_type = clock_type::time_point |
Time point type matches the clock's time point type. More... | |
using | fixed_update_callback_type = std::function< void(duration_type, duration_type)> |
Fixed-rate update callback function type. More... | |
using | variable_update_callback_type = std::function< void(duration_type, duration_type, duration_type)> |
Variable-rate callback function type. More... | |
Public Member Functions | |
frame_scheduler () noexcept | |
Constructs a frame scheduler and starts its frame timer. More... | |
void | tick () |
Performs any scheduled fixed-rate updates followed by a single variable-rate update. More... | |
void | refresh () noexcept |
Resets the accumulated time (at ) and frame timer, but not the elapsed fixed-rate update time. More... | |
void | reset () noexcept |
Resets the elapsed fixed-rate update time (t ), accumulated time (at ), and frame timer. More... | |
void | set_fixed_update_interval (duration_type interval) noexcept |
Sets the interval (dt ) at which fixed-rate updates are scheduled. More... | |
void | set_min_frame_duration (duration_type duration) noexcept |
Sets the minimum frame duration. More... | |
void | set_max_frame_duration (duration_type duration) noexcept |
Sets the maximum accumulated frame duration. More... | |
duration_type | get_fixed_update_time () const noexcept |
Returns the elapsed fixed-rate update time (t ). More... | |
duration_type | get_accumulated_time () const noexcept |
Returns the accumulated time (at ). More... | |
duration_type | get_frame_duration () const noexcept |
Returns the duration of the previous frame. More... | |
duration_type | get_min_frame_duration () const noexcept |
Returns the minimum frame duration. More... | |
duration_type | get_max_frame_duration () const noexcept |
Returns the maximum frame duration. More... | |
duration_type | get_fixed_update_interval () const noexcept |
Returns the fixed-rate update interval (dt ). More... | |
const fixed_update_callback_type & | get_fixed_update_callback () const noexcept |
Returns the fixed-rate update callback. More... | |
const variable_update_callback_type & | get_variable_update_callback () const noexcept |
Returns the variable-rate update callback. More... | |
void | set_fixed_update_callback (fixed_update_callback_type &&callback) noexcept |
Sets the fixed-rate update callback. More... | |
void | set_fixed_update_callback (const fixed_update_callback_type &callback) noexcept |
Sets the fixed-rate update callback. More... | |
void | set_variable_update_callback (variable_update_callback_type &&callback) noexcept |
Sets the variable-rate update callback. More... | |
void | set_variable_update_callback (const variable_update_callback_type &callback) noexcept |
Sets the variable-rate update callback. More... | |
Schedules fixed- and variable-rate updates.
Definition at line 32 of file frame-scheduler.hpp.
using frame_scheduler::clock_type = std::conditional < std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock, std::chrono::steady_clock >::type |
Clock type is std::chrono::high_resolution_clock
if steady, std::chrono::steady_clock
otherwise.
Definition at line 36 of file frame-scheduler.hpp.
using frame_scheduler::duration_type = clock_type::duration |
Duration type matches the clock's duration type.
Definition at line 43 of file frame-scheduler.hpp.
using frame_scheduler::fixed_update_callback_type = std::function<void(duration_type, duration_type)> |
Fixed-rate update callback function type.
The first parameter is the elapsed time (t
) and the second parameter is the fixed-rate update interval (dt
).
Definition at line 53 of file frame-scheduler.hpp.
using frame_scheduler::time_point_type = clock_type::time_point |
Time point type matches the clock's time point type.
Definition at line 46 of file frame-scheduler.hpp.
using frame_scheduler::variable_update_callback_type = std::function<void(duration_type, duration_type, duration_type)> |
Variable-rate callback function type.
The first parameter is the elapsed time (t
), the second parameter is the fixed-rate update interval (dt
), and the third parameter is the accumulated time since the previous fixed-rate update (at
).
alpha
) can be calculated as at / dt
. Definition at line 62 of file frame-scheduler.hpp.
|
noexcept |
Constructs a frame scheduler and starts its frame timer.
Definition at line 24 of file frame-scheduler.cpp.
|
inlinenoexcept |
Returns the accumulated time (at
).
Definition at line 153 of file frame-scheduler.hpp.
|
inlinenoexcept |
Returns the fixed-rate update callback.
Definition at line 183 of file frame-scheduler.hpp.
|
inlinenoexcept |
Returns the fixed-rate update interval (dt
).
Definition at line 177 of file frame-scheduler.hpp.
|
inlinenoexcept |
Returns the elapsed fixed-rate update time (t
).
Definition at line 147 of file frame-scheduler.hpp.
|
inlinenoexcept |
Returns the duration of the previous frame.
Definition at line 159 of file frame-scheduler.hpp.
|
inlinenoexcept |
Returns the maximum frame duration.
Definition at line 171 of file frame-scheduler.hpp.
|
inlinenoexcept |
Returns the minimum frame duration.
Definition at line 165 of file frame-scheduler.hpp.
|
inlinenoexcept |
Returns the variable-rate update callback.
Definition at line 189 of file frame-scheduler.hpp.
|
noexcept |
Resets the accumulated time (at
) and frame timer, but not the elapsed fixed-rate update time.
Definition at line 72 of file frame-scheduler.cpp.
|
noexcept |
Resets the elapsed fixed-rate update time (t
), accumulated time (at
), and frame timer.
Definition at line 79 of file frame-scheduler.cpp.
|
inlinenoexcept |
Sets the fixed-rate update callback.
callback | Fixed-rate update callback. |
Definition at line 124 of file frame-scheduler.hpp.
|
inlinenoexcept |
Sets the fixed-rate update callback.
callback | Fixed-rate update callback. |
Definition at line 120 of file frame-scheduler.hpp.
|
inlinenoexcept |
Sets the interval (dt
) at which fixed-rate updates are scheduled.
interval | Fixed-rate update interval. |
Definition at line 89 of file frame-scheduler.hpp.
|
inlinenoexcept |
Sets the maximum accumulated frame duration.
Prevents a "spiral of death", in which updates are scheduled too many times per frame while trying to catch up to the target update rate.
duration | Maximum accumulated frame duration. |
Definition at line 109 of file frame-scheduler.hpp.
|
inlinenoexcept |
Sets the minimum frame duration.
If a frame is quicker than the minimum frame duration, the CPU will be idled until the minimum frame duration is met.
duration | Minimum frame duration. |
Definition at line 99 of file frame-scheduler.hpp.
|
inlinenoexcept |
Sets the variable-rate update callback.
callback | Variable-rate update callback. |
Definition at line 140 of file frame-scheduler.hpp.
|
inlinenoexcept |
Sets the variable-rate update callback.
callback | Variable-rate update callback. |
Definition at line 136 of file frame-scheduler.hpp.
void frame_scheduler::tick | ( | ) |
Performs any scheduled fixed-rate updates followed by a single variable-rate update.
tick()
. Definition at line 29 of file frame-scheduler.cpp.