From 722accc5c8c57f73ed38e1673754376f1a2d6182 Mon Sep 17 00:00:00 2001 From: Adam Scott Date: Thu, 26 Jun 2025 08:07:29 -0400 Subject: [PATCH] Revert "Web: Avoid unnecessary gamepad polling when no gamepads are connected" This reverts commit 3e7e09f9152288ced7d404b7f7b79e8de9ad165b. --- platform/web/display_server_web.cpp | 8 +------- platform/web/display_server_web.h | 2 -- platform/web/js/libs/library_godot_input.js | 6 ++---- 3 files changed, 3 insertions(+), 13 deletions(-) diff --git a/platform/web/display_server_web.cpp b/platform/web/display_server_web.cpp index 611f8bb6c4..50f3dcc423 100644 --- a/platform/web/display_server_web.cpp +++ b/platform/web/display_server_web.cpp @@ -830,9 +830,6 @@ void DisplayServerWeb::gamepad_callback(int p_index, int p_connected, const char void DisplayServerWeb::_gamepad_callback(int p_index, int p_connected, const String &p_id, const String &p_guid) { Input *input = Input::get_singleton(); - DisplayServerWeb *ds = get_singleton(); - ds->active_gamepad_sample_count = -1; // Invalidate cache - if (p_connected) { input->joy_connection_changed(p_index, true, p_id, p_guid); } else { @@ -1435,10 +1432,7 @@ DisplayServer::VSyncMode DisplayServerWeb::window_get_vsync_mode(WindowID p_vsyn void DisplayServerWeb::process_events() { process_keys(); Input::get_singleton()->flush_buffered_events(); - if (active_gamepad_sample_count == -1) { - active_gamepad_sample_count = godot_js_input_gamepad_sample(); - } - if (active_gamepad_sample_count > 0) { + if (godot_js_input_gamepad_sample() == OK) { process_joypads(); } } diff --git a/platform/web/display_server_web.h b/platform/web/display_server_web.h index a582f899d1..7c5d09fd35 100644 --- a/platform/web/display_server_web.h +++ b/platform/web/display_server_web.h @@ -104,8 +104,6 @@ private: bool swap_cancel_ok = false; NativeMenu *native_menu = nullptr; - int active_gamepad_sample_count = -1; - MouseMode mouse_mode_base = MOUSE_MODE_VISIBLE; MouseMode mouse_mode_override = MOUSE_MODE_VISIBLE; bool mouse_mode_override_enabled = false; diff --git a/platform/web/js/libs/library_godot_input.js b/platform/web/js/libs/library_godot_input.js index 1d1108ba9a..2ba60916ac 100644 --- a/platform/web/js/libs/library_godot_input.js +++ b/platform/web/js/libs/library_godot_input.js @@ -205,7 +205,6 @@ const GodotInputGamepads = { sample: function () { const pads = GodotInputGamepads.get_pads(); const samples = []; - let active = 0; for (let i = 0; i < pads.length; i++) { const pad = pads[i]; if (!pad) { @@ -225,10 +224,8 @@ const GodotInputGamepads = { s.axes.push(pad.axes[a]); } samples.push(s); - active++; } GodotInputGamepads.samples = samples; - return active; }, init: function (onchange) { @@ -662,7 +659,8 @@ const GodotInput = { godot_js_input_gamepad_sample__proxy: 'sync', godot_js_input_gamepad_sample__sig: 'i', godot_js_input_gamepad_sample: function () { - return GodotInputGamepads.sample(); + GodotInputGamepads.sample(); + return 0; }, godot_js_input_gamepad_sample_get__proxy: 'sync',