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"
7#include "StringSetting.hh"
8#include "serialize_meta.hh"
9#include <SDL.h>
10
11namespace openmsx {
12
13class MSXEventDistributor;
14class StateChangeDistributor;
15class CommandController;
16class PluggingController;
17class GlobalSettings;
18class IntegerSetting;
19class TclObject;
20class Interpreter;
21
24class Joystick final
25#ifndef SDL_JOYSTICK_DISABLED
26 : public JoystickDevice, private MSXEventListener, private StateChangeListener
27#endif
28{
29public:
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]] uint8_t read(EmuTime::param time) override;
58 void write(uint8_t value, EmuTime::param time) override;
59
60 template<typename Archive>
61 void serialize(Archive& ar, unsigned version);
62
63private:
64 void plugHelper2();
65 [[nodiscard]] uint8_t calcState();
66 [[nodiscard]] bool getState(Interpreter& interp, const TclObject& dict, std::string_view key,
67 int threshold);
68 void createEvent(EmuTime::param time, uint8_t newStatus);
69
70 // MSXEventListener
71 void signalMSXEvent(const Event& event,
72 EmuTime::param time) noexcept override;
73 // StateChangeListener
74 void signalStateChange(const StateChange& event) override;
75 void stopReplay(EmuTime::param time) noexcept override;
76
77private:
78 MSXEventDistributor& eventDistributor;
79 StateChangeDistributor& stateChangeDistributor;
80
81 SDL_Joystick* const joystick;
82 const int joyNum;
83 IntegerSetting& deadSetting; // must come after joyNum
84 const std::string name;
85 const std::string desc;
86 StringSetting configSetting;
87
88 uint8_t status;
89 bool pin8 = false; // avoid UMR
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
void write(uint8_t value, EmuTime::param time) override
Write a value to the joystick device.
Definition: Joystick.cc:222
std::string_view getName() const override
Name used to identify this pluggable.
Definition: Joystick.cc:184
void unplugHelper(EmuTime::param time) override
Definition: Joystick.cc:209
std::string_view getDescription() const override
Description for this pluggable.
Definition: Joystick.cc:189
uint8_t read(EmuTime::param time) override
Read from the joystick device.
Definition: Joystick.cc:217
~Joystick() override
Definition: Joystick.cc:173
void plugHelper(Connector &connector, EmuTime::param time) override
Definition: Joystick.cc:194
static void registerAll(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, CommandController &commandController, GlobalSettings &globalSettings, PluggingController &controller)
Register all available SDL joysticks.
Definition: Joystick.cc:24
void serialize(Archive &ar, unsigned version)
Definition: Joystick.cc:363
Joystick(MSXEventDistributor &eventDistributor, StateChangeDistributor &stateChangeDistributor, CommandController &commandController, GlobalSettings &globalSettings, SDL_Joystick *joystick)
Definition: Joystick.cc:153
Central administration of Connectors and Pluggables.
Base class for all external MSX state changing events.
Definition: StateChange.hh:20
This file implemented 3 utility functions:
Definition: Autofire.cc:9
std::variant< KeyUpEvent, KeyDownEvent, MouseMotionEvent, MouseButtonUpEvent, MouseButtonDownEvent, MouseWheelEvent, JoystickAxisMotionEvent, JoystickHatEvent, JoystickButtonUpEvent, JoystickButtonDownEvent, OsdControlReleaseEvent, OsdControlPressEvent, WindowEvent, TextEvent, FileDropEvent, QuitEvent, FinishFrameEvent, CliCommandEvent, GroupEvent, BootEvent, FrameDrawnEvent, BreakEvent, SwitchRendererEvent, TakeReverseSnapshotEvent, AfterTimedEvent, MachineLoadedEvent, MachineActivatedEvent, MachineDeactivatedEvent, MidiInReaderEvent, MidiInWindowsEvent, MidiInCoreMidiEvent, MidiInCoreMidiVirtualEvent, MidiInALSAEvent, Rs232TesterEvent, ImGuiDelayedActionEvent, ImGuiActiveEvent > Event
Definition: Event.hh:450
SERIALIZE_CLASS_VERSION(CassettePlayer, 2)