7#include "../InputsManager.h"
24 std::memset(
kv.second.buttonsPressed, 0,
sizeof(
kv.second.buttonsPressed));
25 std::memset(
kv.second.buttonsReleased, 0,
sizeof(
kv.second.buttonsReleased));
44 return it->second.buttonsPressed[
button];
53 return it->second.buttonsReleased[
button];
62 return it->second.axes[
axis];
73 SYSTEM_LOG <<
"JoystickManager created and Initialized with " <<
m_joysticks.size() <<
" joysticks connected\n";
96 if (
kv.second.joystick)
122 SYSTEM_LOG <<
"Gamepad added id=" <<
id <<
"\n";
129 SYSTEM_LOG <<
"Joystick added id=" <<
id <<
"\n";
135 static_cast<int>(
id),
145 SYSTEM_LOG <<
"Gamepad removed id=" <<
id <<
"\n";
152 SYSTEM_LOG <<
"Joystick removed id=" <<
id <<
"\n";
162 static_cast<int>(
id),
171 bool down =
ev->gbutton.down;
179 bool down =
ev->jbutton.down;
189 state.buttonsPressed[
button] =
true;
191 state.buttonsReleased[
button] =
true;
201 bool down =
ev->gbutton.down;
211 state.buttonsPressed[
button] =
true;
213 state.buttonsReleased[
button] =
true;
223 bool down =
ev->jbutton.down;
233 state.buttonsPressed[
button] =
true;
235 state.buttonsReleased[
button] =
true;
244 int axis =
ev->gaxis.axis;
252 float normalized = (value >= 0) ? (value / 32767.0f) : (value / 32768.0f);
262 int axis =
ev->jaxis.axis;
270 float normalized = (value >= 0) ? (value / 32767.0f) : (value / 32768.0f);
286 std::vector<SDL_JoystickID>
res;
318 info.buttons.assign(
info.numButtons,
false);
321 for (
int a =0; a <
info.numAxes; ++a)
327 for (
int b =0; b <
info.numButtons; ++b)
341 if (
it->second.joystick)
358 static_cast<int>(
which),
362 msg.param1 =
down ? 1.0f : 0.0f;
371 if (value >= 0)
normalized = (value / 32767.0f);
377 static_cast<int>(
which),
391 static_cast<int>(
which),
ComponentTypeID GetComponentTypeID_Static()
void Push(const Message &msg)
static EventQueue & Get()
float GetAxis(SDL_JoystickID id, int axis)
void PostJoystickButtonEvent(SDL_JoystickID which, int button, bool down)
bool GetButton(SDL_JoystickID id, int button)
bool IsButtonReleased(SDL_JoystickID id, int button)
bool IsButtonPressed(SDL_JoystickID id, int button)
std::unordered_map< SDL_JoystickID, JoystickState > m_joyStates
static constexpr int MAX_BUTTONS
bool IsJoystickConnected(SDL_JoystickID id)
static JoystickManager & GetInstance()
void OpenJoystick(SDL_JoystickID instance_id)
void PostJoystickConnectedEvent(SDL_JoystickID which, bool bconnected)
void HandleEvent(const SDL_Event *ev)
void CloseJoystick(SDL_JoystickID instance_id)
std::unordered_map< SDL_JoystickID, JoystickInfo > m_joysticks
std::vector< SDL_JoystickID > GetConnectedJoysticks()
void PostJoystickAxisEvent(SDL_JoystickID which, int axis, Sint16 value)
static constexpr int MAX_AXES
static Message Create(EventType _ev_t, EventDomain _domain, int _d_id=-1, int _c_id=-1, uint64_t _t_uid=0)
@ Olympe_EventType_Joystick_ButtonUp
@ Olympe_EventType_Joystick_ButtonDown
@ Olympe_EventType_Joystick_AxisMotion
@ Olympe_EventType_Joystick_Connected
@ Olympe_EventType_Joystick_Disconnected