mirror of
https://github.com/cyberarm/w3d_hub_linux_launcher.git
synced 2025-12-16 09:12:35 +00:00
Use gosu's new Window#gain/lose_focus callbacks to reduce update interval when window is not focused
This commit is contained in:
@@ -15,9 +15,6 @@ 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
|
||||||
@@ -26,16 +23,17 @@ 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
|
|
||||||
|
|
||||||
current = Async::Task.current?
|
current = Async::Task.current?
|
||||||
current&.yield
|
current&.yield
|
||||||
end
|
end
|
||||||
|
|
||||||
def button_down(id)
|
def gain_focus
|
||||||
super
|
self.update_interval = 1000.0 / 60
|
||||||
|
end
|
||||||
|
|
||||||
@last_interaction = Gosu.milliseconds
|
def lose_focus
|
||||||
|
self.update_interval = 1000.0 / 10
|
||||||
end
|
end
|
||||||
|
|
||||||
def close
|
def close
|
||||||
@@ -56,22 +54,6 @@ class W3DHub
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def manage_update_interval
|
|
||||||
return # Wait for #gain/lose_focus callbacks to be merged into Gosu
|
|
||||||
|
|
||||||
@last_interaction = Gosu.milliseconds if @last_mouse_position.x != mouse_x || @last_mouse_position.y != mouse_y
|
|
||||||
@last_interaction = Gosu.milliseconds if mouse_x.between?(0, width) && mouse_y.between?(0, height)
|
|
||||||
|
|
||||||
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
|
||||||
|
|||||||
Reference in New Issue
Block a user