ThrottleManager.hh 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. #ifndef THROTTLEMANAGER_HH
  2. #define THROTTLEMANAGER_HH
  3. #include "Subject.hh"
  4. #include "BooleanSetting.hh"
  5. namespace openmsx {
  6. class CommandController;
  7. /**
  8. * Manages the throttle state of openMSX. It depends on the throttle setting,
  9. * but also on the fullspeedwhenfastloading setting and if the MSX has
  10. * notified us that it is loading... If you want to know about the throttle
  11. * status of openMSX, attach to me! (And not just to throttleSetting!)
  12. */
  13. class ThrottleManager final : public Subject<ThrottleManager>
  14. , private Observer<Setting>
  15. {
  16. public:
  17. explicit ThrottleManager(CommandController& commandController);
  18. ~ThrottleManager();
  19. /**
  20. * Ask if throttling is enabled. Depends on the throttle setting, but
  21. * also on the fullspeedwhenfastloading setting and if the MSX has
  22. * notified us that it is loading... To be used for the timing.
  23. */
  24. bool isThrottled() const { return throttle; }
  25. private:
  26. friend class LoadingIndicator;
  27. /**
  28. * Use to indicate that the MSX is in a loading state, so that full
  29. * speed can be enabled. Note that the caller can only call it once,
  30. * when the state changes. It may not call it twice in a row with the
  31. * same value for the argument.
  32. * @param state true for loading, false for not loading
  33. */
  34. void indicateLoadingState(bool state);
  35. void updateStatus();
  36. // Observer<Setting>
  37. void update(const Setting& setting) override;
  38. BooleanSetting throttleSetting;
  39. BooleanSetting fullSpeedLoadingSetting;
  40. int loading;
  41. bool throttle;
  42. };
  43. /**
  44. * Used by a device to indicate when it is loading.
  45. */
  46. class LoadingIndicator
  47. {
  48. public:
  49. explicit LoadingIndicator(ThrottleManager& throttleManager);
  50. ~LoadingIndicator();
  51. /**
  52. * Called by the device to indicate its loading state may have changed.
  53. */
  54. void update(bool newState);
  55. private:
  56. ThrottleManager& throttleManager;
  57. bool isLoading;
  58. };
  59. } // namespace openmsx
  60. #endif