Frontend: Add pause support
This commit is contained in:
parent
4e6596adfb
commit
21f555cf8f
|
@ -31,7 +31,5 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
std::unique_ptr<AudioStream> m_audio_stream;
|
std::unique_ptr<AudioStream> m_audio_stream;
|
||||||
|
|
||||||
std::unique_ptr<System> m_system;
|
std::unique_ptr<System> m_system;
|
||||||
bool m_running = true;
|
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,6 +11,8 @@ struct Settings
|
||||||
{
|
{
|
||||||
Settings();
|
Settings();
|
||||||
|
|
||||||
|
bool start_paused = false;
|
||||||
|
|
||||||
GPURenderer gpu_renderer = GPURenderer::HardwareOpenGL;
|
GPURenderer gpu_renderer = GPURenderer::HardwareOpenGL;
|
||||||
u32 gpu_resolution_scale = 1;
|
u32 gpu_resolution_scale = 1;
|
||||||
u32 max_gpu_resolution_scale = 1;
|
u32 max_gpu_resolution_scale = 1;
|
||||||
|
|
|
@ -264,6 +264,7 @@ bool SDLInterface::InitializeSystem(const char* filename, const char* exp1_filen
|
||||||
|
|
||||||
ConnectDevices();
|
ConnectDevices();
|
||||||
UpdateAudioVisualSync();
|
UpdateAudioVisualSync();
|
||||||
|
m_paused = m_system->GetSettings().start_paused;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,7 +483,7 @@ void SDLInterface::HandleSDLEvent(const SDL_Event* event)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_QUIT:
|
case SDL_QUIT:
|
||||||
m_running = false;
|
m_quit_request = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SDL_KEYDOWN:
|
case SDL_KEYDOWN:
|
||||||
|
@ -577,6 +578,13 @@ void SDLInterface::HandleSDLKeyEvent(const SDL_Event* event)
|
||||||
UpdateAudioVisualSync();
|
UpdateAudioVisualSync();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case SDL_SCANCODE_SPACE:
|
||||||
|
{
|
||||||
|
if (pressed)
|
||||||
|
DoTogglePause();
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -697,16 +705,16 @@ void SDLInterface::DrawMainMenuBar()
|
||||||
|
|
||||||
if (ImGui::BeginMenu("System"))
|
if (ImGui::BeginMenu("System"))
|
||||||
{
|
{
|
||||||
if (ImGui::MenuItem("Reset", nullptr, false, system_enabled))
|
|
||||||
DoReset();
|
|
||||||
|
|
||||||
ImGui::MenuItem("Change Disc", nullptr, false, system_enabled);
|
|
||||||
|
|
||||||
if (ImGui::MenuItem("Power Off", nullptr, false, system_enabled))
|
if (ImGui::MenuItem("Power Off", nullptr, false, system_enabled))
|
||||||
DoPowerOff();
|
DoPowerOff();
|
||||||
|
|
||||||
if (ImGui::MenuItem("Enable Speed Limiter", nullptr, &m_speed_limiter_enabled, system_enabled))
|
if (ImGui::MenuItem("Reset", nullptr, false, system_enabled))
|
||||||
UpdateAudioVisualSync();
|
DoReset();
|
||||||
|
|
||||||
|
if (ImGui::MenuItem("Pause", nullptr, m_paused, system_enabled))
|
||||||
|
DoTogglePause();
|
||||||
|
|
||||||
|
ImGui::MenuItem("Change Disc", nullptr, false, system_enabled);
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
|
@ -740,13 +748,18 @@ void SDLInterface::DrawMainMenuBar()
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
|
||||||
if (ImGui::MenuItem("Exit"))
|
if (ImGui::MenuItem("Exit"))
|
||||||
m_running = false;
|
m_quit_request = true;
|
||||||
|
|
||||||
ImGui::EndMenu();
|
ImGui::EndMenu();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::BeginMenu("Settings"))
|
if (ImGui::BeginMenu("Settings"))
|
||||||
{
|
{
|
||||||
|
if (ImGui::MenuItem("Enable Speed Limiter", nullptr, &m_speed_limiter_enabled, system_enabled))
|
||||||
|
UpdateAudioVisualSync();
|
||||||
|
|
||||||
|
ImGui::Separator();
|
||||||
|
|
||||||
if (ImGui::MenuItem("Fullscreen", nullptr, IsWindowFullscreen()))
|
if (ImGui::MenuItem("Fullscreen", nullptr, IsWindowFullscreen()))
|
||||||
SDL_SetWindowFullscreen(m_window, IsWindowFullscreen() ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
|
SDL_SetWindowFullscreen(m_window, IsWindowFullscreen() ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||||
|
|
||||||
|
@ -821,6 +834,8 @@ void SDLInterface::DrawMainMenuBar()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_system)
|
if (m_system)
|
||||||
|
{
|
||||||
|
if (!m_paused)
|
||||||
{
|
{
|
||||||
ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - 210.0f);
|
ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - 210.0f);
|
||||||
|
|
||||||
|
@ -838,6 +853,12 @@ void SDLInterface::DrawMainMenuBar()
|
||||||
ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - 80.0f);
|
ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - 80.0f);
|
||||||
ImGui::Text("VPS: %.2f", m_vps);
|
ImGui::Text("VPS: %.2f", m_vps);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ImGui::SetCursorPosX(ImGui::GetIO().DisplaySize.x - 50.0f);
|
||||||
|
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "Paused");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::EndMainMenuBar();
|
ImGui::EndMainMenuBar();
|
||||||
}
|
}
|
||||||
|
@ -909,7 +930,7 @@ void SDLInterface::DrawPoweredOffWindow()
|
||||||
|
|
||||||
ImGui::SetCursorPosX(button_left);
|
ImGui::SetCursorPosX(button_left);
|
||||||
if (ImGui::Button("Exit", button_size))
|
if (ImGui::Button("Exit", button_size))
|
||||||
m_running = false;
|
m_quit_request = true;
|
||||||
|
|
||||||
ImGui::NewLine();
|
ImGui::NewLine();
|
||||||
|
|
||||||
|
@ -1077,6 +1098,7 @@ void SDLInterface::DoPowerOff()
|
||||||
Assert(m_system);
|
Assert(m_system);
|
||||||
|
|
||||||
m_system.reset();
|
m_system.reset();
|
||||||
|
m_paused = false;
|
||||||
m_display_texture = nullptr;
|
m_display_texture = nullptr;
|
||||||
AddOSDMessage("System powered off.");
|
AddOSDMessage("System powered off.");
|
||||||
UpdateAudioVisualSync();
|
UpdateAudioVisualSync();
|
||||||
|
@ -1130,11 +1152,18 @@ void SDLInterface::DoSaveState(u32 index)
|
||||||
ClearImGuiFocus();
|
ClearImGuiFocus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SDLInterface::DoTogglePause()
|
||||||
|
{
|
||||||
|
m_paused = !m_paused;
|
||||||
|
if (!m_paused)
|
||||||
|
m_fps_timer.Reset();
|
||||||
|
}
|
||||||
|
|
||||||
void SDLInterface::Run()
|
void SDLInterface::Run()
|
||||||
{
|
{
|
||||||
m_audio_stream->PauseOutput(false);
|
m_audio_stream->PauseOutput(false);
|
||||||
|
|
||||||
while (m_running)
|
while (!m_quit_request)
|
||||||
{
|
{
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
|
@ -1145,7 +1174,7 @@ void SDLInterface::Run()
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_system)
|
if (m_system && !m_paused)
|
||||||
m_system->RunFrame();
|
m_system->RunFrame();
|
||||||
|
|
||||||
Render();
|
Render();
|
||||||
|
|
|
@ -72,6 +72,7 @@ private:
|
||||||
void DoStartBIOS();
|
void DoStartBIOS();
|
||||||
void DoLoadState(u32 index);
|
void DoLoadState(u32 index);
|
||||||
void DoSaveState(u32 index);
|
void DoSaveState(u32 index);
|
||||||
|
void DoTogglePause();
|
||||||
|
|
||||||
void HandleSDLEvent(const SDL_Event* event);
|
void HandleSDLEvent(const SDL_Event* event);
|
||||||
void HandleSDLKeyEvent(const SDL_Event* event);
|
void HandleSDLKeyEvent(const SDL_Event* event);
|
||||||
|
@ -120,6 +121,8 @@ private:
|
||||||
u32 m_last_global_tick_counter = 0;
|
u32 m_last_global_tick_counter = 0;
|
||||||
Timer m_fps_timer;
|
Timer m_fps_timer;
|
||||||
|
|
||||||
|
bool m_paused = false;
|
||||||
|
bool m_quit_request = false;
|
||||||
bool m_focus_main_menu_bar = false;
|
bool m_focus_main_menu_bar = false;
|
||||||
bool m_about_window_open = false;
|
bool m_about_window_open = false;
|
||||||
bool m_speed_limiter_enabled = true;
|
bool m_speed_limiter_enabled = true;
|
||||||
|
|
Loading…
Reference in New Issue