| 1 |
#ifndef JOYHANDLE_HH |
| 2 |
#define JOYHANDLE_HH |
| 3 |
|
| 4 |
#include "JoystickDevice.hh" |
| 5 |
|
| 6 |
#include "AnalogInput.hh" |
| 7 |
#include "BooleanInput.hh" |
| 8 |
#include "MSXEventListener.hh" |
| 9 |
#include "StateChangeListener.hh" |
| 10 |
#include "StringSetting.hh" |
| 11 |
|
| 12 |
#include <array> |
| 13 |
#include <vector> |
| 14 |
|
| 15 |
namespace openmsx { |
| 16 |
|
| 17 |
class CommandController; |
| 18 |
class JoystickManager; |
| 19 |
class MSXEventDistributor; |
| 20 |
class StateChangeDistributor; |
| 21 |
|
| 22 |
class JoyHandle final : public JoystickDevice, private MSXEventListener |
| 23 |
, private StateChangeListener |
| 24 |
{ |
| 25 |
public: |
| 26 |
JoyHandle(CommandController& commandController, |
| 27 |
MSXEventDistributor& eventDistributor, |
| 28 |
StateChangeDistributor& stateChangeDistributor, |
| 29 |
JoystickManager& joystickManager, |
| 30 |
uint8_t id); |
| 31 |
~JoyHandle() override; |
| 32 |
|
| 33 |
[[nodiscard]] static TclObject getDefaultConfig(JoystickId joyId, const JoystickManager& joystickManager); |
| 34 |
|
| 35 |
template<typename Archive> |
| 36 |
void serialize(Archive& ar, unsigned version); |
| 37 |
|
| 38 |
private: |
| 39 |
void checkJoystickConfig(const TclObject& newValue); |
| 40 |
|
| 41 |
|
| 42 |
[[nodiscard]] zstring_view getName() const override; |
| 43 |
[[nodiscard]] zstring_view getDescription() const override; |
| 44 |
void plugHelper(Connector& connector, EmuTime time) override; |
| 45 |
void unplugHelper(EmuTime time) override; |
| 46 |
|
| 47 |
|
| 48 |
[[nodiscard]] uint8_t read(EmuTime time) override; |
| 49 |
void write(uint8_t value, EmuTime time) override; |
| 50 |
|
| 51 |
|
| 52 |
void signalMSXEvent(const Event& event, |
| 53 |
EmuTime time) noexcept override; |
| 54 |
|
| 55 |
void signalStateChange(const StateChange& event) override; |
| 56 |
void stopReplay(EmuTime time) noexcept override; |
| 57 |
|
| 58 |
void resetWheelCache(); |
| 59 |
|
| 60 |
private: |
| 61 |
CommandController& commandController; |
| 62 |
MSXEventDistributor& eventDistributor; |
| 63 |
StateChangeDistributor& stateChangeDistributor; |
| 64 |
JoystickManager& joystickManager; |
| 65 |
StringSetting configSetting; |
| 66 |
|
| 67 |
|
| 68 |
std::array<std::vector<BooleanInput>, 6> bindings; |
| 69 |
struct AnalogStatus { |
| 70 |
AnalogInput binding; |
| 71 |
float value = 0.0f; |
| 72 |
}; |
| 73 |
std::vector<AnalogStatus> wheelBindings; |
| 74 |
|
| 75 |
const std::string description; |
| 76 |
const uint8_t id; |
| 77 |
uint8_t status = JOY_UP | JOY_DOWN | JOY_LEFT | JOY_RIGHT | |
| 78 |
JOY_BUTTONA | JOY_BUTTONB; |
| 79 |
float analogValue = 0.0f; |
| 80 |
}; |
| 81 |
|
| 82 |
} |
| 83 |
|
| 84 |
#endif |