Make F4/F5 adding/removing controllers a full feature instead of an accidentally pushed debug tool

This commit is contained in:
kalaposfos13 2025-04-15 15:27:22 +02:00
parent ce359b5b4d
commit edf14ac019
3 changed files with 25 additions and 17 deletions

View File

@ -588,7 +588,7 @@ s32 PS4_SYSV_ABI sceUserServiceGetLoginUserIdList(OrbisUserServiceLoginUserIdLis
// TODO only first user, do the others as well // TODO only first user, do the others as well
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
auto controllers = *Common::Singleton<Input::GameControllers>::Instance(); auto controllers = *Common::Singleton<Input::GameControllers>::Instance();
userIdList->user_id[i] = controllers[i]->GetUserId(); userIdList->user_id[i] = controllers[i]->user_id;
} }
return ORBIS_OK; return ORBIS_OK;
} }

View File

@ -65,12 +65,10 @@ public:
bool SetVibration(u8 smallMotor, u8 largeMotor); bool SetVibration(u8 smallMotor, u8 largeMotor);
void SetTouchpadState(int touchIndex, bool touchDown, float x, float y); void SetTouchpadState(int touchIndex, bool touchDown, float x, float y);
u32 Poll(); u32 Poll();
u32 GetUserId() {
return user_id;
}
float gyro_poll_rate; float gyro_poll_rate;
float accel_poll_rate; float accel_poll_rate;
u32 user_id = -1; // ORBIS_USER_SERVICE_USER_ID_INVALID
static void CalculateOrientation(Libraries::Pad::OrbisFVector3& acceleration, static void CalculateOrientation(Libraries::Pad::OrbisFVector3& acceleration,
Libraries::Pad::OrbisFVector3& angularVelocity, Libraries::Pad::OrbisFVector3& angularVelocity,
float deltaTime, float deltaTime,
@ -89,7 +87,6 @@ private:
u32 m_first_state = 0; u32 m_first_state = 0;
std::array<State, MAX_STATES> m_states; std::array<State, MAX_STATES> m_states;
std::array<StateInternal, MAX_STATES> m_private; std::array<StateInternal, MAX_STATES> m_private;
u32 user_id = -1; // ORBIS_USER_SERVICE_USER_ID_INVALID
SDL_Gamepad* m_sdl_gamepad = nullptr; SDL_Gamepad* m_sdl_gamepad = nullptr;
}; };

View File

@ -194,21 +194,20 @@ void WindowSDL::WaitEvent() {
case SDL_EVENT_GAMEPAD_AXIS_MOTION: case SDL_EVENT_GAMEPAD_AXIS_MOTION:
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) - 1;
switch ((SDL_SensorType)event.gsensor.sensor) { switch ((SDL_SensorType)event.gsensor.sensor) {
case SDL_SENSOR_GYRO: case SDL_SENSOR_GYRO:
controllers[controller_id]->Gyro( controllers[controller_id]->Gyro(0, event.gsensor.data);
0, event.gsensor.data);
break; break;
case SDL_SENSOR_ACCEL: case SDL_SENSOR_ACCEL:
controllers[controller_id]->Acceleration( controllers[controller_id]->Acceleration(0, event.gsensor.data);
0, event.gsensor.data);
break; break;
default: default:
break; break;
} }
break;} break;
}
case SDL_EVENT_QUIT: case SDL_EVENT_QUIT:
is_open = false; is_open = false;
break; break;
@ -312,13 +311,25 @@ void WindowSDL::OnKeyboardMouseInput(const SDL_Event* event) {
} }
// test controller connect/disconnect // test controller connect/disconnect
else if (input_id == SDLK_F4) { else if (input_id == SDLK_F4) {
int player_count = Config::GetNumberOfPlayers(); auto controllers = *Common::Singleton<Input::GameControllers>::Instance();
AddUserServiceEvent({OrbisUserServiceEventType::Logout, player_count}); for (int i = 3; i >= 0; i--) {
Config::SetNumberOfPlayers(player_count - 1); if (controllers[i]->user_id != -1) {
AddUserServiceEvent(
{OrbisUserServiceEventType::Logout, (s32)controllers[i]->user_id});
controllers[i]->user_id = -1;
break;
}
}
} else if (input_id == SDLK_F5) { } else if (input_id == SDLK_F5) {
int player_count = Config::GetNumberOfPlayers(); auto controllers = *Common::Singleton<Input::GameControllers>::Instance();
AddUserServiceEvent({OrbisUserServiceEventType::Login, player_count + 1}); for (int i = 0; i < 4; i++) {
Config::SetNumberOfPlayers(player_count + 1); if (controllers[i]->user_id == -1) {
controllers[i]->user_id = i + 1;
AddUserServiceEvent(
{OrbisUserServiceEventType::Login, (s32)controllers[i]->user_id});
break;
}
}
} }
} }