openMSX
RealTime.hh
Go to the documentation of this file.
1#ifndef MSXREALTIME_HH
2#define MSXREALTIME_HH
3
4#include "EmuTime.hh"
5#include "EventListener.hh"
6#include "Observer.hh"
7#include "Schedulable.hh"
8
9#include <cstdint>
10
11namespace openmsx {
12
13class MSXMotherBoard;
14class GlobalSettings;
15class EventDistributor;
16class EventDelay;
17class BooleanSetting;
18class SpeedManager;
19class ThrottleManager;
20class Setting;
21
22class RealTime final : private Schedulable, private EventListener
23 , private Observer<Setting>
24 , private Observer<SpeedManager>
25 , private Observer<ThrottleManager>
26{
27public:
28 explicit RealTime(
29 MSXMotherBoard& motherBoard, GlobalSettings& globalSettings,
30 EventDelay& eventDelay);
31 ~RealTime();
32
35 [[nodiscard]] double getRealDuration(EmuTime::param time1, EmuTime::param time2) const;
36
39 [[nodiscard]] EmuDuration getEmuDuration(double realDur) const;
40
46 [[nodiscard]] bool timeLeft(uint64_t us, EmuTime::param time) const;
47
48 void resync();
49
50 void enable();
51 void disable();
52
53private:
59 void sync(EmuTime::param time, bool allowSleep);
60
61 // Schedulable
62 void executeUntil(EmuTime::param time) override;
63
64 // EventListener
65 int signalEvent(const Event& event) override;
66
67 // Observer<Setting>
68 void update(const Setting& setting) noexcept override;
69 // Observer<SpeedManager>
70 void update(const SpeedManager& speedManager) noexcept override;
71 // Observer<ThrottleManager>
72 void update(const ThrottleManager& throttleManager) noexcept override;
73
74 void internalSync(EmuTime::param time, bool allowSleep);
75
76 MSXMotherBoard& motherBoard;
77 EventDistributor& eventDistributor;
78 EventDelay& eventDelay;
79 SpeedManager& speedManager;
80 ThrottleManager& throttleManager;
81 BooleanSetting& pauseSetting;
82 BooleanSetting& powerSetting;
83
84 uint64_t idealRealTime;
85 EmuTime emuTime = EmuTime::zero();
86 double sleepAdjust;
87 bool enabled = true;
88};
89
90} // namespace openmsx
91
92#endif
BaseSetting * setting
This class is responsible for translating host events into MSX events.
Definition EventDelay.hh:27
This class contains settings that are used by several other class (including some singletons).
Generic Gang-of-Four Observer class, templatized edition.
Definition Observer.hh:10
bool timeLeft(uint64_t us, EmuTime::param time) const
Check that there is enough real time left before we reach as certain point in emulated time.
Definition RealTime.cc:67
double getRealDuration(EmuTime::param time1, EmuTime::param time2) const
Convert EmuTime to RealTime.
Definition RealTime.cc:57
EmuDuration getEmuDuration(double realDur) const
Convert RealTime to EmuTime.
Definition RealTime.cc:62
Every class that wants to get scheduled at some point must inherit from this class.
Manages the desired ratio between EmuTime and real time.
Manages the throttle state of openMSX.
This file implemented 3 utility functions:
Definition Autofire.cc:11
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, Rs232NetEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
Definition Event.hh:446