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