From dc187324beded208b8aef77d2e5e0cc1650f4d78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Fri, 13 Aug 2021 00:38:41 +0200 Subject: Add input buffering framework Input buffering is implicitly used by event accumulation, but this commit makes it more generic so it can be enabled for other uses. For desktop OSs it's currently not feasible given main and UI threads are the same). --- main/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'main') diff --git a/main/main.cpp b/main/main.cpp index 7351dafa22..8cfcacbfe8 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -2587,6 +2587,11 @@ bool Main::iteration() { iterating--; + // Needed for OSs using input buffering regardless accumulation (like Android) + if (Input::get_singleton()->is_using_input_buffering()) { + Input::get_singleton()->flush_buffered_events(); + } + if (fixed_fps != -1) { return exit; } -- cgit v1.2.3 From abdfbef07516beae019643ba6cea000067b478cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pedro=20J=2E=20Est=C3=A9banez?= Date: Mon, 21 Sep 2020 01:35:20 +0200 Subject: Add project setting for agile input event flushing If enabled, key/touch/joystick events will be flushed just before every idle and physics frame. Enabling this can greatly improve the responsiveness to input, specially in devices that need to run multiple physics frames per each idle frame, because of not being powerful enough to run at the target frame rate. This will only work for platforms using input buffering (regardless event accumulation). Currenly, only Android does so, but could be implemented for iOS in an upcoming PR. --- main/main.cpp | 19 +++++++++++++++---- main/main.h | 1 + 2 files changed, 16 insertions(+), 4 deletions(-) (limited to 'main') diff --git a/main/main.cpp b/main/main.cpp index 8cfcacbfe8..6764332f16 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -1735,6 +1735,8 @@ Error Main::setup2(Thread::ID p_main_tid_override) { Input *id = Input::get_singleton(); if (id) { + agile_input_event_flushing = GLOBAL_DEF("input_devices/buffering/agile_event_flushing", false); + if (bool(GLOBAL_DEF("input_devices/pointing/emulate_touch_from_mouse", false)) && !(editor || project_manager)) { bool found_touchscreen = false; @@ -2442,6 +2444,7 @@ uint32_t Main::frames = 0; uint32_t Main::frame = 0; bool Main::force_redraw_requested = false; int Main::iterating = 0; +bool Main::agile_input_event_flushing = false; bool Main::is_iterating() { return iterating > 0; @@ -2491,9 +2494,13 @@ bool Main::iteration() { bool exit = false; - Engine::get_singleton()->_in_physics = true; - for (int iters = 0; iters < advance.physics_steps; ++iters) { + if (Input::get_singleton()->is_using_input_buffering() && agile_input_event_flushing) { + Input::get_singleton()->flush_buffered_events(); + } + + Engine::get_singleton()->_in_physics = true; + uint64_t physics_begin = OS::get_singleton()->get_ticks_usec(); PhysicsServer3D::get_singleton()->sync(); @@ -2522,9 +2529,13 @@ bool Main::iteration() { physics_process_ticks = MAX(physics_process_ticks, OS::get_singleton()->get_ticks_usec() - physics_begin); // keep the largest one for reference physics_process_max = MAX(OS::get_singleton()->get_ticks_usec() - physics_begin, physics_process_max); Engine::get_singleton()->_physics_frames++; + + Engine::get_singleton()->_in_physics = false; } - Engine::get_singleton()->_in_physics = false; + if (Input::get_singleton()->is_using_input_buffering() && agile_input_event_flushing) { + Input::get_singleton()->flush_buffered_events(); + } uint64_t process_begin = OS::get_singleton()->get_ticks_usec(); @@ -2588,7 +2599,7 @@ bool Main::iteration() { iterating--; // Needed for OSs using input buffering regardless accumulation (like Android) - if (Input::get_singleton()->is_using_input_buffering()) { + if (Input::get_singleton()->is_using_input_buffering() && !agile_input_event_flushing) { Input::get_singleton()->flush_buffered_events(); } diff --git a/main/main.h b/main/main.h index 84077137ba..4911ff42b4 100644 --- a/main/main.h +++ b/main/main.h @@ -42,6 +42,7 @@ class Main { static uint32_t frame; static bool force_redraw_requested; static int iterating; + static bool agile_input_event_flushing; public: static bool is_project_manager(); -- cgit v1.2.3