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.
This commit is contained in:
Hyper 2025-02-16 19:21:58 +00:00
parent c68b5247c7
commit 4a33883512
9 changed files with 43 additions and 24 deletions

View file

@ -3596,7 +3596,7 @@ static void SetTexture(GuestDevice* device, uint32_t index, GuestTexture* textur
auto isPlayStation = Config::ControllerIcons == EControllerIcons::PlayStation;
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)
texture = texture->patchedTexture.get();

View file

@ -174,17 +174,16 @@ static void SetControllerInputDevice(Controller* controller)
if (App::s_isLoading)
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_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_inputDeviceExplicit != controllerType)
{
hid::g_inputDeviceExplicit = controllerType;
LOGFN("Detected controller: {}", hid::GetInputDeviceName());
}
if (hid::g_hasChangedInputDevice)
LOGFN("Input Device: {}", hid::GetInputDeviceName());
}
static void SetControllerTimeOfDayLED(Controller& controller, bool isNight)
@ -244,14 +243,16 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
SetControllerInputDevice(controller);
}
controller->PollAxis();
if (!hid::g_hasChangedInputDevice)
controller->PollAxis();
}
else
{
SDL_ShowCursor(SDL_DISABLE);
SetControllerInputDevice(controller);
controller->Poll();
if (!hid::g_hasChangedInputDevice)
controller->Poll();
}
break;
@ -259,8 +260,17 @@ int HID_OnSDLEvent(void*, SDL_Event* event)
case SDL_KEYDOWN:
case SDL_KEYUP:
hid::g_inputDevice = hid::EInputDevice::Keyboard;
{
if (hid::g_inputDevice != hid::EInputDevice::Keyboard)
{
hid::g_inputDevice = hid::EInputDevice::Keyboard;
hid::g_hasChangedInputDevice = true;
LOGN("Input Device: Keyboard");
}
break;
}
case SDL_MOUSEMOTION:
case SDL_MOUSEBUTTONDOWN:
@ -331,6 +341,12 @@ uint32_t hid::GetState(uint32_t dwUserIndex, XAMINPUT_STATE* pState)
if (!g_activeController)
return ERROR_DEVICE_NOT_CONNECTED;
if (hid::g_hasChangedInputDevice)
{
hid::g_hasChangedInputDevice = false;
return ERROR_SUCCESS;
}
pState->Gamepad = g_activeController->state;
return ERROR_SUCCESS;

View file

@ -2,9 +2,10 @@
#include <ui/game_window.h>
#include <user/config.h>
hid::EInputDevice hid::g_inputDevice;
hid::EInputDevice hid::g_inputDeviceController;
hid::EInputDeviceExplicit hid::g_inputDeviceExplicit;
hid::EInputDevice hid::g_inputDevice = EInputDevice::None;
hid::EInputDevice hid::g_inputDevicePad = EInputDevice::None;
hid::EInputDeviceExplicit hid::g_inputDevicePadExplicit = EInputDeviceExplicit::Unknown;
bool hid::g_hasChangedInputDevice;
uint16_t hid::g_prohibitedButtons;
bool hid::g_isLeftStickProhibited;
@ -39,7 +40,7 @@ std::string hid::GetInputDeviceName()
return "Mouse";
}
switch (g_inputDeviceExplicit)
switch (g_inputDevicePadExplicit)
{
case EInputDeviceExplicit::Xbox360:
return "Xbox 360";

View file

@ -4,6 +4,7 @@ namespace hid
{
enum class EInputDevice
{
None,
Keyboard,
Mouse,
Xbox,
@ -29,8 +30,9 @@ namespace hid
};
extern EInputDevice g_inputDevice;
extern EInputDevice g_inputDeviceController;
extern EInputDeviceExplicit g_inputDeviceExplicit;
extern EInputDevice g_inputDevicePad;
extern EInputDeviceExplicit g_inputDevicePadExplicit;
extern bool g_hasChangedInputDevice;
extern uint16_t g_prohibitedButtons;
extern bool g_isLeftStickProhibited;

View file

@ -186,7 +186,7 @@ public:
case SDL_CONTROLLERTOUCHPADDOWN:
{
g_worldMapCursorParams = hid::g_inputDeviceExplicit == hid::EInputDeviceExplicit::DualSense
g_worldMapCursorParams = hid::g_inputDevicePadExplicit == hid::EInputDeviceExplicit::DualSense
? (WorldMapCursorParams)g_worldMapCursorParamsProspero
: (WorldMapCursorParams)g_worldMapCursorParamsOrbis;

View file

@ -80,7 +80,7 @@ PPC_FUNC(sub_82B14CC0)
auto isPlayStation = Config::ControllerIcons == EControllerIcons::PlayStation;
if (Config::ControllerIcons == EControllerIcons::Auto)
isPlayStation = hid::g_inputDeviceController == hid::EInputDevice::PlayStation;
isPlayStation = hid::g_inputDevicePad == hid::EInputDevice::PlayStation;
if (isPlayStation)
{

View file

@ -161,7 +161,7 @@ void LoadingScreenControllerMidAsmHook()
auto isPlayStation = Config::ControllerIcons == EControllerIcons::PlayStation;
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";

View file

@ -67,7 +67,7 @@ std::tuple<std::tuple<ImVec2, ImVec2>, GuestTexture*> GetButtonIcon(EButtonIcon
GuestTexture* texture;
auto isPlayStation = Config::ControllerIcons == EControllerIcons::Auto
? hid::g_inputDeviceController == hid::EInputDevice::PlayStation
? hid::g_inputDevicePad == hid::EInputDevice::PlayStation
: Config::ControllerIcons == EControllerIcons::PlayStation;
auto yOffsetCmn = isPlayStation ? 42 : 0;

View file

@ -185,7 +185,7 @@ GuestTexture* GetThumbnail(const IConfigDef* cfg)
bool isPlayStation = Config::ControllerIcons == EControllerIcons::PlayStation;
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();
}