Instancefy framerate stuff
[lsnes.git] / include / core / framerate.hpp
blob82be8f5ee1939df3d7b3230dc3609059e3731adb
1 #ifndef _framerate__hpp__included__
2 #define _framerate__hpp__included__
4 #include <cstdint>
5 #include "library/threads.hpp"
7 #define FRAMERATE_HISTORY_FRAMES 10
9 /**
10 * Framerate regulator.
12 class framerate_regulator
14 public:
15 framerate_regulator();
16 /**
17 * Set the target speed multiplier.
19 * Parameter multiplier: The multiplier target. May be INFINITE.
21 void set_speed_multiplier(double multiplier) throw();
23 /**
24 * Get the target speed multiplier.
26 * Returns: The multiplier. May be INFINITE.
28 double get_speed_multiplier() throw();
30 /**
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();
36 /**
37 * Returns the current realized framerate multiplier.
39 * returns: The framerate multiplier the system is currently archiving.
41 double get_realized_multiplier() throw();
43 /**
44 * Freeze time.
46 * Parameter usec: Current time in microseconds.
48 void freeze_time(uint64_t usec);
50 /**
51 * Unfreeze time.
53 * Parameter usec: Current time in microseconds.
55 void unfreeze_time(uint64_t usec);
57 /**
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();
64 /**
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();
72 /**
73 * Return microsecond-resolution time since unix epoch.
75 static uint64_t get_utime();
77 /**
78 * Wait specified number of microseconds.
80 void wait_usec(uint64_t usec);
81 /**
82 * Turbo flag.
84 bool turboed;
85 private:
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;
92 bool time_frozen;
93 uint64_t frame_number;
94 uint64_t frame_start_times[FRAMERATE_HISTORY_FRAMES];
95 //Framerate.
96 double nominal_framerate;
97 double multiplier_framerate;
98 threads::lock framerate_lock;
102 #endif