You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-11 13:10:58 +00:00
Web: Avoid unnecessary gamepad polling when no gamepads are connected
This commit is contained in:
@@ -829,6 +829,9 @@ 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) {
|
void DisplayServerWeb::_gamepad_callback(int p_index, int p_connected, const String &p_id, const String &p_guid) {
|
||||||
Input *input = Input::get_singleton();
|
Input *input = Input::get_singleton();
|
||||||
|
DisplayServerWeb *ds = get_singleton();
|
||||||
|
ds->active_gamepad_sample_count = -1; // Invalidate cache
|
||||||
|
|
||||||
if (p_connected) {
|
if (p_connected) {
|
||||||
input->joy_connection_changed(p_index, true, p_id, p_guid);
|
input->joy_connection_changed(p_index, true, p_id, p_guid);
|
||||||
} else {
|
} else {
|
||||||
@@ -1406,7 +1409,10 @@ DisplayServer::VSyncMode DisplayServerWeb::window_get_vsync_mode(WindowID p_vsyn
|
|||||||
void DisplayServerWeb::process_events() {
|
void DisplayServerWeb::process_events() {
|
||||||
process_keys();
|
process_keys();
|
||||||
Input::get_singleton()->flush_buffered_events();
|
Input::get_singleton()->flush_buffered_events();
|
||||||
if (godot_js_input_gamepad_sample() == OK) {
|
if (active_gamepad_sample_count == -1) {
|
||||||
|
active_gamepad_sample_count = godot_js_input_gamepad_sample();
|
||||||
|
}
|
||||||
|
if (active_gamepad_sample_count > 0) {
|
||||||
process_joypads();
|
process_joypads();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -104,6 +104,8 @@ private:
|
|||||||
bool swap_cancel_ok = false;
|
bool swap_cancel_ok = false;
|
||||||
NativeMenu *native_menu = nullptr;
|
NativeMenu *native_menu = nullptr;
|
||||||
|
|
||||||
|
int active_gamepad_sample_count = -1;
|
||||||
|
|
||||||
MouseMode mouse_mode_base = MOUSE_MODE_VISIBLE;
|
MouseMode mouse_mode_base = MOUSE_MODE_VISIBLE;
|
||||||
MouseMode mouse_mode_override = MOUSE_MODE_VISIBLE;
|
MouseMode mouse_mode_override = MOUSE_MODE_VISIBLE;
|
||||||
bool mouse_mode_override_enabled = false;
|
bool mouse_mode_override_enabled = false;
|
||||||
|
|||||||
@@ -205,6 +205,7 @@ const GodotInputGamepads = {
|
|||||||
sample: function () {
|
sample: function () {
|
||||||
const pads = GodotInputGamepads.get_pads();
|
const pads = GodotInputGamepads.get_pads();
|
||||||
const samples = [];
|
const samples = [];
|
||||||
|
let active = 0;
|
||||||
for (let i = 0; i < pads.length; i++) {
|
for (let i = 0; i < pads.length; i++) {
|
||||||
const pad = pads[i];
|
const pad = pads[i];
|
||||||
if (!pad) {
|
if (!pad) {
|
||||||
@@ -224,8 +225,10 @@ const GodotInputGamepads = {
|
|||||||
s.axes.push(pad.axes[a]);
|
s.axes.push(pad.axes[a]);
|
||||||
}
|
}
|
||||||
samples.push(s);
|
samples.push(s);
|
||||||
|
active++;
|
||||||
}
|
}
|
||||||
GodotInputGamepads.samples = samples;
|
GodotInputGamepads.samples = samples;
|
||||||
|
return active;
|
||||||
},
|
},
|
||||||
|
|
||||||
init: function (onchange) {
|
init: function (onchange) {
|
||||||
@@ -651,8 +654,7 @@ const GodotInput = {
|
|||||||
godot_js_input_gamepad_sample__proxy: 'sync',
|
godot_js_input_gamepad_sample__proxy: 'sync',
|
||||||
godot_js_input_gamepad_sample__sig: 'i',
|
godot_js_input_gamepad_sample__sig: 'i',
|
||||||
godot_js_input_gamepad_sample: function () {
|
godot_js_input_gamepad_sample: function () {
|
||||||
GodotInputGamepads.sample();
|
return GodotInputGamepads.sample();
|
||||||
return 0;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
godot_js_input_gamepad_sample_get__proxy: 'sync',
|
godot_js_input_gamepad_sample_get__proxy: 'sync',
|
||||||
|
|||||||
Reference in New Issue
Block a user