Rendu
A lightweight rendering engine for experimentations
Loading...
Searching...
No Matches
Controller.hpp
1#pragma once
2
3#include "Common.hpp"
4
9class Controller {
10
11public:
13 Controller();
14
16 enum Input {
17 ButtonX,
18 ButtonY,
19 ButtonA,
20 ButtonB,
21 BumperL1,
22 TriggerL2,
23 ButtonL3,
24 BumperR1,
25 TriggerR2,
26 ButtonR3,
27 ButtonUp,
28 ButtonLeft,
29 ButtonDown,
30 ButtonRight,
31 ButtonLogo,
32 ButtonMenu,
33 ButtonView,
34 PadLeftX,
35 PadLeftY,
36 PadRightX,
37 PadRightY,
38 InputCount
39 };
40
46 virtual bool activate(int id) = 0;
47
51 virtual void deactivate() = 0;
52
56 virtual void update() = 0;
57
63 bool pressed(const Controller::Input & input) const;
64
71 bool triggered(const Controller::Input & input, bool absorb = false);
72
78 float axis(const Controller::Input & input) const;
79
83 int id() const { return _id; }
84
88 std::string name() const { return _name; }
89
93 std::string guid() const { return _name; }
94
96 virtual ~Controller() = default;
97
99 Controller(const Controller &) = delete;
100
104 Controller & operator=(const Controller &) = delete;
105
107 Controller(Controller &&) = delete;
108
113
122 static void saveConfiguration(const std::string & outputPath, const std::string & guid, const std::string & name, const std::vector<int> & axesMapping, const std::vector<int> & buttonsMapping);
123
131 static bool parseConfiguration(const std::string & settingsContent, std::vector<int> & axesMapping, std::vector<int> & buttonsMapping);
132
133protected:
137 void reset();
138
141 bool pressed = false;
142 bool first = false;
143 };
144
145 ControllerButton _buttons[Controller::Input::InputCount];
146 float _axes[Controller::Input::InputCount];
147
148 int _id = -1;
149 std::string _name = "Unknown";
150 std::string _guid = "0x0";
151};
Represents a joystick or any additional controller.
Definition: Controller.hpp:9
Controller(Controller &&)=delete
int id() const
Definition: Controller.hpp:83
static bool parseConfiguration(const std::string &settingsContent, std::vector< int > &axesMapping, std::vector< int > &buttonsMapping)
Definition: Controller.cpp:84
Controller & operator=(const Controller &)=delete
ControllerButton _buttons[Controller::Input::InputCount]
States of all possible buttons.
Definition: Controller.hpp:145
virtual bool activate(int id)=0
bool triggered(const Controller::Input &input, bool absorb=false)
Definition: Controller.cpp:25
std::string name() const
Definition: Controller.hpp:88
virtual ~Controller()=default
Destructor.
Controller()
Constructor.
Definition: Controller.cpp:7
Input
Controller inputs, based on the Xbox controller layout.
Definition: Controller.hpp:16
std::string guid() const
Definition: Controller.hpp:93
virtual void update()=0
Controller(const Controller &)=delete
void reset()
Definition: Controller.cpp:11
virtual void deactivate()=0
static void saveConfiguration(const std::string &outputPath, const std::string &guid, const std::string &name, const std::vector< int > &axesMapping, const std::vector< int > &buttonsMapping)
Definition: Controller.cpp:37
int _id
Joystick ID (or -1 if no joystick is connected).
Definition: Controller.hpp:148
Controller & operator=(Controller &&)=delete
std::string _guid
GUID of the joystick.
Definition: Controller.hpp:150
float _axes[Controller::Input::InputCount]
States of all possible axis.
Definition: Controller.hpp:146
bool pressed(const Controller::Input &input) const
Definition: Controller.cpp:21
float axis(const Controller::Input &input) const
Definition: Controller.cpp:33
std::string _name
Name of the joystick.
Definition: Controller.hpp:149
The input manager is responsible for updating the internal input states (keyboard,...
Definition: Input.hpp:10
The state of a controller button.
Definition: Controller.hpp:140
bool pressed
Is the button currently held.
Definition: Controller.hpp:141
bool first
Is it the first frame it is held.
Definition: Controller.hpp:142