Lua: Fix type confusion between signed and unsigned
[lsnes.git] / include / core / framerate.hpp
blob8dcb775d41e4ff3cb72e337e7aeafcfc143f31be
1 #ifndef _framerate__hpp__included__
2 #define _framerate__hpp__included__
4 #include <cstdint>
5 #include "library/threads.hpp"
6 #include "library/command.hpp"
8 #define FRAMERATE_HISTORY_FRAMES 10
10 /**
11 * Framerate regulator.
13 class framerate_regulator
15 public:
16 framerate_regulator(command::group& _cmd);
17 /**
18 * Set the target speed multiplier.
20 * Parameter multiplier: The multiplier target. May be INFINITE.
22 void set_speed_multiplier(double multiplier) throw();
24 /**
25 * Increase the speed to next step.
27 void increase_speed() throw();
29 /**
30 * Decrease the speed to next step.
32 void decrease_speed() throw();
34 /**
35 * Get the target speed multiplier.
37 * Returns: The multiplier. May be INFINITE.
39 double get_speed_multiplier() throw();
41 /**
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();
47 /**
48 * Returns the current realized framerate multiplier.
50 * returns: The framerate multiplier the system is currently archiving.
52 double get_realized_multiplier() throw();
54 /**
55 * Freeze time.
57 * Parameter usec: Current time in microseconds.
59 void freeze_time(uint64_t usec);
61 /**
62 * Unfreeze time.
64 * Parameter usec: Current time in microseconds.
66 void unfreeze_time(uint64_t usec);
68 /**
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();
75 /**
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();
83 /**
84 * Return microsecond-resolution time since unix epoch.
86 static uint64_t get_utime();
88 /**
89 * Wait specified number of microseconds.
91 void wait_usec(uint64_t usec);
92 /**
93 * Turbo flag.
95 bool turboed;
96 private:
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;
108 bool time_frozen;
109 uint64_t frame_number;
110 uint64_t frame_start_times[FRAMERATE_HISTORY_FRAMES];
111 //Framerate.
112 double nominal_framerate;
113 double multiplier_framerate;
114 bool framerate_realtime_locked;
115 threads::lock framerate_lock;
116 command::group& cmd;
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;
125 #endif