-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathGamepad.h
More file actions
45 lines (37 loc) · 2.07 KB
/
Copy pathGamepad.h
File metadata and controls
45 lines (37 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#pragma once
#include "Vector.h"
#include <SDL3/SDL_gamepad.h>
namespace RTE {
/// Structure for storing SDL_Gamepad or SDL_Joystick states.
struct Gamepad {
int m_DeviceIndex = -1; //!< The internal device index.
SDL_JoystickID m_JoystickID = -1; //!< The joystick ID for event handling.
std::vector<int> m_Axis; //!< Array of analog axis states.
std::vector<int> m_DigitalAxis; //!< Array of digital axis states. Should be updated when analog axis crosses half value 8192.
std::vector<bool> m_Buttons; //!< Array of button states.
#pragma region Creation
/// Constructor method used to instantiate a Gamepad object in system memory and make it ready for use.
Gamepad() = default;
/// Constructor method used to instantiate a Gamepad object in system memory and make it ready for use.
/// @param deviceIndex The SDL device index.
/// @param id The joystick ID for event handling.
/// @param numAxis Number of analog axis.
/// @param numButtons Number of buttons.
Gamepad(int deviceIndex, SDL_JoystickID id, int numAxis, int numButtons) :
m_DeviceIndex(deviceIndex), m_JoystickID(id), m_Axis(numAxis), m_DigitalAxis(numAxis), m_Buttons(numButtons) {}
#pragma endregion
#pragma region Operator Overloads
/// Equality operator for testing if any two Gamepads are equal by ID.
/// @param joystickID The ID to check equality with.
/// @return A boolean indicating whether the two operands are equal or not.
bool operator==(int joystickID) const { return m_JoystickID == joystickID; }
/// Equality operator for testing if any two Gamepads are equal.
/// @param rhs A Gamepad reference as the right hand side operand.
/// @return A boolean indicating whether the two operands are equal or not.
bool operator==(const Gamepad& rhs) const { return m_JoystickID == rhs.m_JoystickID; }
/// Comparison operator for sorting Gamepads by ID.
/// @param rhs A Gamepad reference as the right hand side operand.
/// @return A boolean indicating the comparison result.
bool operator<(const Gamepad& rhs) const { return m_JoystickID < rhs.m_JoystickID; }
};
} // namespace RTE