openMSX
EventDelay.hh
Go to the documentation of this file.
1 #ifndef EVENTDELAY_HH
2 #define EVENTDELAY_HH
3 
4 #include "EventListener.hh"
5 #include "Schedulable.hh"
6 #include "EmuTime.hh"
7 #include "FloatSetting.hh"
8 #include "build-info.hh"
9 #include <vector>
10 #include <deque>
11 #include <cstdint>
12 
13 namespace openmsx {
14 
15 class Scheduler;
16 class CommandController;
17 class Event;
18 class EventDistributor;
19 class MSXEventDistributor;
20 class ReverseManager;
21 
22 /** This class is responsible for translating host events into MSX events.
23  * It also translates host event timing into EmuTime. To better do this
24  * we introduce a small delay (default 0.03s) in this translation.
25  */
26 class EventDelay final : private EventListener, private Schedulable
27 {
28 public:
29  EventDelay(Scheduler& scheduler, CommandController& commandController,
30  EventDistributor& eventDistributor,
31  MSXEventDistributor& msxEventDistributor,
32  ReverseManager& reverseManager);
33  ~EventDelay();
34 
35  void sync(EmuTime::param curEmu);
36  void flush();
37 
38 private:
39  using EventPtr = std::shared_ptr<const Event>;
40 
41  // EventListener
42  int signalEvent(const EventPtr& event) override;
43 
44  // Schedulable
45  void executeUntil(EmuTime::param time) override;
46 
47  EventDistributor& eventDistributor;
48  MSXEventDistributor& msxEventDistributor;
49 
50  std::vector<EventPtr> toBeScheduledEvents;
51  std::deque<EventPtr> scheduledEvents;
52 
53 #if PLATFORM_ANDROID
54  std::vector<std::pair<int, EventPtr>> nonMatchedKeyPresses;
55 #endif
56 
57  EmuTime prevEmu;
58  uint64_t prevReal;
59  FloatSetting delaySetting;
60 };
61 
62 } // namespace openmsx
63 
64 #endif
bool getEnum() const noexcept
Definition: EnumSetting.hh:96
void sync(EmuTime::param curEmu)
Definition: EventDelay.cc:86
Every class that wants to get scheduled at some point must inherit from this class.
Definition: Schedulable.hh:33
EventDelay(Scheduler &scheduler, CommandController &commandController, EventDistributor &eventDistributor, MSXEventDistributor &msxEventDistributor, ReverseManager &reverseManager)
Definition: EventDelay.cc:15