From fc4edad3915758736766782d55da6b7345c4b555 Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Tue, 24 Nov 2026 18:41:19 -0700 Subject: [PATCH] ESP32: a gamepad jump is as high as a keyboard one; face buttons do one thing each tab5-emu sends the USB gamepad's face buttons to JK as keys (A = space, B = x, X = c, Y = enter: activate, jump, crouch, use item) and, through jk_esp_input_t.buttons, also as joystick buttons B1-B4, which the homebrew default binds map to fire, duck, activate and jump (profile binds are reset to those defaults on homebrew). So each button did two things. B jumped and ducked in the same frame, and sithPlayerActions_JumpWithVel gives a crouching jump 0.7x the speed: measured on the device, the player rose 0.095 against 0.1149 for the keyboard's X. A also fired, X also activated, and Y also jumped. In play, stdControl_ReadControls now takes the joystick buttons from jk_esp_input_t.joy_buttons, which leaves out the USB gamepad's a/b/x/y; the touch pad's buttons still go through. While one of JK's menus is open (jkGuiRend_ESP32_MenuActive), it still takes all of them: the menus use B1 as enter, B2 as back and B3 as the default button, and the binding screens read them too. The Select + X noclip combo still works from either pad. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SFCMzomCZ5wRHJN4sxwkvY --- src/Gui/jkGUIRend.c | 7 +++++++ src/Gui/jkGUIRend.h | 2 ++ src/Platform/ESP32/stdControl.c | 35 +++++++++++++++++++++------------ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/src/Gui/jkGUIRend.c b/src/Gui/jkGUIRend.c index 712ec6e0d..22ff185d6 100644 --- a/src/Gui/jkGUIRend.c +++ b/src/Gui/jkGUIRend.c @@ -50,6 +50,13 @@ void jkGuiRend_ESP32_CancelActiveMenu(void) // happens. Also set by a quit from outside the engine (Window_MessageLoop): // the same loops are what kept a quit at the main menu from returning. int jkGuiRend_ESP32_bCloseMenus = 0; + +// Added: whether one of JK's menus is open. Their input reads take every +// gamepad button as a joystick button (see Platform/ESP32/stdControl.c). +int jkGuiRend_ESP32_MenuActive(void) +{ + return jkGuiRend_activeMenu != NULL; +} #endif static tVBuffer* jkGuiRend_menuBuffer = NULL; static tVBuffer *jkGuiRend_texture_dword_8561E8 = NULL; diff --git a/src/Gui/jkGUIRend.h b/src/Gui/jkGUIRend.h index 2b9f3513d..78cf3c5ae 100644 --- a/src/Gui/jkGUIRend.h +++ b/src/Gui/jkGUIRend.h @@ -87,6 +87,8 @@ extern int32_t jkGuiRend_thing_four; #ifdef TARGET_ESP32 // tab5-emu: close the open modal menus for a pending GUI state switch or a quit (see jkGUIRend.c) extern int jkGuiRend_ESP32_bCloseMenus; +// tab5-emu: whether one of JK's menus is open +int jkGuiRend_ESP32_MenuActive(void); #endif void jkGuiRend_CopyVBuffer(jkGuiMenu *menu, rdRect *rect); diff --git a/src/Platform/ESP32/stdControl.c b/src/Platform/ESP32/stdControl.c index 381c26f56..1ce3b6f44 100644 --- a/src/Platform/ESP32/stdControl.c +++ b/src/Platform/ESP32/stdControl.c @@ -5,6 +5,7 @@ #include "stdPlatform.h" #include "Main/jkQuakeConsole.h" #include "Main/jkDev.h" +#include "Gui/jkGUIRend.h" #include "jk_esp.h" @@ -718,17 +719,25 @@ void stdControl_ReadControls() enum { KEY_A = 1<<0, KEY_B = 1<<1, KEY_SELECT = 1<<2, KEY_START = 1<<3, KEY_RIGHT = 1<<4, KEY_LEFT = 1<<5, KEY_UP = 1<<6, KEY_DOWN = 1<<7, KEY_R = 1<<8, KEY_L = 1<<9, KEY_X = 1<<10, KEY_Y = 1<<11 }; + // JK's menus take every gamepad button as a joystick button (B1 enter, B2 + // back, B3 the default button; the binding screens). In play the USB + // gamepad's A/B/X/Y already arrive as keys (jk_esp_read_input), so the + // joystick binds get the touch pad's only (joy_buttons): both at once + // doubled each action, and B (jump) plus B2 (duck) made a crouched jump. + const uint16_t buttons = jkGuiRend_ESP32_MenuActive() ? in.buttons : in.joy_buttons; uint16_t keys_held = 0; - if (in.buttons & (1<<0)) keys_held |= KEY_A; - if (in.buttons & (1<<1)) keys_held |= KEY_B; - if (in.buttons & (1<<2)) keys_held |= KEY_X; - if (in.buttons & (1<<3)) keys_held |= KEY_Y; - if (in.buttons & (1<<4)) keys_held |= KEY_SELECT; - if (in.buttons & (1<<5)) keys_held |= KEY_START; - if (in.buttons & (1<<6)) keys_held |= KEY_UP; - if (in.buttons & (1<<7)) keys_held |= KEY_DOWN; - if (in.buttons & (1<<8)) keys_held |= KEY_LEFT; - if (in.buttons & (1<<9)) keys_held |= KEY_RIGHT; + if (buttons & (1<<0)) keys_held |= KEY_A; + if (buttons & (1<<1)) keys_held |= KEY_B; + if (buttons & (1<<2)) keys_held |= KEY_X; + if (buttons & (1<<3)) keys_held |= KEY_Y; + if (buttons & (1<<4)) keys_held |= KEY_SELECT; + if (buttons & (1<<5)) keys_held |= KEY_START; + if (buttons & (1<<6)) keys_held |= KEY_UP; + if (buttons & (1<<7)) keys_held |= KEY_DOWN; + if (buttons & (1<<8)) keys_held |= KEY_LEFT; + if (buttons & (1<<9)) keys_held |= KEY_RIGHT; + // the Select + X noclip combo below works from either pad + const uint16_t keys_combo = ((in.buttons & (1<<2)) ? KEY_X : 0) | ((in.buttons & (1<<4)) ? KEY_SELECT : 0); static uint16_t keys_held_last = 0; //if((keys_held & KEY_UP)) rotateX += 3; //if((keys_held & KEY_DOWN)) rotateX -= 3; @@ -737,8 +746,8 @@ void stdControl_ReadControls() //if((keys & KEY_A)) fCamera -= 0.05f; //if((keys & KEY_B)) fCamera += 0.05f; - uint16_t keysPressed = keys_held & ~keys_held_last; - keys_held_last = keys_held; + uint16_t keysPressed = keys_combo & ~keys_held_last; + keys_held_last = keys_combo; //_memset(stdControl_aKeyIdleTimes, 0, sizeof(int) * JK_NUM_KEYS); stdControl_bControlsIdle = 1; @@ -825,7 +834,7 @@ void stdControl_ReadControls() //stdPlatform_Printf("total %u heap 0x%x 0x%x\n", sampleTime_roundtrip, (intptr_t)getHeapLimit() - (intptr_t)getHeapEnd(), (intptr_t)getHeapEnd() - (intptr_t)getHeapStart()); } //#ifdef DEBUG_QOL_CHEATS - if ((keysPressed & (KEY_X)) && (keys_held & KEY_SELECT)) { + if ((keysPressed & (KEY_X)) && (keys_combo & KEY_SELECT)) { jkDev_CmdNoclip(NULL, NULL); } //#endif