24 , motherBoard(motherBoard_)
25 , eventDistributor(motherBoard.getReactor().getEventDistributor())
26 , eventDelay(eventDelay_)
27 , speedManager (globalSettings.getSpeedManager())
28 , throttleManager(globalSettings.getThrottleManager())
29 , pauseSetting (globalSettings.getPauseSetting())
30 , powerSetting (globalSettings.getPowerSetting())
32 speedManager.
attach(*
this);
33 throttleManager.
attach(*
this);
34 pauseSetting.
attach(*
this);
35 powerSetting.
attach(*
this);
48 powerSetting.
detach(*
this);
49 pauseSetting.
detach(*
this);
50 throttleManager.
detach(*
this);
51 speedManager.
detach(*
this);
56 return (time2 - time1).toDouble() / speedManager.
getSpeed();
66 auto realDuration =
static_cast<uint64_t
>(
69 return (currentRealTime + us) <
73void RealTime::sync(EmuTime::param time,
bool allowSleep)
78 internalSync(time, allowSleep);
84void RealTime::internalSync(EmuTime::param time,
bool allowSleep)
87 auto realDuration =
static_cast<uint64_t
>(
89 idealRealTime += realDuration;
91 auto sleep = narrow_cast<int64_t>(idealRealTime - currentRealTime);
94 sleep += narrow_cast<int64_t>(sleepAdjust);
99 delta =
sleep - slept;
101 const double ALPHA = 0.2;
102 sleepAdjust = sleepAdjust * (1 - ALPHA) + narrow_cast<double>(delta) * ALPHA;
105 idealRealTime = currentRealTime -
MAX_LAG / 2;
109 eventDelay.
sync(time);
115void RealTime::executeUntil(EmuTime::param time)
117 internalSync(time,
true);
121int RealTime::signalEvent(
const Event& event)
123 if (!motherBoard.
isActive() || !enabled) {
129 [&](
const FinishFrameEvent& ffe) {
130 if (!ffe.needRender()) {
135 [&](
const FrameDrawnEvent&) {
139 [&](
const EventBase ) {
146void RealTime::update(
const Setting& )
noexcept
151void RealTime::update(
const SpeedManager& )
noexcept
156void RealTime::update(
const ThrottleManager& )
noexcept
163 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=OTHER)
Registers a given object to receive certain events.
This class contains settings that are used by several other class (including some singletons).
double getRealDuration(EmuTime::param time1, EmuTime::param time2)
Convert EmuTime to RealTime.
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.
RealTime(MSXMotherBoard &motherBoard, GlobalSettings &globalSettings, EventDelay &eventDelay)
EmuDuration getEmuDuration(double realDur)
Convert RealTime to EmuTime.
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:
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, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
const double SYNC_INTERVAL
const uint64_t ALLOWED_LAG