mirror of
https://github.com/smartcmd/MinecraftConsoles.git
synced 2026-08-20 09:57:09 +00:00
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:
parent
bda3b1078a
commit
76a7d4102a
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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">
|
||||
|
|
|
|||
Loading…
Reference in a new issue