Unravel Engine C++ Reference
Loading...
Searching...
No Matches
simulation.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <cstdint>
5#include <vector>
6
7namespace unravel
8{
9
10//-----------------------------------------------------------------------------
11// Main Class Declarations
12//-----------------------------------------------------------------------------
13//-----------------------------------------------------------------------------
14// Name : simulation (Class)
18//-----------------------------------------------------------------------------
20{
21 using clock_t = std::chrono::steady_clock;
22 using timepoint_t = clock_t::time_point;
23 using duration_t = clock_t::duration;
24 using delta_t = std::chrono::duration<float>;
25 simulation();
26
27 //-----------------------------------------------------------------------------
28 // Name : run_one_frame ()
32 //-----------------------------------------------------------------------------
33 void run_one_frame(bool is_active);
34
35 //-----------------------------------------------------------------------------
36 // Name : get_frame ()
42 //-----------------------------------------------------------------------------
43 auto get_frame() const -> uint64_t;
44
45 //-----------------------------------------------------------------------------
46 // Name : set_min_fps ()
53 //-----------------------------------------------------------------------------
54 void set_min_fps(uint32_t fps);
55
56 //-----------------------------------------------------------------------------
57 // Name : set_max_fps ()
62 //-----------------------------------------------------------------------------
63 void set_max_fps(uint32_t fps);
64
65 //-----------------------------------------------------------------------------
66 // Name : set_max_inactive_fps ()
71 //-----------------------------------------------------------------------------
72 void set_max_inactive_fps(uint32_t fps);
73
74 //-----------------------------------------------------------------------------
75 // Name : set_time_smoothing_step ()
79 //-----------------------------------------------------------------------------
80 void set_time_smoothing_step(uint32_t step);
81
82 //-----------------------------------------------------------------------------
83 // Name : get_time_since_launch ()
87 //-----------------------------------------------------------------------------
88 auto get_time_since_launch() const -> duration_t;
89
90 //-----------------------------------------------------------------------------
91 // Name : get_fps ()
95 //-----------------------------------------------------------------------------
96 auto get_fps() const -> float;
97
98 //-----------------------------------------------------------------------------
99 // Name : get_delta_time ()
103 //-----------------------------------------------------------------------------
104 auto get_delta_time() const -> delta_t;
105
106
107 void set_time_scale(float time_scale = 1.0f);
108 auto get_time_scale() const -> float;
109
110protected:
111 float time_scale_{1.0f};
113 uint32_t min_fps_ = 0;
115 uint32_t max_fps_ = 0;
117 uint32_t max_inactive_fps_ = 20;
119 std::vector<duration_t> previous_timesteps_;
121 duration_t timestep_ = duration_t::zero();
123 uint64_t frame_ = 0;
125 uint32_t smoothing_step_ = 11;
130};
131} // namespace unravel
Class responsible for timers.
Definition simulation.h:20
std::vector< duration_t > previous_timesteps_
previous time steps for smoothing in seconds
Definition simulation.h:119
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
Definition simulation.h:127
duration_t timestep_
next frame time step in seconds
Definition simulation.h:121
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
Definition simulation.h:125
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
Definition simulation.h:24
std::chrono::steady_clock clock_t
Definition simulation.h:21
uint32_t max_inactive_fps_
Definition simulation.h:117
uint64_t frame_
current frame
Definition simulation.h:123
clock_t::time_point timepoint_t
Definition simulation.h:22
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
Definition simulation.h:129
clock_t::duration duration_t
Definition simulation.h:23
uint32_t min_fps_
minimum/maximum frames per second
Definition simulation.h:113