Fix gamepad hot-plug detection (controller connected after launch now works)

### Problem
Currently, the game checks `InputManager.IsPadConnected(0)` once at startup to determine whether a gamepad is available. If a controller is connected after the program has already started, this flag remains `false`, and the input system never switches to gamepad mode — even when buttons or sticks are used.

### Solution
Remove the static `IsPadConnected` check from the main input loop. Instead, directly evaluate whether any gamepad input (buttons or stick movements) is present. The underlying input functions (`ButtonPressed`, `GetJoypadStick_...`) safely return `false`/`0.0f` when no controller is connected. Once a gamepad is plugged in and the player uses it, `controllerUsed` becomes `true` and the input mode switches to gamepad as expected.

This change:
- Eliminates the need for runtime connection polling.
- Works with any controller that becomes available after launch.
- Simplifies the input‑mode logic.

### Testing
Verified that a gamepad connected after the game is running is immediately recognized as soon as a button is pressed. No regressions observed with keyboard/mouse input.
This commit is contained in:
NSDeathman 2026-03-09 17:50:21 +03:00
parent bda3b1078a
commit 76a7d4102a
4 changed files with 14 additions and 19 deletions

View file

@ -1,7 +1,7 @@
#pragma once
#define VER_PRODUCTBUILD 560
#define VER_PRODUCTVERSION_STR_W L"DEV (unknown version)"
#define VER_PRODUCTVERSION_STR_W L""
#define VER_FILEVERSION_STR_W VER_PRODUCTVERSION_STR_W
#define VER_BRANCHVERSION_STR_W L"UNKNOWN BRANCH"
#define VER_BRANCHVERSION_STR_W L"UNKNOWN/"
#define VER_NETWORK VER_PRODUCTBUILD

View file

@ -235,6 +235,7 @@
<SccProvider>SAK</SccProvider>
<Keyword>Xbox360Proj</Keyword>
<ApplicationEnvironment>title</ApplicationEnvironment>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Xbox 360'" Label="Configuration">
@ -309,7 +310,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64EC'" Label="Configuration">

View file

@ -1806,23 +1806,16 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
InputManager.Tick();
// Detect KBM vs controller input mode
if (InputManager.IsPadConnected(0))
{
const bool controllerUsed = InputManager.ButtonPressed(0) ||
InputManager.GetJoypadStick_LX(0, false) != 0.0f ||
InputManager.GetJoypadStick_LY(0, false) != 0.0f ||
InputManager.GetJoypadStick_RX(0, false) != 0.0f ||
InputManager.GetJoypadStick_RY(0, false) != 0.0f;
const bool controllerUsed = InputManager.ButtonPressed(0) ||
InputManager.GetJoypadStick_LX(0, false) != 0.0f ||
InputManager.GetJoypadStick_LY(0, false) != 0.0f ||
InputManager.GetJoypadStick_RX(0, false) != 0.0f ||
InputManager.GetJoypadStick_RY(0, false) != 0.0f;
if (controllerUsed)
g_KBMInput.SetKBMActive(false);
else if (g_KBMInput.HasAnyInput())
g_KBMInput.SetKBMActive(true);
}
else
{
if (controllerUsed)
g_KBMInput.SetKBMActive(false);
else if (g_KBMInput.HasAnyInput())
g_KBMInput.SetKBMActive(true);
}
if (!g_KBMInput.IsMouseGrabbed())
{

View file

@ -235,6 +235,7 @@
<SccLocalPath>SAK</SccLocalPath>
<SccProvider>SAK</SccProvider>
<ApplicationEnvironment>title</ApplicationEnvironment>
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Xbox 360'" Label="Configuration">
@ -306,7 +307,7 @@
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v143</PlatformToolset>
<PlatformToolset>v142</PlatformToolset>
<WholeProgramOptimization>true</WholeProgramOptimization>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|ARM64EC'" Label="Configuration">