Compare commits

...

1 Commits

Author SHA1 Message Date
Hyper 4a33883512 hid: implemented delay input for switching devices
This makes controllers have their first input ignored until after detection, much like other PC ports.

This probably won't end up being merged in though, as other Sonic PC ports don't seem to work this way, but I'll push it anyway just for the sake of having this somewhere.
2025-02-16 19:21:58 +00:00
9 changed files with 43 additions and 24 deletions
+1 -1
View File
@@ -3596,7 +3596,7 @@ static void SetTexture(GuestDevice* device, uint32_t index, GuestTexture* textur
auto isPlayStation = Config::ControllerIcons == EControllerIcons::PlayStation; auto isPlayStation = Config::ControllerIcons == EControllerIcons::PlayStation;
if (Config::ControllerIcons == EControllerIcons::Auto) if (Config::ControllerIcons == EControllerIcons::Auto)
isPlayStation = hid::g_inputDeviceController == hid::EInputDevice::PlayStation; isPlayStation = hid::g_inputDevicePad == hid::EInputDevice::PlayStation;
if (isPlayStation && texture != nullptr && texture->patchedTexture != nullptr) if (isPlayStation && texture != nullptr && texture->patchedTexture != nullptr)
texture = texture->patchedTexture.get(); texture = texture->patchedTexture.get();
+25 -9
View File
@@ -174,17 +174,16 @@ static void SetControllerInputDevice(Controller* controller)
if (App::s_isLoading) if (App::s_isLoading)
return; return;
// Signal that we've changed input device to block first input.
if (hid::g_inputDevice == hid::EInputDevice::Keyboard)
hid::g_hasChangedInputDevice = true;
hid::g_inputDevice = controller->GetInputDevice(); hid::g_inputDevice = controller->GetInputDevice();
hid::g_inputDeviceController = hid::g_inputDevice; hid::g_inputDevicePad = hid::g_inputDevice;
hid::g_inputDevicePadExplicit = (hid::EInputDeviceExplicit)controller->GetControllerType();
auto controllerType = (hid::EInputDeviceExplicit)controller->GetControllerType(); if (hid::g_hasChangedInputDevice)
LOGFN("Input Device: {}", hid::GetInputDeviceName());
if (hid::g_inputDeviceExplicit != controllerType)
{
hid::g_inputDeviceExplicit = controllerType;
LOGFN("Detected controller: {}", hid::GetInputDeviceName());
}
} }
static void SetControllerTimeOfDayLED(Controller& controller, bool isNight) static void SetControllerTimeOfDayLED(Controller& controller, bool isNight)
@@ -244,6 +243,7 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
SetControllerInputDevice(controller); SetControllerInputDevice(controller);
} }
if (!hid::g_hasChangedInputDevice)
controller->PollAxis(); controller->PollAxis();
} }
else else
@@ -251,6 +251,7 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
SDL_ShowCursor(SDL_DISABLE); SDL_ShowCursor(SDL_DISABLE);
SetControllerInputDevice(controller); SetControllerInputDevice(controller);
if (!hid::g_hasChangedInputDevice)
controller->Poll(); controller->Poll();
} }
@@ -259,8 +260,17 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
case SDL_KEYDOWN: case SDL_KEYDOWN:
case SDL_KEYUP: case SDL_KEYUP:
{
if (hid::g_inputDevice != hid::EInputDevice::Keyboard)
{
hid::g_inputDevice = hid::EInputDevice::Keyboard; hid::g_inputDevice = hid::EInputDevice::Keyboard;
hid::g_hasChangedInputDevice = true;
LOGN("Input Device: Keyboard");
}
break; break;
}
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONDOWN:
@@ -331,6 +341,12 @@ uint32_t hid::GetState(uint32_t dwUserIndex, XAMINPUT_STATE* pState)
if (!g_activeController) if (!g_activeController)
return ERROR_DEVICE_NOT_CONNECTED; return ERROR_DEVICE_NOT_CONNECTED;
if (hid::g_hasChangedInputDevice)
{
hid::g_hasChangedInputDevice = false;
return ERROR_SUCCESS;
}
pState->Gamepad = g_activeController->state; pState->Gamepad = g_activeController->state;
return ERROR_SUCCESS; return ERROR_SUCCESS;
+5 -4
View File
@@ -2,9 +2,10 @@
#include <ui/game_window.h> #include <ui/game_window.h>
#include <user/config.h> #include <user/config.h>
hid::EInputDevice hid::g_inputDevice; hid::EInputDevice hid::g_inputDevice = EInputDevice::None;
hid::EInputDevice hid::g_inputDeviceController; hid::EInputDevice hid::g_inputDevicePad = EInputDevice::None;
hid::EInputDeviceExplicit hid::g_inputDeviceExplicit; hid::EInputDeviceExplicit hid::g_inputDevicePadExplicit = EInputDeviceExplicit::Unknown;
bool hid::g_hasChangedInputDevice;
uint16_t hid::g_prohibitedButtons; uint16_t hid::g_prohibitedButtons;
bool hid::g_isLeftStickProhibited; bool hid::g_isLeftStickProhibited;
@@ -39,7 +40,7 @@ std::string hid::GetInputDeviceName()
return "Mouse"; return "Mouse";
} }
switch (g_inputDeviceExplicit) switch (g_inputDevicePadExplicit)
{ {
case EInputDeviceExplicit::Xbox360: case EInputDeviceExplicit::Xbox360:
return "Xbox 360"; return "Xbox 360";
+4 -2
View File
@@ -4,6 +4,7 @@ namespace hid
{ {
enum class EInputDevice enum class EInputDevice
{ {
None,
Keyboard, Keyboard,
Mouse, Mouse,
Xbox, Xbox,
@@ -29,8 +30,9 @@ namespace hid
}; };
extern EInputDevice g_inputDevice; extern EInputDevice g_inputDevice;
extern EInputDevice g_inputDeviceController; extern EInputDevice g_inputDevicePad;
extern EInputDeviceExplicit g_inputDeviceExplicit; extern EInputDeviceExplicit g_inputDevicePadExplicit;
extern bool g_hasChangedInputDevice;
extern uint16_t g_prohibitedButtons; extern uint16_t g_prohibitedButtons;
extern bool g_isLeftStickProhibited; extern bool g_isLeftStickProhibited;
+1 -1
View File
@@ -186,7 +186,7 @@ public:
case SDL_CONTROLLERTOUCHPADDOWN: case SDL_CONTROLLERTOUCHPADDOWN:
{ {
g_worldMapCursorParams = hid::g_inputDeviceExplicit == hid::EInputDeviceExplicit::DualSense g_worldMapCursorParams = hid::g_inputDevicePadExplicit == hid::EInputDeviceExplicit::DualSense
? (WorldMapCursorParams)g_worldMapCursorParamsProspero ? (WorldMapCursorParams)g_worldMapCursorParamsProspero
: (WorldMapCursorParams)g_worldMapCursorParamsOrbis; : (WorldMapCursorParams)g_worldMapCursorParamsOrbis;
+1 -1
View File
@@ -80,7 +80,7 @@ PPC_FUNC(sub_82B14CC0)
auto isPlayStation = Config::ControllerIcons == EControllerIcons::PlayStation; auto isPlayStation = Config::ControllerIcons == EControllerIcons::PlayStation;
if (Config::ControllerIcons == EControllerIcons::Auto) if (Config::ControllerIcons == EControllerIcons::Auto)
isPlayStation = hid::g_inputDeviceController == hid::EInputDevice::PlayStation; isPlayStation = hid::g_inputDevicePad == hid::EInputDevice::PlayStation;
if (isPlayStation) if (isPlayStation)
{ {
+1 -1
View File
@@ -161,7 +161,7 @@ void LoadingScreenControllerMidAsmHook()
auto isPlayStation = Config::ControllerIcons == EControllerIcons::PlayStation; auto isPlayStation = Config::ControllerIcons == EControllerIcons::PlayStation;
if (Config::ControllerIcons == EControllerIcons::Auto) if (Config::ControllerIcons == EControllerIcons::Auto)
isPlayStation = hid::g_inputDeviceController == hid::EInputDevice::PlayStation; isPlayStation = hid::g_inputDevicePad == hid::EInputDevice::PlayStation;
const char* prefix = isPlayStation ? "ps3" : "360"; const char* prefix = isPlayStation ? "ps3" : "360";
+1 -1
View File
@@ -67,7 +67,7 @@ std::tuple<std::tuple<ImVec2, ImVec2>, GuestTexture*> GetButtonIcon(EButtonIcon
GuestTexture* texture; GuestTexture* texture;
auto isPlayStation = Config::ControllerIcons == EControllerIcons::Auto auto isPlayStation = Config::ControllerIcons == EControllerIcons::Auto
? hid::g_inputDeviceController == hid::EInputDevice::PlayStation ? hid::g_inputDevicePad == hid::EInputDevice::PlayStation
: Config::ControllerIcons == EControllerIcons::PlayStation; : Config::ControllerIcons == EControllerIcons::PlayStation;
auto yOffsetCmn = isPlayStation ? 42 : 0; auto yOffsetCmn = isPlayStation ? 42 : 0;
@@ -185,7 +185,7 @@ GuestTexture* GetThumbnail(const IConfigDef* cfg)
bool isPlayStation = Config::ControllerIcons == EControllerIcons::PlayStation; bool isPlayStation = Config::ControllerIcons == EControllerIcons::PlayStation;
if (Config::ControllerIcons == EControllerIcons::Auto) if (Config::ControllerIcons == EControllerIcons::Auto)
isPlayStation = hid::g_inputDeviceController == hid::EInputDevice::PlayStation; isPlayStation = hid::g_inputDevicePad == hid::EInputDevice::PlayStation;
texture = isPlayStation ? g_namedThumbnails["ControlTutorialPS"].get() : g_namedThumbnails["ControlTutorialXB"].get(); texture = isPlayStation ? g_namedThumbnails["ControlTutorialPS"].get() : g_namedThumbnails["ControlTutorialXB"].get();
} }