20 #ifndef ANTKEEPER_UTILITY_FRAME_SCHEDULER_HPP
21 #define ANTKEEPER_UTILITY_FRAME_SCHEDULER_HPP
25 #include <type_traits>
38 std::chrono::high_resolution_clock::is_steady,
39 std::chrono::high_resolution_clock, std::chrono::steady_clock
82 void reset() noexcept;
91 m_fixed_update_interval = interval;
101 m_min_frame_duration = duration;
111 m_max_frame_duration = duration;
122 m_fixed_update_callback = callback;
126 m_fixed_update_callback = callback;
138 m_variable_update_callback = callback;
142 m_variable_update_callback = callback;
149 return m_fixed_update_time;
155 return m_accumulated_time;
161 return m_frame_duration;
167 return m_min_frame_duration;
173 return m_max_frame_duration;
179 return m_fixed_update_interval;
185 return m_fixed_update_callback;
191 return m_variable_update_callback;
205 duration_type m_fixed_update_interval{duration_type::zero()};
Schedules fixed- and variable-rate updates.
clock_type::time_point time_point_type
Time point type matches the clock's time point type.
void reset() noexcept
Resets the elapsed fixed-rate update time (t), accumulated time (at), and frame timer.
std::conditional< std::chrono::high_resolution_clock::is_steady, std::chrono::high_resolution_clock, std::chrono::steady_clock >::type clock_type
Clock type is std::chrono::high_resolution_clock if steady, std::chrono::steady_clock otherwise.
duration_type get_max_frame_duration() const noexcept
Returns the maximum frame duration.
duration_type get_accumulated_time() const noexcept
Returns the accumulated time (at).
void set_min_frame_duration(duration_type duration) noexcept
Sets the minimum frame duration.
void set_max_frame_duration(duration_type duration) noexcept
Sets the maximum accumulated frame duration.
duration_type get_min_frame_duration() const noexcept
Returns the minimum frame duration.
duration_type get_fixed_update_time() const noexcept
Returns the elapsed fixed-rate update time (t).
const variable_update_callback_type & get_variable_update_callback() const noexcept
Returns the variable-rate update callback.
std::function< void(duration_type, duration_type)> fixed_update_callback_type
Fixed-rate update callback function type.
void refresh() noexcept
Resets the accumulated time (at) and frame timer, but not the elapsed fixed-rate update time.
void set_fixed_update_interval(duration_type interval) noexcept
Sets the interval (dt) at which fixed-rate updates are scheduled.
frame_scheduler() noexcept
Constructs a frame scheduler and starts its frame timer.
void tick()
Performs any scheduled fixed-rate updates followed by a single variable-rate update.
const fixed_update_callback_type & get_fixed_update_callback() const noexcept
Returns the fixed-rate update callback.
void set_fixed_update_callback(fixed_update_callback_type &&callback) noexcept
Sets the fixed-rate update callback.
duration_type get_fixed_update_interval() const noexcept
Returns the fixed-rate update interval (dt).
void set_fixed_update_callback(const fixed_update_callback_type &callback) noexcept
Sets the fixed-rate update callback.
duration_type get_frame_duration() const noexcept
Returns the duration of the previous frame.
clock_type::duration duration_type
Duration type matches the clock's duration type.
void set_variable_update_callback(variable_update_callback_type &&callback) noexcept
Sets the variable-rate update callback.
std::function< void(duration_type, duration_type, duration_type)> variable_update_callback_type
Variable-rate callback function type.
void set_variable_update_callback(const variable_update_callback_type &callback) noexcept
Sets the variable-rate update callback.
constexpr vector< T, N > max(const vector< T, N > &x, const vector< T, N > &y)
Returns a vector containing the maximum elements of two vectors.