openMSX
Joystick.hh
Go to the documentation of this file.
1 #ifndef JOYSTICK_HH
2 #define JOYSTICK_HH
3 
4 #include "JoystickDevice.hh"
5 #include "MSXEventListener.hh"
6 #include "StateChangeListener.hh"
7 #include "StringSetting.hh"
8 #include "serialize_meta.hh"
9 #include <SDL.h>
10 
11 namespace openmsx {
12 
13 class MSXEventDistributor;
14 class StateChangeDistributor;
15 class CommandController;
16 class PluggingController;
17 class GlobalSettings;
18 class IntegerSetting;
19 class TclObject;
20 class Interpreter;
21 
24 class Joystick final
25 #ifndef SDL_JOYSTICK_DISABLED
26  : public JoystickDevice, private MSXEventListener, private StateChangeListener
27 #endif
28 {
29 public:
32  static void registerAll(MSXEventDistributor& eventDistributor,
33  StateChangeDistributor& stateChangeDistributor,
34  CommandController& commandController,
35  GlobalSettings& globalSettings,
36  PluggingController& controller);
37 
38  Joystick(MSXEventDistributor& eventDistributor,
39  StateChangeDistributor& stateChangeDistributor,
40  CommandController& commandController,
41  GlobalSettings& globalSettings,
42  SDL_Joystick* joystick);
43  ~Joystick()
44 #ifndef SDL_JOYSTICK_DISABLED
45  override
46 #endif
47  ;
48 
49 #ifndef SDL_JOYSTICK_DISABLED
50  // Pluggable
51  [[nodiscard]] std::string_view getName() const override;
52  [[nodiscard]] std::string_view getDescription() const override;
53  void plugHelper(Connector& connector, EmuTime::param time) override;
54  void unplugHelper(EmuTime::param time) override;
55 
56  // JoystickDevice
57  [[nodiscard]] byte read(EmuTime::param time) override;
58  void write(byte value, EmuTime::param time) override;
59 
60  template<typename Archive>
61  void serialize(Archive& ar, unsigned version);
62 
63 private:
64  void plugHelper2();
65  [[nodiscard]] byte calcState();
66  [[nodiscard]] bool getState(Interpreter& interp, const TclObject& dict, std::string_view key,
67  int threshold);
68  void createEvent(EmuTime::param time, byte newStatus);
69 
70  // MSXEventListener
71  void signalMSXEvent(const std::shared_ptr<const Event>& event,
72  EmuTime::param time) noexcept override;
73  // StateChangeListener
74  void signalStateChange(const std::shared_ptr<StateChange>& event) override;
75  void stopReplay(EmuTime::param time) noexcept override;
76 
77 private:
78  MSXEventDistributor& eventDistributor;
79  StateChangeDistributor& stateChangeDistributor;
80 
81  SDL_Joystick* const joystick;
82  const unsigned joyNum;
83  IntegerSetting& deadSetting; // must come after joyNum
84  const std::string name;
85  const std::string desc;
86  StringSetting configSetting;
87 
88  byte status;
89  bool pin8;
90 #endif // SDL_JOYSTICK_DISABLED
91 };
93 
94 } // namespace openmsx
95 
96 #endif
Represents something you can plug devices into.
Definition: Connector.hh:21
This class contains settings that are used by several other class (including some singletons).
A Setting with an integer value.
Uses an SDL joystick to emulate an MSX joystick.
Definition: Joystick.hh:28
std::string_view getName() const override
Name used to identify this pluggable.
Definition: Joystick.cc:188
void unplugHelper(EmuTime::param time) override
Definition: Joystick.cc:213
std::string_view getDescription() const override
Description for this pluggable.
Definition: Joystick.cc:193
~Joystick() override
Definition: Joystick.cc:177
void write(byte value, EmuTime::param time) override
Write a value to the joystick device.
Definition: Joystick.cc:226
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: Joystick.cc:198
static void registerAll(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, CommandController &commandController, GlobalSettings &globalSettings, PluggingController &controller)
Register all available SDL joysticks.
Definition: Joystick.cc:26
void serialize(Archive &ar, unsigned version)
Definition: Joystick.cc:367
byte read(EmuTime::param time) override
Read from the joystick device.
Definition: Joystick.cc:221
Joystick(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, CommandController &commandController, GlobalSettings &globalSettings, SDL_Joystick *joystick)
Definition: Joystick.cc:155
Central administration of Connectors and Pluggables.
This file implemented 3 utility functions:
Definition: Autofire.cc:5
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)