Skip to content

Commit 722accc

Browse files
committed
Revert "Web: Avoid unnecessary gamepad polling when no gamepads are connected"
This reverts commit 3e7e09f.
1 parent 9a39760 commit 722accc

File tree

3 files changed

+3
-13
lines changed

3 files changed

+3
-13
lines changed

platform/web/display_server_web.cpp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -830,9 +830,6 @@ void DisplayServerWeb::gamepad_callback(int p_index, int p_connected, const char
830830

831831
void DisplayServerWeb::_gamepad_callback(int p_index, int p_connected, const String &p_id, const String &p_guid) {
832832
Input *input = Input::get_singleton();
833-
DisplayServerWeb *ds = get_singleton();
834-
ds->active_gamepad_sample_count = -1; // Invalidate cache
835-
836833
if (p_connected) {
837834
input->joy_connection_changed(p_index, true, p_id, p_guid);
838835
} else {
@@ -1435,10 +1432,7 @@ DisplayServer::VSyncMode DisplayServerWeb::window_get_vsync_mode(WindowID p_vsyn
14351432
void DisplayServerWeb::process_events() {
14361433
process_keys();
14371434
Input::get_singleton()->flush_buffered_events();
1438-
if (active_gamepad_sample_count == -1) {
1439-
active_gamepad_sample_count = godot_js_input_gamepad_sample();
1440-
}
1441-
if (active_gamepad_sample_count > 0) {
1435+
if (godot_js_input_gamepad_sample() == OK) {
14421436
process_joypads();
14431437
}
14441438
}

platform/web/display_server_web.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,6 @@ class DisplayServerWeb : public DisplayServer {
104104
bool swap_cancel_ok = false;
105105
NativeMenu *native_menu = nullptr;
106106

107-
int active_gamepad_sample_count = -1;
108-
109107
MouseMode mouse_mode_base = MOUSE_MODE_VISIBLE;
110108
MouseMode mouse_mode_override = MOUSE_MODE_VISIBLE;
111109
bool mouse_mode_override_enabled = false;

platform/web/js/libs/library_godot_input.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,6 @@ const GodotInputGamepads = {
205205
sample: function () {
206206
const pads = GodotInputGamepads.get_pads();
207207
const samples = [];
208-
let active = 0;
209208
for (let i = 0; i < pads.length; i++) {
210209
const pad = pads[i];
211210
if (!pad) {
@@ -225,10 +224,8 @@ const GodotInputGamepads = {
225224
s.axes.push(pad.axes[a]);
226225
}
227226
samples.push(s);
228-
active++;
229227
}
230228
GodotInputGamepads.samples = samples;
231-
return active;
232229
},
233230

234231
init: function (onchange) {
@@ -662,7 +659,8 @@ const GodotInput = {
662659
godot_js_input_gamepad_sample__proxy: 'sync',
663660
godot_js_input_gamepad_sample__sig: 'i',
664661
godot_js_input_gamepad_sample: function () {
665-
return GodotInputGamepads.sample();
662+
GodotInputGamepads.sample();
663+
return 0;
666664
},
667665

668666
godot_js_input_gamepad_sample_get__proxy: 'sync',

0 commit comments

Comments
 (0)