Unravel Engine C++ Reference
Loading...
Searching...
No Matches
unravel::simulation Struct Reference

Class responsible for timers. More...

#include <simulation.h>

Public Types

using clock_t = std::chrono::steady_clock
 
using timepoint_t = clock_t::time_point
 
using duration_t = clock_t::duration
 
using delta_t = std::chrono::duration<float>
 

Public Member Functions

 simulation ()
 
void run_one_frame (bool is_active)
 Perform on frame computations with specified fps.
 
void reset_delta_clock ()
 
auto get_frame () const -> uint64_t
 
void set_min_fps (uint32_t fps)
 Set minimum frames per second. If fps goes lower than this, time will appear to slow.
 
void set_max_fps (uint32_t fps)
 Set maximum frames per second. The engine will sleep if fps is higher than this.
 
void set_max_inactive_fps (uint32_t fps)
 Set maximum frames per second when the application does not have input focus.
 
void set_time_smoothing_step (uint32_t step)
 Set how many frames to average for timestep smoothing.
 
auto get_time_since_launch () const -> duration_t
 Returns duration since launch.
 
auto get_fps () const -> float
 Returns frames per second.
 
auto get_delta_time () const -> delta_t
 Returns the delta time in seconds.
 
void set_time_scale (float time_scale=1.0f)
 
auto get_time_scale () const -> float
 
auto get_max_fps () const -> uint32_t
 Returns the configured software FPS cap (0 means uncapped).
 
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 can distinguish actual CPU work from time spent in the software frame limiter.
 

Protected Attributes

float time_scale_ {1.0f}
 
uint32_t min_fps_ = 0
 minimum/maximum frames per second
 
uint32_t max_fps_ = 0
 
uint32_t max_inactive_fps_ = 20
 
std::vector< duration_tprevious_timesteps_
 previous time steps for smoothing in seconds
 
duration_t timestep_ = duration_t::zero()
 next frame time step in seconds
 
duration_t last_sleep_duration_ = duration_t::zero()
 time spent sleeping inside the last run_one_frame call
 
uint64_t frame_ = 0
 current frame
 
uint32_t smoothing_step_ = 11
 how many frames to average for the smoothed time step
 
timepoint_t last_frame_timepoint_ = clock_t::now()
 frame update timer
 
timepoint_t launch_timepoint_ = clock_t::now()
 time point when we launched
 

Detailed Description

Class responsible for timers.

Definition at line 19 of file simulation.h.

Member Typedef Documentation

◆ clock_t

using unravel::simulation::clock_t = std::chrono::steady_clock

Definition at line 21 of file simulation.h.

◆ delta_t

using unravel::simulation::delta_t = std::chrono::duration<float>

Definition at line 24 of file simulation.h.

◆ duration_t

using unravel::simulation::duration_t = clock_t::duration

Definition at line 23 of file simulation.h.

◆ timepoint_t

using unravel::simulation::timepoint_t = clock_t::time_point

Definition at line 22 of file simulation.h.

Constructor & Destructor Documentation

◆ simulation()

unravel::simulation::simulation ( )

Definition at line 9 of file simulation.cpp.

Member Function Documentation

◆ get_delta_time()

auto unravel::simulation::get_delta_time ( ) const -> delta_t

Returns the delta time in seconds.

Definition at line 160 of file simulation.cpp.

◆ get_fps()

auto unravel::simulation::get_fps ( ) const -> float

Returns frames per second.

Definition at line 154 of file simulation.cpp.

◆ get_frame()

auto unravel::simulation::get_frame ( ) const -> uint64_t

Definition at line 124 of file simulation.cpp.

◆ get_last_sleep_duration()

auto unravel::simulation::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 can distinguish actual CPU work from time spent in the software frame limiter.

Definition at line 181 of file simulation.cpp.

◆ get_max_fps()

auto unravel::simulation::get_max_fps ( ) const -> uint32_t

Returns the configured software FPS cap (0 means uncapped).

Definition at line 176 of file simulation.cpp.

◆ get_time_scale()

auto unravel::simulation::get_time_scale ( ) const -> float

Definition at line 171 of file simulation.cpp.

◆ get_time_since_launch()

auto unravel::simulation::get_time_since_launch ( ) const -> duration_t

Returns duration since launch.

Definition at line 149 of file simulation.cpp.

◆ reset_delta_clock()

void unravel::simulation::reset_delta_clock ( )

Drop smoothed history and restart the frame clock from now. Call when entering play simulation so a preceding hitch (domain reload, scene load) does not inflate subsequent deltas.

Definition at line 116 of file simulation.cpp.

◆ run_one_frame()

void unravel::simulation::run_one_frame ( bool is_active)

Perform on frame computations with specified fps.

Definition at line 17 of file simulation.cpp.

◆ set_max_fps()

void unravel::simulation::set_max_fps ( uint32_t fps)

Set maximum frames per second. The engine will sleep if fps is higher than this.

Definition at line 134 of file simulation.cpp.

◆ set_max_inactive_fps()

void unravel::simulation::set_max_inactive_fps ( uint32_t fps)

Set maximum frames per second when the application does not have input focus.

Definition at line 139 of file simulation.cpp.

◆ set_min_fps()

void unravel::simulation::set_min_fps ( uint32_t fps)

Set minimum frames per second. If fps goes lower than this, time will appear to slow.

Definition at line 129 of file simulation.cpp.

◆ set_time_scale()

void unravel::simulation::set_time_scale ( float time_scale = 1.0f)

Definition at line 166 of file simulation.cpp.

◆ set_time_smoothing_step()

void unravel::simulation::set_time_smoothing_step ( uint32_t step)

Set how many frames to average for timestep smoothing.

Definition at line 144 of file simulation.cpp.

Member Data Documentation

◆ frame_

uint64_t unravel::simulation::frame_ = 0
protected

current frame

Definition at line 148 of file simulation.h.

◆ last_frame_timepoint_

timepoint_t unravel::simulation::last_frame_timepoint_ = clock_t::now()
protected

frame update timer

Definition at line 152 of file simulation.h.

◆ last_sleep_duration_

duration_t unravel::simulation::last_sleep_duration_ = duration_t::zero()
protected

time spent sleeping inside the last run_one_frame call

Definition at line 146 of file simulation.h.

◆ launch_timepoint_

timepoint_t unravel::simulation::launch_timepoint_ = clock_t::now()
protected

time point when we launched

Definition at line 154 of file simulation.h.

◆ max_fps_

uint32_t unravel::simulation::max_fps_ = 0
protected

Definition at line 138 of file simulation.h.

◆ max_inactive_fps_

uint32_t unravel::simulation::max_inactive_fps_ = 20
protected

Definition at line 140 of file simulation.h.

◆ min_fps_

uint32_t unravel::simulation::min_fps_ = 0
protected

minimum/maximum frames per second

Definition at line 136 of file simulation.h.

◆ previous_timesteps_

std::vector<duration_t> unravel::simulation::previous_timesteps_
protected

previous time steps for smoothing in seconds

Definition at line 142 of file simulation.h.

◆ smoothing_step_

uint32_t unravel::simulation::smoothing_step_ = 11
protected

how many frames to average for the smoothed time step

Definition at line 150 of file simulation.h.

◆ time_scale_

float unravel::simulation::time_scale_ {1.0f}
protected

Definition at line 134 of file simulation.h.

◆ timestep_

duration_t unravel::simulation::timestep_ = duration_t::zero()
protected

next frame time step in seconds

Definition at line 144 of file simulation.h.


The documentation for this struct was generated from the following files: