OXYGENHUB
◆ main openmsx / src / ThrottleManager.cc
1.4 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "ThrottleManager.hh"
2
3
namespace openmsx {
4
5
// class ThrottleManager:
6
7
ThrottleManager::ThrottleManager(CommandController& commandController)
8
	: throttleSetting(
9
		commandController, "throttle",
10
		"controls speed throttling", true, Setting::Save::NO)
11
	, fullSpeedLoadingSetting(
12
		commandController, "fullspeedwhenloading",
13
		"sets openMSX to full speed when the MSX is loading", false)
14
{
15
	throttleSetting        .attach(*this);
16
	fullSpeedLoadingSetting.attach(*this);
17
}
18
19
ThrottleManager::~ThrottleManager()
20
{
21
	throttleSetting        .detach(*this);
22
	fullSpeedLoadingSetting.detach(*this);
23
}
24
25
void ThrottleManager::updateStatus()
26
{
27
	bool newThrottle = throttleSetting.getBoolean() &&
28
	                   (!loading || !fullSpeedLoadingSetting.getBoolean());
29
	if (throttle != newThrottle) {
30
		throttle = newThrottle;
31
		notify();
32
	}
33
}
34
35
void ThrottleManager::indicateLoadingState(bool state)
36
{
37
	if (state) {
38
		++loading;
39
	} else {
40
		--loading;
41
	}
42
	assert(loading >= 0);
43
	updateStatus();
44
}
45
46
void ThrottleManager::update(const Setting& /*setting*/) noexcept
47
{
48
	updateStatus();
49
}
50
51
52
// class LoadingIndicator:
53
54
LoadingIndicator::LoadingIndicator(ThrottleManager& throttleManager_)
55
	: throttleManager(throttleManager_)
56
{
57
}
58
59
LoadingIndicator::~LoadingIndicator()
60
{
61
	update(false);
62
}
63
64
void LoadingIndicator::update(bool newState)
65
{
66
	if (isLoading != newState) {
67
		isLoading = newState;
68
		throttleManager.indicateLoadingState(isLoading);
69
	}
70
}
71
72
} // namespace openmsx