1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-09 12:50:35 +00:00

Web: Avoid unnecessary gamepad polling when no gamepads are connected

This commit is contained in:
Marcos Casagrande
2025-04-20 21:44:06 +02:00
parent 2d3bdcac35
commit 3e7e09f915
3 changed files with 13 additions and 3 deletions

View File

@@ -205,6 +205,7 @@ 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) {
@@ -224,8 +225,10 @@ const GodotInputGamepads = {
s.axes.push(pad.axes[a]);
}
samples.push(s);
active++;
}
GodotInputGamepads.samples = samples;
return active;
},
init: function (onchange) {
@@ -651,8 +654,7 @@ const GodotInput = {
godot_js_input_gamepad_sample__proxy: 'sync',
godot_js_input_gamepad_sample__sig: 'i',
godot_js_input_gamepad_sample: function () {
GodotInputGamepads.sample();
return 0;
return GodotInputGamepads.sample();
},
godot_js_input_gamepad_sample_get__proxy: 'sync',