Reduce update interval when inactive

This commit is contained in:
2021-12-03 15:32:55 -06:00
parent c1a497cd91
commit 451f92b9d6

View File

@@ -15,6 +15,9 @@ class W3DHub
I18n.locale = :en I18n.locale = :en
end end
@last_interaction = Gosu.milliseconds
@last_mouse_position = CyberarmEngine::Vector.new(mouse_x, mouse_y)
# push_state(W3DHub::States::DemoInputDelay) # push_state(W3DHub::States::DemoInputDelay)
push_state(W3DHub::States::Boot) push_state(W3DHub::States::Boot)
end end
@@ -23,6 +26,13 @@ class W3DHub
super super
Store.application_manager.start_next_available_task if Store.application_manager.idle? 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 end
def close def close
@@ -31,6 +41,19 @@ class W3DHub
super if Store.application_manager.idle? super if Store.application_manager.idle?
end 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 def main_thread_queue
if current_state.is_a?(W3DHub::States::Interface) if current_state.is_a?(W3DHub::States::Interface)
current_state.main_thread_queue current_state.main_thread_queue