mirror of
https://github.com/mattrberry/crab.git
synced 2025-02-06 08:45:53 +01:00
abstract pause logic and interaction with vsync
This commit is contained in:
parent
e9a403fcf6
commit
bf1154945b
1 changed files with 14 additions and 12 deletions
|
@ -47,7 +47,7 @@ class SDLOpenGLImGuiFrontend < Frontend
|
|||
LibGL.use_program(@shader_programs[@controller.class])
|
||||
@opengl_info = OpenGLInfo.new
|
||||
@io = setup_imgui
|
||||
LibSDL.gl_set_swap_interval(1) if stubbed?
|
||||
pause(true) if stubbed?
|
||||
|
||||
@file_explorer = ImGui::FileExplorer.new
|
||||
@keybindings = ImGui::Keybindings.new
|
||||
|
@ -67,6 +67,13 @@ class SDLOpenGLImGuiFrontend < Frontend
|
|||
end
|
||||
end
|
||||
|
||||
def pause(b : Bool) : Nil
|
||||
if @pause != b
|
||||
@pause = b
|
||||
LibSDL.gl_set_swap_interval(@pause.to_unsafe)
|
||||
end
|
||||
end
|
||||
|
||||
private def handle_file_selection : Nil
|
||||
if selection = @file_explorer.selection
|
||||
file, symbol = selection
|
||||
|
@ -95,9 +102,7 @@ class SDLOpenGLImGuiFrontend < Frontend
|
|||
LibGL.viewport(0, 0, @window.width, @window.height)
|
||||
LibGL.use_program(@shader_programs[@controller.class])
|
||||
|
||||
LibSDL.gl_set_swap_interval(0)
|
||||
@enable_overlay = false
|
||||
@pause = false
|
||||
pause(false)
|
||||
end
|
||||
|
||||
private def load_new_bios(bios : String) : Nil
|
||||
|
@ -125,10 +130,7 @@ class SDLOpenGLImGuiFrontend < Frontend
|
|||
elsif event.sym == LibSDL::Keycode::Q && event.mod.includes?(LibSDL::Keymod::LCTRL)
|
||||
exit
|
||||
elsif event.sym == LibSDL::Keycode::P && event.mod.includes?(LibSDL::Keymod::LCTRL)
|
||||
unless event.pressed? # pause on key release
|
||||
@pause = !@pause
|
||||
LibSDL.gl_set_swap_interval(@pause.to_unsafe)
|
||||
end
|
||||
pause(!@pause) unless event.pressed? # toggle pause on key release
|
||||
end
|
||||
when SDL::Event::JoyHat,
|
||||
SDL::Event::JoyButton then @controller.handle_controller_event(event)
|
||||
|
@ -191,12 +193,12 @@ class SDLOpenGLImGuiFrontend < Frontend
|
|||
end
|
||||
|
||||
if ImGui.begin_menu "Emulation"
|
||||
previously_paused = @pause
|
||||
pause = @pause
|
||||
|
||||
ImGui.menu_item "Pause", "Ctrl+P", pointerof(@pause)
|
||||
@controller.toggle_sync if ImGui.menu_item "Audio Sync", selected: @controller.sync?, enabled: !stubbed?
|
||||
ImGui.menu_item "Pause", "Ctrl+P", pointerof(pause)
|
||||
@controller.toggle_sync if ImGui.menu_item "Audio Sync", "Tab", @controller.sync?, !stubbed?
|
||||
|
||||
LibSDL.gl_set_swap_interval(@pause.to_unsafe) if previously_paused ^ @pause
|
||||
pause(pause)
|
||||
ImGui.end_menu
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue