1 #ifndef _framerate__hpp__included__
2 #define _framerate__hpp__included__
5 #include "library/threads.hpp"
6 #include "library/command.hpp"
8 #define FRAMERATE_HISTORY_FRAMES 10
11 * Framerate regulator.
13 class framerate_regulator
16 framerate_regulator(command::group
& _cmd
);
18 * Set the target speed multiplier.
20 * Parameter multiplier: The multiplier target. May be INFINITE.
22 void set_speed_multiplier(double multiplier
) throw();
25 * Increase the speed to next step.
27 void increase_speed() throw();
30 * Decrease the speed to next step.
32 void decrease_speed() throw();
35 * Get the target speed multiplier.
37 * Returns: The multiplier. May be INFINITE.
39 double get_speed_multiplier() throw();
42 * Sets the nominal frame rate. Framerate limiting tries to maintain the nominal framerate when there is no other
43 * explict framerate to maintain.
45 void set_nominal_framerate(double fps
) throw();
48 * Returns the current realized framerate multiplier.
50 * returns: The framerate multiplier the system is currently archiving.
52 double get_realized_multiplier() throw();
57 * Parameter usec: Current time in microseconds.
59 void freeze_time(uint64_t usec
);
64 * Parameter usec: Current time in microseconds.
66 void unfreeze_time(uint64_t usec
);
69 * Acknowledge frame start for timing purposes. If time is frozen, it is automatically unfrozen.
71 * parameter usec: Current time (relative to some unknown epoch) in microseconds.
73 void ack_frame_tick(uint64_t usec
) throw();
76 * Computes the number of microseconds to wait for next frame.
78 * parameter usec: Current time (relative to some unknown epoch) in microseconds.
79 * returns: Number of more microseconds to wait.
81 uint64_t to_wait_frame(uint64_t usec
) throw();
84 * Return microsecond-resolution time since unix epoch.
86 static uint64_t get_utime();
89 * Wait specified number of microseconds.
91 void wait_usec(uint64_t usec
);
97 void set_speed_cmd(const std::string
& args
);
98 uint64_t get_time(uint64_t curtime
, bool update
);
99 double get_realized_fps();
100 void add_frame(uint64_t linear_time
);
101 std::pair
<bool, double> read_fps();
102 //Step should be ODD.
103 void set_speedstep(unsigned step
);
104 //Step can be EVEN if between steps.
105 unsigned get_speedstep();
106 uint64_t last_time_update
;
107 uint64_t time_at_last_update
;
109 uint64_t frame_number
;
110 uint64_t frame_start_times
[FRAMERATE_HISTORY_FRAMES
];
112 double nominal_framerate
;
113 double multiplier_framerate
;
114 bool framerate_realtime_locked
;
115 threads::lock framerate_lock
;
117 command::_fnptr
<> turbo_p
;
118 command::_fnptr
<> turbo_r
;
119 command::_fnptr
<> turbo_t
;
120 command::_fnptr
<const std::string
&> setspeed_t
;
121 command::_fnptr
<> spd_inc
;
122 command::_fnptr
<> spd_dec
;