RealTime.hh 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #ifndef MSXREALTIME_HH
  2. #define MSXREALTIME_HH
  3. #include "Schedulable.hh"
  4. #include "EventListener.hh"
  5. #include "Observer.hh"
  6. #include "EmuTime.hh"
  7. #include <cstdint>
  8. namespace openmsx {
  9. class MSXMotherBoard;
  10. class GlobalSettings;
  11. class EventDistributor;
  12. class EventDelay;
  13. class BooleanSetting;
  14. class SpeedManager;
  15. class ThrottleManager;
  16. class Setting;
  17. class RealTime final : private Schedulable, private EventListener
  18. , private Observer<Setting>
  19. , private Observer<SpeedManager>
  20. , private Observer<ThrottleManager>
  21. {
  22. public:
  23. explicit RealTime(
  24. MSXMotherBoard& motherBoard, GlobalSettings& globalSettings,
  25. EventDelay& eventDelay);
  26. ~RealTime();
  27. /** Convert EmuTime to RealTime.
  28. */
  29. double getRealDuration(EmuTime::param time1, EmuTime::param time2);
  30. /** Convert RealTime to EmuTime.
  31. */
  32. EmuDuration getEmuDuration(double realDur);
  33. /** Check that there is enough real time left before we reach as certain
  34. * point in emulated time.
  35. * @param us Real time duration is micro seconds.
  36. * @param time Point in emulated time.
  37. */
  38. bool timeLeft(uint64_t us, EmuTime::param time);
  39. void resync();
  40. void enable();
  41. void disable();
  42. private:
  43. /** Synchronize EmuTime with RealTime.
  44. * @param time The current emulation time.
  45. * @param allowSleep Is this method allowed to sleep, typically the
  46. * result of a previous call to timeLeft() is passed.
  47. */
  48. void sync(EmuTime::param time, bool allowSleep);
  49. // Schedulable
  50. void executeUntil(EmuTime::param time) override;
  51. // EventListener
  52. int signalEvent(const std::shared_ptr<const Event>& event) override;
  53. // Observer<Setting>
  54. void update(const Setting& setting) override;
  55. // Observer<SpeedManager>
  56. void update(const SpeedManager& speedManager) override;
  57. // Observer<ThrottleManager>
  58. void update(const ThrottleManager& throttleManager) override;
  59. void internalSync(EmuTime::param time, bool allowSleep);
  60. MSXMotherBoard& motherBoard;
  61. EventDistributor& eventDistributor;
  62. EventDelay& eventDelay;
  63. SpeedManager& speedManager;
  64. ThrottleManager& throttleManager;
  65. BooleanSetting& pauseSetting;
  66. BooleanSetting& powerSetting;
  67. uint64_t idealRealTime;
  68. EmuTime emuTime;
  69. double sleepAdjust;
  70. bool enabled;
  71. };
  72. } // namespace openmsx
  73. #endif