mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2025-07-27 12:34:37 +00:00
Fix gamepad indexing + cleanup
This commit is contained in:
parent
e6354b8f2d
commit
01d8f85bc8
@ -289,8 +289,7 @@ int PS4_SYSV_ABI scePadOutputReport() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI scePadRead(s32 handle, OrbisPadData* pData, s32 num) {
|
int PS4_SYSV_ABI scePadRead(s32 handle, OrbisPadData* pData, s32 num) {
|
||||||
LOG_TRACE(Lib_Pad, "called");
|
LOG_TRACE(Lib_Pad, "handle: {}", handle);
|
||||||
LOG_DEBUG(Lib_Pad, "handle: {}", handle);
|
|
||||||
int connected_count = 0;
|
int connected_count = 0;
|
||||||
bool connected = false;
|
bool connected = false;
|
||||||
Input::State states[64];
|
Input::State states[64];
|
||||||
@ -356,8 +355,7 @@ int PS4_SYSV_ABI scePadReadHistory() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int PS4_SYSV_ABI scePadReadState(s32 handle, OrbisPadData* pData) {
|
int PS4_SYSV_ABI scePadReadState(s32 handle, OrbisPadData* pData) {
|
||||||
LOG_TRACE(Lib_Pad, "called");
|
LOG_TRACE(Lib_Pad, "handle: {}", handle);
|
||||||
LOG_DEBUG(Lib_Pad, "handle: {}", handle);
|
|
||||||
if (handle == ORBIS_PAD_ERROR_DEVICE_NO_HANDLE) {
|
if (handle == ORBIS_PAD_ERROR_DEVICE_NO_HANDLE) {
|
||||||
return ORBIS_PAD_ERROR_INVALID_HANDLE;
|
return ORBIS_PAD_ERROR_INVALID_HANDLE;
|
||||||
}
|
}
|
||||||
|
@ -285,6 +285,7 @@ void GameControllers::TryOpenSDLControllers(GameControllers& controllers) {
|
|||||||
controllers[i]->m_sdl_gamepad = pad;
|
controllers[i]->m_sdl_gamepad = pad;
|
||||||
controllers[i]->user_id = i + 1;
|
controllers[i]->user_id = i + 1;
|
||||||
slot_taken[i] = true;
|
slot_taken[i] = true;
|
||||||
|
SDL_SetGamepadPlayerIndex(pad, i);
|
||||||
AddUserServiceEvent(
|
AddUserServiceEvent(
|
||||||
{OrbisUserServiceEventType::Login, SDL_GetGamepadPlayerIndex(pad) + 1});
|
{OrbisUserServiceEventType::Login, SDL_GetGamepadPlayerIndex(pad) + 1});
|
||||||
|
|
||||||
@ -312,30 +313,6 @@ void GameControllers::TryOpenSDLControllers(GameControllers& controllers) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (m_sdl_gamepad == nullptr || !SDL_GamepadConnected(m_sdl_gamepad)) {
|
|
||||||
// int gamepad_count;
|
|
||||||
// SDL_JoystickID* gamepads = SDL_GetGamepads(&gamepad_count);
|
|
||||||
// m_sdl_gamepad = gamepad_count > 0 ? SDL_OpenGamepad(gamepads[0]) : nullptr;
|
|
||||||
// if (Config::getIsMotionControlsEnabled()) {
|
|
||||||
// if (SDL_SetGamepadSensorEnabled(m_sdl_gamepad, SDL_SENSOR_GYRO, true)) {
|
|
||||||
// gyro_poll_rate = SDL_GetGamepadSensorDataRate(m_sdl_gamepad, SDL_SENSOR_GYRO);
|
|
||||||
// LOG_INFO(Input, "Gyro initialized, poll rate: {}", gyro_poll_rate);
|
|
||||||
// } else {
|
|
||||||
// LOG_ERROR(Input, "Failed to initialize gyro controls for gamepad");
|
|
||||||
// }
|
|
||||||
// if (SDL_SetGamepadSensorEnabled(m_sdl_gamepad, SDL_SENSOR_ACCEL, true)) {
|
|
||||||
// accel_poll_rate = SDL_GetGamepadSensorDataRate(m_sdl_gamepad, SDL_SENSOR_ACCEL);
|
|
||||||
// LOG_INFO(Input, "Accel initialized, poll rate: {}", accel_poll_rate);
|
|
||||||
// } else {
|
|
||||||
// LOG_ERROR(Input, "Failed to initialize accel controls for gamepad");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// SDL_free(gamepads);
|
|
||||||
|
|
||||||
// SetLightBarRGB(0, 0, 255);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
u32 GameController::Poll() {
|
u32 GameController::Poll() {
|
||||||
|
@ -754,7 +754,11 @@ void ActivateOutputsFromInputs() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
u8 GetGamepadIndexFromJoystickId(SDL_JoystickID id) {
|
u8 GetGamepadIndexFromJoystickId(SDL_JoystickID id) {
|
||||||
return SDL_GetGamepadPlayerIndex(SDL_GetGamepadFromID(id)) + 1;
|
u8 index = SDL_GetGamepadPlayerIndex(SDL_GetGamepadFromID(id));
|
||||||
|
if (index > 3) [[unlikely]] {
|
||||||
|
UNREACHABLE_MSG("Index out of bounds: {}", index);
|
||||||
|
}
|
||||||
|
return index;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Input
|
} // namespace Input
|
||||||
|
@ -191,7 +191,7 @@ void WindowSDL::WaitEvent() {
|
|||||||
OnGamepadEvent(&event);
|
OnGamepadEvent(&event);
|
||||||
break;
|
break;
|
||||||
case SDL_EVENT_GAMEPAD_SENSOR_UPDATE: {
|
case SDL_EVENT_GAMEPAD_SENSOR_UPDATE: {
|
||||||
int controller_id = Input::GetGamepadIndexFromJoystickId(event.gsensor.which) - 1;
|
int controller_id = Input::GetGamepadIndexFromJoystickId(event.gsensor.which);
|
||||||
switch ((SDL_SensorType)event.gsensor.sensor) {
|
switch ((SDL_SensorType)event.gsensor.sensor) {
|
||||||
case SDL_SENSOR_GYRO:
|
case SDL_SENSOR_GYRO:
|
||||||
controllers[controller_id]->Gyro(0, event.gsensor.data);
|
controllers[controller_id]->Gyro(0, event.gsensor.data);
|
||||||
|
Loading…
Reference in New Issue
Block a user