1 #ifndef _framerate__hpp__included__
2 #define _framerate__hpp__included__
5 #include "library/threads.hpp"
7 #define FRAMERATE_HISTORY_FRAMES 10
10 * Framerate regulator.
12 class framerate_regulator
15 framerate_regulator();
17 * Set the target speed multiplier.
19 * Parameter multiplier: The multiplier target. May be INFINITE.
21 void set_speed_multiplier(double multiplier
) throw();
24 * Get the target speed multiplier.
26 * Returns: The multiplier. May be INFINITE.
28 double get_speed_multiplier() throw();
31 * Sets the nominal frame rate. Framerate limiting tries to maintain the nominal framerate when there is no other
32 * explict framerate to maintain.
34 void set_nominal_framerate(double fps
) throw();
37 * Returns the current realized framerate multiplier.
39 * returns: The framerate multiplier the system is currently archiving.
41 double get_realized_multiplier() throw();
46 * Parameter usec: Current time in microseconds.
48 void freeze_time(uint64_t usec
);
53 * Parameter usec: Current time in microseconds.
55 void unfreeze_time(uint64_t usec
);
58 * Acknowledge frame start for timing purposes. If time is frozen, it is automatically unfrozen.
60 * parameter usec: Current time (relative to some unknown epoch) in microseconds.
62 void ack_frame_tick(uint64_t usec
) throw();
65 * Computes the number of microseconds to wait for next frame.
67 * parameter usec: Current time (relative to some unknown epoch) in microseconds.
68 * returns: Number of more microseconds to wait.
70 uint64_t to_wait_frame(uint64_t usec
) throw();
73 * Return microsecond-resolution time since unix epoch.
75 static uint64_t get_utime();
78 * Wait specified number of microseconds.
80 void wait_usec(uint64_t usec
);
86 uint64_t get_time(uint64_t curtime
, bool update
);
87 double get_realized_fps();
88 void add_frame(uint64_t linear_time
);
89 std::pair
<bool, double> read_fps();
90 uint64_t last_time_update
;
91 uint64_t time_at_last_update
;
93 uint64_t frame_number
;
94 uint64_t frame_start_times
[FRAMERATE_HISTORY_FRAMES
];
96 double nominal_framerate
;
97 double multiplier_framerate
;
98 threads::lock framerate_lock
;