26 , motherBoard(motherBoard_)
27 , eventDistributor(motherBoard.getReactor().getEventDistributor())
28 , eventDelay(eventDelay_)
29 , speedManager (globalSettings.getSpeedManager())
30 , throttleManager(globalSettings.getThrottleManager())
31 , pauseSetting (globalSettings.getPauseSetting())
32 , powerSetting (globalSettings.getPowerSetting())
34 speedManager.
attach(*
this);
35 throttleManager.
attach(*
this);
36 pauseSetting.
attach(*
this);
37 powerSetting.
attach(*
this);
51 powerSetting.
detach(*
this);
52 pauseSetting.
detach(*
this);
53 throttleManager.
detach(*
this);
54 speedManager.
detach(*
this);
59 return (time2 - time1).toDouble() / speedManager.
getSpeed();
69 auto realDuration =
static_cast<uint64_t
>(
72 return (currentRealTime + us) <
76void RealTime::sync(EmuTime::param time,
bool allowSleep)
81 internalSync(time, allowSleep);
87void RealTime::internalSync(EmuTime::param time,
bool allowSleep)
90 auto realDuration =
static_cast<uint64_t
>(
92 idealRealTime += realDuration;
94 auto sleep = narrow_cast<int64_t>(idealRealTime - currentRealTime);
97 sleep += narrow_cast<int64_t>(sleepAdjust);
102 delta =
sleep - slept;
104 const double ALPHA = 0.2;
105 sleepAdjust = sleepAdjust * (1 - ALPHA) + narrow_cast<double>(delta) * ALPHA;
108 idealRealTime = currentRealTime -
MAX_LAG / 2;
112 eventDelay.
sync(time);
118void RealTime::executeUntil(EmuTime::param time)
120 internalSync(time,
true);
124bool RealTime::signalEvent(
const Event& event)
126 if (!motherBoard.
isActive() || !enabled) {
132 [&](
const FinishFrameEvent& ffe) {
133 if (!ffe.needRender()) {
138 [&](
const FrameDrawnEvent&) {
142 [&](
const EventBase ) {
149void RealTime::update(
const Setting& )
noexcept
154void RealTime::update(
const SpeedManager& )
noexcept
159void RealTime::update(
const ThrottleManager& )
noexcept
166 if (!enabled)
return;
This class is responsible for translating host events into MSX events.
void sync(EmuTime::param curEmu)
void unregisterEventListener(EventType type, EventListener &listener)
Unregisters a previously registered event listener.
void registerEventListener(EventType type, EventListener &listener, Priority priority=Priority::OTHER)
Registers a given object to receive certain events.
This class contains settings that are used by several other class (including some singletons).
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.
double getRealDuration(EmuTime::param time1, EmuTime::param time2) const
Convert EmuTime to RealTime.
EmuDuration getEmuDuration(double realDur) const
Convert RealTime to EmuTime.
RealTime(MSXMotherBoard &motherBoard, GlobalSettings &globalSettings, EventDelay &eventDelay)
Every class that wants to get scheduled at some point must inherit from this class.
void setSyncPoint(EmuTime::param timestamp)
EmuTime::param getCurrentTime() const
Convenience method: This is the same as getScheduler().getCurrentTime().
double getSpeed() const
Return the desired ratio between EmuTime and real time.
void detach(Observer< T > &observer)
void attach(Observer< T > &observer)
bool isThrottled() const
Ask if throttling is enabled.
uint64_t getTime()
Get current (real) time in us.
void sleep(uint64_t us)
Sleep for the specified amount of time (in us).
This file implemented 3 utility functions:
const double SYNC_INTERVAL
const uint64_t ALLOWED_LAG
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