From 451f92b9d67c8dbf672159b33a778dcab5beb292 Mon Sep 17 00:00:00 2001 From: Cyberarm Date: Fri, 3 Dec 2021 15:32:55 -0600 Subject: [PATCH] Reduce update interval when inactive --- lib/window.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/lib/window.rb b/lib/window.rb index 9e41d20..87797ed 100644 --- a/lib/window.rb +++ b/lib/window.rb @@ -15,6 +15,9 @@ class W3DHub I18n.locale = :en end + @last_interaction = Gosu.milliseconds + @last_mouse_position = CyberarmEngine::Vector.new(mouse_x, mouse_y) + # push_state(W3DHub::States::DemoInputDelay) push_state(W3DHub::States::Boot) end @@ -23,6 +26,13 @@ class W3DHub super Store.application_manager.start_next_available_task if Store.application_manager.idle? + manage_update_interval + end + + def button_down(id) + super + + @last_interaction = Gosu.milliseconds end def close @@ -31,6 +41,19 @@ class W3DHub super if Store.application_manager.idle? end + def manage_update_interval + @last_interaction = Gosu.milliseconds if @last_mouse_position.x != mouse_x || @last_mouse_position.y != mouse_y + + self.update_interval = if Gosu.milliseconds - @last_interaction >= 1_000 + 1000.0 / 10 + else + 1000.0 / 60 + end + + @last_mouse_position.x = mouse_x + @last_mouse_position.y = mouse_y + end + def main_thread_queue if current_state.is_a?(W3DHub::States::Interface) current_state.main_thread_queue