21 al_install_keyboard();
25 al_set_config_value(al_get_system_config(),
"joystick",
"driver",
"xinput");
26 al_install_joystick();
31 m_currentGamePadStates[i].
ID =
nullptr;
32 m_previousGamePadStates[i].
ID =
nullptr;
37 if (al_is_joystick_installed())
43 void InputState::Update()
45 if (al_is_keyboard_installed())
47 m_previousKeyboardState = m_currentKeyboardState;
48 al_get_keyboard_state(&m_currentKeyboardState);
51 if (al_is_mouse_installed())
53 m_previousMouseState = m_currentMouseState;
54 al_get_mouse_state(&m_currentMouseState);
59 m_previousGamePadStates[i] = m_currentGamePadStates[i];
63 void InputState::InitializeGamePads()
65 for (
int i = 0; i < al_get_num_joysticks(); i++)
67 ALLEGRO_JOYSTICK *joystick = al_get_joystick(i);
74 if (m_currentGamePadStates[i].ID ==
nullptr)
76 m_currentGamePadStates[i].
ID = joystick;
78 m_currentGamePadStates[i].
Reset();
80 m_previousGamePadStates[i] = m_currentGamePadStates[i];
82 m_map.emplace(std::pair<ALLEGRO_JOYSTICK *, int>(joystick, i));
90 void InputState::UpdateConfigurationEvent()
92 if (al_is_joystick_installed())
94 if (al_reconfigure_joysticks())
101 void InputState::UpdateAxisEvent(ALLEGRO_EVENT alEvent)
103 int index = GetGamePadIndex(alEvent.joystick.id);
112 if (alEvent.joystick.stick == 0 && alEvent.joystick.axis == 0)
116 else if (alEvent.joystick.stick == 0 && alEvent.joystick.axis == 1)
120 else if (alEvent.joystick.stick == 1 && alEvent.joystick.axis == 0)
124 else if (alEvent.joystick.stick == 1 && alEvent.joystick.axis == 1)
128 else if (alEvent.joystick.stick == 2)
130 m_currentGamePadStates[index].
Triggers.
Left = alEvent.joystick.pos;
132 else if (alEvent.joystick.stick == 3)
134 m_currentGamePadStates[index].
Triggers.
Right = alEvent.joystick.pos;
139 void InputState::UpdateButtonEvent(ALLEGRO_EVENT alEvent,
ButtonState state)
141 int index = GetGamePadIndex(alEvent.joystick.id);
145 GamePadButtons *pButtons = &m_currentGamePadStates[index].
Buttons;
146 GamePadDPad *pDPad = &m_currentGamePadStates[index].
DPad;
152 switch (alEvent.joystick.button)
154 case 0: pButtons->A = state;
break;
155 case 1: pButtons->B = state;
break;
156 case 2: pButtons->X = state;
break;
157 case 3: pButtons->Y = state;
break;
159 case 4: pButtons->RightShoulder = state;
break;
160 case 5: pButtons->LeftShoulder = state;
break;
162 case 6: pButtons->RightStick = state;
break;
163 case 7: pButtons->LeftStick = state;
break;
165 case 8: pButtons->Back = state;
break;
166 case 9: pButtons->Start = state;
break;
168 case 10: pDPad->
Right = state;
break;
169 case 11: pDPad->Left = state;
break;
170 case 12: pDPad->Down = state;
break;
171 case 13: pDPad->Up = state;
break;
178 return al_key_down(&m_currentKeyboardState, (
int)key);
183 return !al_key_down(&m_currentKeyboardState, (
int)key);
188 return IsKeyDown(key) && !al_key_down(&m_previousKeyboardState, (
int)key);
193 return IsKeyUp(key) && al_key_down(&m_previousKeyboardState, (
int)key);
200 if (m_currentGamePadStates[controllingIndex].
IsButtonUp(button))
202 indexOut = controllingIndex;
219 if (m_currentGamePadStates[controllingIndex].
IsButtonDown(button))
221 indexOut = controllingIndex;
238 if (m_currentGamePadStates[controllingIndex].
IsButtonDown(button) &&
239 m_previousGamePadStates[controllingIndex].
IsButtonUp(button))
241 indexOut = controllingIndex;
258 if (m_currentGamePadStates[controllingIndex].
IsButtonUp(button) &&
259 m_previousGamePadStates[controllingIndex].
IsButtonDown(button))
261 indexOut = controllingIndex;
276 return m_currentGamePadStates[gamePadIndex];
279 int8_t InputState::GetGamePadIndex(ALLEGRO_JOYSTICK *pId)
float Y
The y-coordinate of the vector.
float X
The x-coordinate of the vector.
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Button
Defines the buttons for an Xbox Controller.
ButtonState
Defines the possible states of a Button.
Key
Defines the keys on a keyboard.
Represents specific information about the state of an Xbox Controller, including the current state of...
GamePadButtons Buttons
The current state of the GamePad's Buttons.
GamePadDPad DPad
The current state of the GamePad's DPad.
ALLEGRO_JOYSTICK * ID
The underlaying allegro joystick id.
bool IsConnected
True if the GamePad is connected, false otherwise.
GamePadThumbSticks Thumbsticks
The current state of the GamePad's Thumbsticks.
GamePadTriggers Triggers
The current state of the GamePad's Triggers.