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 final : private Schedulable, private EventListener
22  , private Observer<Setting>
23  , private Observer<ThrottleManager>
24 {
25 public:
26  explicit RealTime(
27  MSXMotherBoard& motherBoard, GlobalSettings& globalSettings,
28  EventDelay& eventDelay);
29  ~RealTime();
30 
33  double getRealDuration(EmuTime::param time1, EmuTime::param time2);
34 
37  EmuDuration getEmuDuration(double realDur);
38 
44  bool timeLeft(uint64_t us, EmuTime::param time);
45 
46  void resync();
47 
48  void enable();
49  void disable();
50 
51 private:
57  void sync(EmuTime::param time, bool allowSleep);
58 
59  // Schedulable
60  void executeUntil(EmuTime::param time) override;
61 
62  // EventListener
63  int signalEvent(const std::shared_ptr<const Event>& event) override;
64 
65  // Observer<Setting>
66  void update(const Setting& setting) override;
67  // Observer<ThrottleManager>
68  void update(const ThrottleManager& throttleManager) override;
69 
70  void internalSync(EmuTime::param time, bool allowSleep);
71 
72  MSXMotherBoard& motherBoard;
73  EventDistributor& eventDistributor;
74  EventDelay& eventDelay;
75  ThrottleManager& throttleManager;
76  IntegerSetting& speedSetting;
77  BooleanSetting& pauseSetting;
78  BooleanSetting& powerSetting;
79 
80  uint64_t idealRealTime;
81  EmuTime emuTime;
82  double sleepAdjust;
83  bool enabled;
84 };
85 
86 } // namespace openmsx
87 
88 #endif
This class is responsible for translating host events into MSX events.
Definition: EventDelay.hh:26
RealTime(MSXMotherBoard &motherBoard, GlobalSettings &globalSettings, EventDelay &eventDelay)
Definition: RealTime.cc:21
bool timeLeft(uint64_t us, EmuTime::param time)
Check that there is enough real time left before we reach as certain point in emulated time...
Definition: RealTime.cc:67
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:33
A Setting with an integer value.
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
double getRealDuration(EmuTime::param time1, EmuTime::param time2)
Convert EmuTime to RealTime.
Definition: RealTime.cc:57
EmuDuration getEmuDuration(double realDur)
Convert RealTime to EmuTime.
Definition: RealTime.cc:62
Manages the throttle state of openMSX.
Generic Gang-of-Four Observer class, templatized edition.
Definition: Observer.hh:9
This class contains settings that are used by several other class (including some singletons)...