openMSX
ThrottleManager.cc
Go to the documentation of this file.
1 #include "ThrottleManager.hh"
2 #include "BooleanSetting.hh"
3 #include "memory.hh"
4 
5 namespace openmsx {
6 
7 // class ThrottleManager:
8 
10  : throttleSetting(make_unique<BooleanSetting>(
11  commandController, "throttle",
12  "controls speed throttling", true, Setting::DONT_SAVE))
13  , fullSpeedLoadingSetting(make_unique<BooleanSetting>(
14  commandController, "fullspeedwhenloading",
15  "sets openMSX to full speed when the MSX is loading", false))
16  , loading(0), throttle(true)
17 {
18  throttleSetting->attach(*this);
19  fullSpeedLoadingSetting->attach(*this);
20 }
21 
23 {
24  throttleSetting->detach(*this);
25  fullSpeedLoadingSetting->detach(*this);
26 }
27 
28 void ThrottleManager::updateStatus()
29 {
30  bool newThrottle = throttleSetting->getValue() &&
31  (!loading || !fullSpeedLoadingSetting->getValue());
32  if (throttle != newThrottle) {
33  throttle = newThrottle;
34  notify();
35  }
36 }
37 
39 {
40  return throttle;
41 }
42 
43 void ThrottleManager::indicateLoadingState(bool state)
44 {
45  if (state) {
46  ++loading;
47  } else {
48  --loading;
49  }
50  assert(loading >= 0);
51  updateStatus();
52 }
53 
54 void ThrottleManager::update(const Setting& /*setting*/)
55 {
56  updateStatus();
57 }
58 
59 
60 // class LoadingIndicator:
61 
63  : throttleManager(throttleManager_)
64  , isLoading(false)
65 {
66 }
67 
69 {
70  update(false);
71 }
72 
73 void LoadingIndicator::update(bool newState)
74 {
75  if (isLoading != newState) {
76  isLoading = newState;
77  throttleManager.indicateLoadingState(isLoading);
78  }
79 }
80 
81 } // namespace openmsx