From 62a49ec0cc9d78a8733f81474b170664da760b4d Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Fri, 25 Jul 2025 00:08:56 +0200 Subject: [PATCH 1/2] add imgui.ini to gitignore --- .gitignore | 1 + imgui.ini | 4 ---- 2 files changed, 1 insertion(+), 4 deletions(-) delete mode 100644 imgui.ini diff --git a/.gitignore b/.gitignore index 9f9fd18d6..7122989a4 100644 --- a/.gitignore +++ b/.gitignore @@ -102,3 +102,4 @@ LogLoadingWarning.txt LogConsole.txt Console.dump.log Console.input.log +imgui.ini diff --git a/imgui.ini b/imgui.ini deleted file mode 100644 index 9930887f2..000000000 --- a/imgui.ini +++ /dev/null @@ -1,4 +0,0 @@ -[Window][Debug##Default] -Pos=60,60 -Size=400,400 - From 80d89c3753b8d605195a76669184675282c380dd Mon Sep 17 00:00:00 2001 From: HeliumAnt Date: Fri, 25 Jul 2025 00:12:28 +0200 Subject: [PATCH 2/2] Fix extra gamepad appearing at main menu - SDL3 changed handling for devices, meaning that reconnecting a device will never result in the same device id, so that's now meaningless. Device events now also return a joystick ID instead. --- Source/Managers/UInputMan.cpp | 38 ++++++++++++++++++----------------- Source/Managers/UInputMan.h | 3 ++- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/Source/Managers/UInputMan.cpp b/Source/Managers/UInputMan.cpp index accd9694f..3b5af044f 100644 --- a/Source/Managers/UInputMan.cpp +++ b/Source/Managers/UInputMan.cpp @@ -1,8 +1,5 @@ #include "UInputMan.h" #include "Constants.h" -#include "SDL3/SDL_events.h" -#include "SDL3/SDL_keyboard.h" -#include "SDL3/SDL_mouse.h" #include "SceneMan.h" #include "ActivityMan.h" #include "MetaMan.h" @@ -14,6 +11,7 @@ #include "Icon.h" #include "GameActivity.h" #include "System.h" + #include #include #include @@ -82,7 +80,7 @@ int UInputMan::Initialize() { int controllerIndex = 0; int joystickCount = 0; - SDL_JoystickID* joysticks = SDL_GetJoysticks(&joystickCount); + SDL_JoystickID* joysticks = SDL_GetGamepads(&joystickCount); for (size_t index = 0; index < std::min(joystickCount, static_cast(Players::MaxPlayerCount)); ++index) { if (SDL_IsGamepad(joysticks[index])) { @@ -997,11 +995,12 @@ int UInputMan::Update() { } } break; - case SDL_EVENT_GAMEPAD_BUTTON_DOWN: - case SDL_EVENT_GAMEPAD_BUTTON_UP: case SDL_EVENT_JOYSTICK_BUTTON_DOWN: case SDL_EVENT_JOYSTICK_BUTTON_UP: - if (std::vector::iterator device = std::find(s_PrevJoystickStates.begin(), s_PrevJoystickStates.end(), (inputEvent.type == SDL_EVENT_GAMEPAD_BUTTON_DOWN || inputEvent.type == SDL_EVENT_GAMEPAD_BUTTON_UP) ? inputEvent.gbutton.which : inputEvent.jbutton.which); device != s_PrevJoystickStates.end()) { + case SDL_EVENT_GAMEPAD_BUTTON_DOWN: + case SDL_EVENT_GAMEPAD_BUTTON_UP: { + bool joystickEvent = (inputEvent.type == SDL_EVENT_JOYSTICK_BUTTON_DOWN || inputEvent.type == SDL_EVENT_JOYSTICK_BUTTON_UP); + if (std::vector::iterator device = std::find(s_PrevJoystickStates.begin(), s_PrevJoystickStates.end(), joystickEvent ? inputEvent.jbutton.which : inputEvent.gbutton.which); device != s_PrevJoystickStates.end()) { int button = -1; int down = false; if (SDL_IsGamepad(device->m_DeviceIndex)) { @@ -1020,10 +1019,14 @@ int UInputMan::Update() { device->m_Buttons[button] = down; } break; + } case SDL_EVENT_JOYSTICK_ADDED: + case SDL_EVENT_GAMEPAD_ADDED: { HandleGamepadHotPlug(inputEvent.jdevice.which); break; + } case SDL_EVENT_JOYSTICK_REMOVED: + case SDL_EVENT_GAMEPAD_REMOVED: if (std::vector::iterator prevDevice = std::find(s_PrevJoystickStates.begin(), s_PrevJoystickStates.end(), inputEvent.jdevice.which); prevDevice != s_PrevJoystickStates.end()) { g_ConsoleMan.PrintString("INFO: Gamepad " + std::to_string(prevDevice->m_DeviceIndex + 1) + " disconnected!"); SDL_CloseGamepad(SDL_GetGamepadFromID(prevDevice->m_JoystickID)); @@ -1281,17 +1284,19 @@ void UInputMan::UpdateJoystickDigitalAxis() { } } -void UInputMan::HandleGamepadHotPlug(int deviceIndex) { +void UInputMan::HandleGamepadHotPlug(SDL_JoystickID deviceIndex) { SDL_Joystick* controller = nullptr; int controllerIndex = 0; for (controllerIndex = 0; controllerIndex < s_PrevJoystickStates.size(); ++controllerIndex) { - if (s_PrevJoystickStates[controllerIndex].m_DeviceIndex == deviceIndex || s_PrevJoystickStates[controllerIndex].m_DeviceIndex == -1) { + if (s_PrevJoystickStates[controllerIndex].m_JoystickID == deviceIndex) { + return; + } + if (s_PrevJoystickStates[controllerIndex].m_JoystickID == -1) { if (SDL_IsGamepad(deviceIndex)) { SDL_Gamepad* gameController = SDL_OpenGamepad(deviceIndex); if (!gameController) { - std::string connectString = s_PrevJoystickStates[controllerIndex].m_DeviceIndex == deviceIndex ? "reconnect" : "connect"; - g_ConsoleMan.PrintString("ERROR: Failed to " + connectString + " Gamepad " + std::to_string(controllerIndex + 1)); + g_ConsoleMan.PrintString("ERROR: Failed to connect Gamepad!"); break; } controller = SDL_GetGamepadJoystick(gameController); @@ -1300,12 +1305,10 @@ void UInputMan::HandleGamepadHotPlug(int deviceIndex) { controller = SDL_OpenJoystick(deviceIndex); } if (!controller) { - std::string connectString = s_PrevJoystickStates[controllerIndex].m_DeviceIndex == deviceIndex ? "reconnect" : "connect"; - g_ConsoleMan.PrintString("ERROR: Failed to " + connectString + " Gamepad " + std::to_string(controllerIndex + 1)); + g_ConsoleMan.PrintString("ERROR: Failed to connect Gamepad!"); break; } - std::string connectString = s_PrevJoystickStates[controllerIndex].m_DeviceIndex == deviceIndex ? " reconnected" : " connected"; - g_ConsoleMan.PrintString("INFO: Gamepad " + std::to_string(controllerIndex + 1) + connectString); + g_ConsoleMan.PrintString("INFO: Gamepad " + std::to_string(controllerIndex + 1) + "connected."); break; } } @@ -1315,7 +1318,6 @@ void UInputMan::HandleGamepadHotPlug(int deviceIndex) { } if (controller) { - SDL_JoystickID id = SDL_GetJoystickID(controller); int numAxis = 0; int numButtons = 0; if (SDL_IsGamepad(deviceIndex)) { @@ -1325,8 +1327,8 @@ void UInputMan::HandleGamepadHotPlug(int deviceIndex) { numAxis = SDL_GetNumJoystickAxes(controller); numButtons = SDL_GetNumJoystickButtons(controller); } - s_PrevJoystickStates[controllerIndex] = Gamepad(deviceIndex, id, numAxis, numButtons); - s_ChangedJoystickStates[controllerIndex] = Gamepad(deviceIndex, id, numAxis, numButtons); + s_PrevJoystickStates[controllerIndex] = Gamepad(controllerIndex, deviceIndex, numAxis, numButtons); + s_ChangedJoystickStates[controllerIndex] = Gamepad(controllerIndex, deviceIndex, numAxis, numButtons); m_NumJoysticks++; } } diff --git a/Source/Managers/UInputMan.h b/Source/Managers/UInputMan.h index 3a66f0c47..39003d92c 100644 --- a/Source/Managers/UInputMan.h +++ b/Source/Managers/UInputMan.h @@ -1,6 +1,7 @@ #pragma once #include "Constants.h" +#include "SDL3/SDL_joystick.h" #include "SDL3/SDL_keycode.h" #include "SDL3/SDL_scancode.h" #include "Singleton.h" @@ -606,7 +607,7 @@ namespace RTE { /// Connect a joystick or gamepad device and add it to the joystick list if a slot is available (up to max player count). /// @param deviceIndex The device index (generated by the connected event or a value up to SDL_NumJoysticks()). - void HandleGamepadHotPlug(int deviceIndex); + void HandleGamepadHotPlug(SDL_JoystickID deviceIndex); #pragma endregion /// Clears all the member variables of this UInputMan, effectively resetting the members of this abstraction level only.