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 * Get the target speed multiplier.
27 * Returns: The multiplier. May be INFINITE.
29 double get_speed_multiplier() throw();
32 * Sets the nominal frame rate. Framerate limiting tries to maintain the nominal framerate when there is no other
33 * explict framerate to maintain.
35 void set_nominal_framerate(double fps
) throw();
38 * Returns the current realized framerate multiplier.
40 * returns: The framerate multiplier the system is currently archiving.
42 double get_realized_multiplier() throw();
47 * Parameter usec: Current time in microseconds.
49 void freeze_time(uint64_t usec
);
54 * Parameter usec: Current time in microseconds.
56 void unfreeze_time(uint64_t usec
);
59 * Acknowledge frame start for timing purposes. If time is frozen, it is automatically unfrozen.
61 * parameter usec: Current time (relative to some unknown epoch) in microseconds.
63 void ack_frame_tick(uint64_t usec
) throw();
66 * Computes the number of microseconds to wait for next frame.
68 * parameter usec: Current time (relative to some unknown epoch) in microseconds.
69 * returns: Number of more microseconds to wait.
71 uint64_t to_wait_frame(uint64_t usec
) throw();
74 * Return microsecond-resolution time since unix epoch.
76 static uint64_t get_utime();
79 * Wait specified number of microseconds.
81 void wait_usec(uint64_t usec
);
87 void set_speed_cmd(const std::string
& args
);
88 uint64_t get_time(uint64_t curtime
, bool update
);
89 double get_realized_fps();
90 void add_frame(uint64_t linear_time
);
91 std::pair
<bool, double> read_fps();
92 uint64_t last_time_update
;
93 uint64_t time_at_last_update
;
95 uint64_t frame_number
;
96 uint64_t frame_start_times
[FRAMERATE_HISTORY_FRAMES
];
98 double nominal_framerate
;
99 double multiplier_framerate
;
100 threads::lock framerate_lock
;
102 command::_fnptr
<> turbo_p
;
103 command::_fnptr
<> turbo_r
;
104 command::_fnptr
<> turbo_t
;
105 command::_fnptr
<const std::string
&> setspeed_t
;