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