8using namespace std::chrono_literals;
22 if(!is_active && max_fps > 0)
45 auto ms = std::chrono::duration_cast<std::chrono::milliseconds>(sleep_time);
47 if(sleep_time > std::chrono::microseconds(1000))
51 sleep_time /= ms.count();
54 std::this_thread::sleep_for(sleep_time);
110 min_fps_ = std::max<uint32_t>(fps, 0);
115 max_fps_ = std::max<uint32_t>(fps, 0);
135 auto dt = std::chrono::duration_cast<std::chrono::duration<float, std::milli>>(
get_delta_time()).
count();
136 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 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_
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.
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