ThrottleManager.cc 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. #include "ThrottleManager.hh"
  2. namespace openmsx {
  3. // class ThrottleManager:
  4. ThrottleManager::ThrottleManager(CommandController& commandController)
  5. : throttleSetting(
  6. commandController, "throttle",
  7. "controls speed throttling", true, Setting::DONT_SAVE)
  8. , fullSpeedLoadingSetting(
  9. commandController, "fullspeedwhenloading",
  10. "sets openMSX to full speed when the MSX is loading", false)
  11. , loading(0), throttle(true)
  12. {
  13. throttleSetting .attach(*this);
  14. fullSpeedLoadingSetting.attach(*this);
  15. }
  16. ThrottleManager::~ThrottleManager()
  17. {
  18. throttleSetting .detach(*this);
  19. fullSpeedLoadingSetting.detach(*this);
  20. }
  21. void ThrottleManager::updateStatus()
  22. {
  23. bool newThrottle = throttleSetting.getBoolean() &&
  24. (!loading || !fullSpeedLoadingSetting.getBoolean());
  25. if (throttle != newThrottle) {
  26. throttle = newThrottle;
  27. notify();
  28. }
  29. }
  30. void ThrottleManager::indicateLoadingState(bool state)
  31. {
  32. if (state) {
  33. ++loading;
  34. } else {
  35. --loading;
  36. }
  37. assert(loading >= 0);
  38. updateStatus();
  39. }
  40. void ThrottleManager::update(const Setting& /*setting*/)
  41. {
  42. updateStatus();
  43. }
  44. // class LoadingIndicator:
  45. LoadingIndicator::LoadingIndicator(ThrottleManager& throttleManager_)
  46. : throttleManager(throttleManager_)
  47. , isLoading(false)
  48. {
  49. }
  50. LoadingIndicator::~LoadingIndicator()
  51. {
  52. update(false);
  53. }
  54. void LoadingIndicator::update(bool newState)
  55. {
  56. if (isLoading != newState) {
  57. isLoading = newState;
  58. throttleManager.indicateLoadingState(isLoading);
  59. }
  60. }
  61. } // namespace openmsx