OXYGENHUB
◆ main openmsx / src / input / EventDelay.hh
1.4 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#ifndef EVENTDELAY_HH
2
#define EVENTDELAY_HH
3
4
#include "EmuTime.hh"
5
#include "Event.hh"
6
#include "EventListener.hh"
7
#include "FloatSetting.hh"
8
#include "Schedulable.hh"
9
10
#include "build-info.hh"
11
12
#include <cstdint>
13
#include <deque>
14
#include <vector>
15
16
namespace openmsx {
17
18
class Scheduler;
19
class CommandController;
20
class EventDistributor;
21
class MSXEventDistributor;
22
class ReverseManager;
23
24
/** This class is responsible for translating host events into MSX events.
25
  * It also translates host event timing into EmuTime. To better do this
26
  * we introduce a small delay (default 0.03s) in this translation.
27
  */
28
class EventDelay final : private EventListener, private Schedulable
29
{
30
public:
31
	EventDelay(Scheduler& scheduler, CommandController& commandController,
32
	           EventDistributor& eventDistributor,
33
	           MSXEventDistributor& msxEventDistributor,
34
	           ReverseManager& reverseManager);
35
	~EventDelay();
36
37
	void sync(EmuTime curEmu);
38
	void flush();
39
40
private:
41
	// EventListener
42
	bool signalEvent(const Event& event) override;
43
44
	// Schedulable
45
	void executeUntil(EmuTime time) override;
46
47
private:
48
	EventDistributor& eventDistributor;
49
	MSXEventDistributor& msxEventDistributor;
50
51
	std::vector<Event> toBeScheduledEvents;
52
	std::deque<Event> scheduledEvents;
53
54
#if PLATFORM_ANDROID
55
	std::vector<std::pair<int, Event>> nonMatchedKeyPresses;
56
#endif
57
58
	EmuTime prevEmu = EmuTime::zero();
59
	uint64_t prevReal;
60
	FloatSetting delaySetting;
61
};
62
63
} // namespace openmsx
64
65
#endif