openMSX
RealTime.hh
Go to the documentation of this file.
1 #ifndef MSXREALTIME_HH
2 #define MSXREALTIME_HH
3 
4 #include "Schedulable.hh"
5 #include "EventListener.hh"
6 #include "Observer.hh"
7 #include "EmuTime.hh"
8 #include <cstdint>
9 
10 namespace openmsx {
11 
12 class MSXMotherBoard;
13 class GlobalSettings;
14 class EventDistributor;
15 class EventDelay;
16 class IntegerSetting;
17 class BooleanSetting;
18 class ThrottleManager;
19 class Setting;
20 
21 class RealTime : private Schedulable, private EventListener,
22  private Observer<Setting>, private Observer<ThrottleManager>
23 {
24 public:
25  explicit RealTime(
26  MSXMotherBoard& motherBoard, GlobalSettings& globalSettings,
27  EventDelay& eventDelay);
28  ~RealTime();
29 
32  double getRealDuration(EmuTime::param time1, EmuTime::param time2);
33 
36  EmuDuration getEmuDuration(double realDur);
37 
43  bool timeLeft(uint64_t us, EmuTime::param time);
44 
45  void resync();
46 
47  void enable();
48  void disable();
49 
50 private:
56  void sync(EmuTime::param time, bool allowSleep);
57 
58  // Schedulable
59  virtual void executeUntil(EmuTime::param time, int userData);
60 
61  // EventListener
62  virtual int signalEvent(const std::shared_ptr<const Event>& event);
63 
64  // Observer<Setting>
65  void update(const Setting& setting);
66  // Observer<ThrottleManager>
67  void update(const ThrottleManager& throttleManager);
68 
69  void internalSync(EmuTime::param time, bool allowSleep);
70 
71  MSXMotherBoard& motherBoard;
72  EventDistributor& eventDistributor;
73  EventDelay& eventDelay;
74  ThrottleManager& throttleManager;
75  IntegerSetting& speedSetting;
76  BooleanSetting& pauseSetting;
77  BooleanSetting& powerSetting;
78 
79  uint64_t idealRealTime;
80  EmuTime emuTime;
81  double sleepAdjust;
82  bool enabled;
83 };
84 
85 } // namespace openmsx
86 
87 #endif