Skip to content

Commit 612b35e

Browse files
committed
fix: cap evshim's vjoy count to currently-connected controllers
EVSHIM_MAX_PLAYERS was hardcoded to WinHandler.MAX_PLAYERS (=4), so evshim always registered four SDL virtual joysticks regardless of how many physical controllers were actually connected. Games (ToS, etc.) would see one or more phantom unbound gamepads — they didn't respond to input because no slot had a controller, and rumble routed at them went nowhere because getControllerForSlot returned null. Cap to controllerManager.getDetectedDevices().size() with a floor of 1 so the virtual on-screen gamepad still has a vjoy when no physical controller is present at launch. Mem files for all four slots are still pre-created; only the SDL vjoy registration is bounded.
1 parent e9c0046 commit 612b35e

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

app/src/main/java/com/winlator/xenvironment/components/BionicProgramLauncherComponent.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,7 @@ private int execGuestProgram() {
182182

183183
// Always pre-create all 4 mem files so controllers can be hot-plugged during gameplay.
184184
// Unused gamepads just read zeroes (no-op in evshim).
185-
final int enabledPlayerCount = WinHandler.MAX_PLAYERS;
186-
for (int i = 0; i < enabledPlayerCount; i++) {
185+
for (int i = 0; i < WinHandler.MAX_PLAYERS; i++) {
187186
String memPath;
188187
if (i == 0) {
189188
// Player 1 uses the original, non-numbered path that is known to work.
@@ -224,7 +223,16 @@ private int execGuestProgram() {
224223

225224
EnvVars envVars = new EnvVars();
226225

227-
// Use the ControllerManager's dynamic count for the environment variable
226+
// Tell evshim how many SDL virtual joysticks to register, capped at the count of
227+
// currently-detected physical controllers. Without the cap we'd always spawn
228+
// MAX_PLAYERS vjoys regardless of how many were connected, and games (e.g. ToS
229+
// controller tester) would see phantom unbound gamepads — they don't respond to
230+
// input and rumble routed at them goes nowhere. Floor at 1 so the virtual
231+
// on-screen gamepad still has a vjoy when no physical controller is present.
232+
final int connectedControllerCount =
233+
com.winlator.inputcontrols.ControllerManager.getInstance().getDetectedDevices().size();
234+
final int enabledPlayerCount =
235+
Math.max(1, Math.min(connectedControllerCount, WinHandler.MAX_PLAYERS));
228236
envVars.put("EVSHIM_MAX_PLAYERS", String.valueOf(enabledPlayerCount));
229237
if (true) {
230238
envVars.put("EVSHIM_SHM_ID", 1);

0 commit comments

Comments
 (0)