| 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 |
|
| 11 |
namespace openmsx { |
| 12 |
|
| 13 |
class MSXMotherBoard; |
| 14 |
class GlobalSettings; |
| 15 |
class EventDistributor; |
| 16 |
class EventDelay; |
| 17 |
class BooleanSetting; |
| 18 |
class SpeedManager; |
| 19 |
class ThrottleManager; |
| 20 |
class Setting; |
| 21 |
|
| 22 |
class RealTime final : private Schedulable, private EventListener |
| 23 |
, private Observer<Setting> |
| 24 |
, private Observer<SpeedManager> |
| 25 |
, private Observer<ThrottleManager> |
| 26 |
{ |
| 27 |
public: |
| 28 |
explicit RealTime( |
| 29 |
MSXMotherBoard& motherBoard, GlobalSettings& globalSettings, |
| 30 |
EventDelay& eventDelay); |
| 31 |
~RealTime(); |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
[[nodiscard]] double getRealDuration(EmuTime time1, EmuTime time2) const; |
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
[[nodiscard]] EmuDuration getEmuDuration(double realDur) const; |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
[[nodiscard]] bool timeLeft(uint64_t us, EmuTime time) const; |
| 47 |
|
| 48 |
void resync(); |
| 49 |
|
| 50 |
void enable(); |
| 51 |
void disable(); |
| 52 |
|
| 53 |
private: |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
void sync(EmuTime time, bool allowSleep); |
| 60 |
|
| 61 |
|
| 62 |
void executeUntil(EmuTime time) override; |
| 63 |
|
| 64 |
|
| 65 |
bool signalEvent(const Event& event) override; |
| 66 |
|
| 67 |
|
| 68 |
void update(const Setting& setting) noexcept override; |
| 69 |
|
| 70 |
void update(const SpeedManager& speedManager) noexcept override; |
| 71 |
|
| 72 |
void update(const ThrottleManager& throttleManager) noexcept override; |
| 73 |
|
| 74 |
void internalSync(EmuTime 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 |
} |
| 91 |
|
| 92 |
#endif |