21 if(!is_active && max_fps > 0)
26 const auto wait_begin = clock_t::now();
38 std::chrono::duration_cast<duration_t>(std::chrono::seconds(1)) / max_fps;
45 constexpr auto sleep_safety_margin = std::chrono::milliseconds(2);
48 const auto coarse_until = deadline - sleep_safety_margin;
50 if(clock_t::now() < coarse_until)
52 std::this_thread::sleep_until(coarse_until);
55 while(clock_t::now() < deadline)
57 std::this_thread::yield();
68 const auto wait_end = clock_t::now();
81 std::chrono::duration_cast<duration_t>(std::chrono::seconds(1)) /
min_fps_;
131 min_fps_ = std::max<uint32_t>(fps, 0);
136 max_fps_ = std::max<uint32_t>(fps, 0);
156 auto dt = std::chrono::duration_cast<std::chrono::duration<float, std::milli>>(
get_delta_time()).
count();
157 return (std::abs(dt) < std::numeric_limits<float>::epsilon()) ? 0 : 1000.0f / dt;
std::vector< duration_t > previous_timesteps_
previous time steps for smoothing in seconds
auto get_delta_time() const -> delta_t
Returns the delta time in seconds.
auto get_time_scale() const -> float
auto get_fps() const -> float
Returns frames per second.
void set_time_scale(float time_scale=1.0f)
void set_time_smoothing_step(uint32_t step)
Set how many frames to average for timestep smoothing.
timepoint_t last_frame_timepoint_
frame update timer
duration_t last_sleep_duration_
time spent sleeping inside the last run_one_frame call
duration_t timestep_
next frame time step in seconds
void set_max_inactive_fps(uint32_t fps)
Set maximum frames per second when the application does not have input focus.
uint32_t smoothing_step_
how many frames to average for the smoothed time step
void run_one_frame(bool is_active)
Perform on frame computations with specified fps.
auto get_frame() const -> uint64_t
auto get_time_since_launch() const -> duration_t
Returns duration since launch.
std::chrono::duration< float > delta_t
uint32_t max_inactive_fps_
auto get_last_sleep_duration() const -> duration_t
Returns how long run_one_frame spent sleeping during the last call. Useful for stats overlays so they...
uint64_t frame_
current frame
void set_max_fps(uint32_t fps)
Set maximum frames per second. The engine will sleep if fps is higher than this.
auto get_max_fps() const -> uint32_t
Returns the configured software FPS cap (0 means uncapped).
void set_min_fps(uint32_t fps)
Set minimum frames per second. If fps goes lower than this, time will appear to slow.
timepoint_t launch_timepoint_
time point when we launched
clock_t::duration duration_t
uint32_t min_fps_
minimum/maximum frames per second