Settings: Add audio sync and additional cleanup

This commit is contained in:
Connor McLaughlin 2019-11-16 20:50:11 +10:00
parent 3673c6e33c
commit 8fb4f73d17
4 changed files with 56 additions and 22 deletions

View File

@ -206,11 +206,11 @@ void HostInterface::UpdateSpeedLimiterState()
{ {
m_speed_limiter_enabled = m_settings.speed_limiter_enabled && !m_speed_limiter_temp_disabled; m_speed_limiter_enabled = m_settings.speed_limiter_enabled && !m_speed_limiter_temp_disabled;
const bool audio_sync_enabled = !m_system || m_paused || m_speed_limiter_enabled; const bool audio_sync_enabled = !m_system || m_paused || (m_speed_limiter_enabled && m_settings.audio_sync_enabled);
const bool vsync_enabled = !m_system || m_paused || (m_speed_limiter_enabled && m_settings.gpu_vsync); const bool video_sync_enabled = !m_system || m_paused || (m_speed_limiter_enabled && m_settings.video_sync_enabled);
Log_InfoPrintf("Syncing to %s%s", audio_sync_enabled ? "audio" : "", Log_InfoPrintf("Syncing to %s%s", audio_sync_enabled ? "audio" : "",
(m_speed_limiter_enabled && vsync_enabled) ? " and video" : ""); (audio_sync_enabled && video_sync_enabled) ? " and video" : (video_sync_enabled ? "video" : ""));
m_audio_stream->SetSync(audio_sync_enabled); m_audio_stream->SetSync(audio_sync_enabled);
m_display->SetVSync(vsync_enabled); m_display->SetVSync(video_sync_enabled);
} }

View File

@ -13,9 +13,15 @@ Settings::Settings() = default;
void Settings::SetDefaults() void Settings::SetDefaults()
{ {
region = ConsoleRegion::Auto;
audio_sync_enabled = true;
video_sync_enabled = true;
speed_limiter_enabled = true;
start_paused = false;
gpu_renderer = GPURenderer::HardwareOpenGL; gpu_renderer = GPURenderer::HardwareOpenGL;
gpu_resolution_scale = 1; gpu_resolution_scale = 1;
gpu_vsync = true;
gpu_true_color = true; gpu_true_color = true;
display_linear_filtering = true; display_linear_filtering = true;
@ -39,9 +45,13 @@ void Settings::Load(const char* filename)
region = ParseConsoleRegionName(ini.GetValue("Console", "Region", "NTSC-U")).value_or(ConsoleRegion::NTSC_U); region = ParseConsoleRegionName(ini.GetValue("Console", "Region", "NTSC-U")).value_or(ConsoleRegion::NTSC_U);
audio_sync_enabled = ini.GetBoolValue("General", "SyncToAudio", true);
video_sync_enabled = ini.GetBoolValue("General", "SyncToVideo", true);
speed_limiter_enabled = ini.GetBoolValue("General", "SpeedLimiterEnabled", true);
start_paused = ini.GetBoolValue("General", "StartPaused", false);
gpu_renderer = ParseRendererName(ini.GetValue("GPU", "Renderer", "OpenGL")).value_or(GPURenderer::HardwareOpenGL); gpu_renderer = ParseRendererName(ini.GetValue("GPU", "Renderer", "OpenGL")).value_or(GPURenderer::HardwareOpenGL);
gpu_resolution_scale = static_cast<u32>(ini.GetLongValue("GPU", "ResolutionScale", 1)); gpu_resolution_scale = static_cast<u32>(ini.GetLongValue("GPU", "ResolutionScale", 1));
gpu_vsync = static_cast<u32>(ini.GetBoolValue("GPU", "VSync", true));
gpu_true_color = ini.GetBoolValue("GPU", "TrueColor", false); gpu_true_color = ini.GetBoolValue("GPU", "TrueColor", false);
display_linear_filtering = ini.GetBoolValue("Display", "LinearFiltering", true); display_linear_filtering = ini.GetBoolValue("Display", "LinearFiltering", true);
@ -64,9 +74,14 @@ bool Settings::Save(const char* filename) const
ini.SetValue("Console", "Region", GetConsoleRegionName(region)); ini.SetValue("Console", "Region", GetConsoleRegionName(region));
ini.SetBoolValue("General", "SyncToAudio", audio_sync_enabled);
ini.SetBoolValue("General", "SyncToVideo", video_sync_enabled);
ini.SetBoolValue("General", "SpeedLimiterEnabled", speed_limiter_enabled);
ini.SetBoolValue("General", "StartPaused", start_paused);
ini.SetValue("GPU", "Renderer", GetRendererName(gpu_renderer)); ini.SetValue("GPU", "Renderer", GetRendererName(gpu_renderer));
ini.SetLongValue("GPU", "ResolutionScale", static_cast<long>(gpu_resolution_scale)); ini.SetLongValue("GPU", "ResolutionScale", static_cast<long>(gpu_resolution_scale));
ini.SetBoolValue("GPU", "VSync", gpu_vsync); ini.SetBoolValue("GPU", "VSync", video_sync_enabled);
ini.SetBoolValue("GPU", "TrueColor", gpu_true_color); ini.SetBoolValue("GPU", "TrueColor", gpu_true_color);
ini.SetBoolValue("Display", "LinearFiltering", display_linear_filtering); ini.SetBoolValue("Display", "LinearFiltering", display_linear_filtering);

View File

@ -6,15 +6,16 @@ struct Settings
{ {
Settings(); Settings();
ConsoleRegion region = ConsoleRegion::NTSC_U; ConsoleRegion region = ConsoleRegion::Auto;
bool start_paused = false; bool start_paused = false;
bool speed_limiter_enabled = true; bool speed_limiter_enabled = true;
bool audio_sync_enabled = true;
bool video_sync_enabled = true;
GPURenderer gpu_renderer = GPURenderer::Software; GPURenderer gpu_renderer = GPURenderer::Software;
u32 gpu_resolution_scale = 1; u32 gpu_resolution_scale = 1;
mutable u32 max_gpu_resolution_scale = 1; mutable u32 max_gpu_resolution_scale = 1;
bool gpu_vsync = true;
bool gpu_true_color = false; bool gpu_true_color = false;
bool display_linear_filtering = true; bool display_linear_filtering = true;
bool display_fullscreen = false; bool display_fullscreen = false;

View File

@ -743,9 +743,12 @@ void SDLHostInterface::DrawQuickSettingsMenu()
} }
if (ImGui::MenuItem("Fullscreen", nullptr, &m_settings.display_fullscreen)) if (ImGui::MenuItem("Fullscreen", nullptr, &m_settings.display_fullscreen))
{
settings_changed = true;
UpdateFullscreen(); UpdateFullscreen();
}
if (ImGui::MenuItem("VSync", nullptr, &m_settings.gpu_vsync)) if (ImGui::MenuItem("VSync", nullptr, &m_settings.video_sync_enabled))
{ {
settings_changed = true; settings_changed = true;
UpdateSpeedLimiterState(); UpdateSpeedLimiterState();
@ -914,13 +917,6 @@ void SDLHostInterface::DrawSettingsWindow()
if (ImGui::BeginTabItem("General")) if (ImGui::BeginTabItem("General"))
{ {
if (DrawSettingsSectionHeader("Behavior"))
{
settings_changed |= ImGui::Checkbox("Enable Speed Limiter", &m_settings.speed_limiter_enabled);
settings_changed |= ImGui::Checkbox("Pause On Start", &m_settings.start_paused);
}
ImGui::NewLine();
if (DrawSettingsSectionHeader("Console")) if (DrawSettingsSectionHeader("Console"))
{ {
ImGui::Text("Region:"); ImGui::Text("Region:");
@ -940,6 +936,33 @@ void SDLHostInterface::DrawSettingsWindow()
} }
} }
ImGui::NewLine();
if (DrawSettingsSectionHeader("Behavior"))
{
if (ImGui::Checkbox("Enable Speed Limiter", &m_settings.speed_limiter_enabled))
{
settings_changed = true;
UpdateSpeedLimiterState();
}
settings_changed |= ImGui::Checkbox("Pause On Start", &m_settings.start_paused);
}
ImGui::NewLine();
if (DrawSettingsSectionHeader("Host Synchronization"))
{
if (ImGui::Checkbox("Sync To Audio", &m_settings.audio_sync_enabled))
{
settings_changed = true;
UpdateSpeedLimiterState();
}
if (ImGui::Checkbox("Sync To Video", &m_settings.video_sync_enabled))
{
settings_changed = true;
UpdateSpeedLimiterState();
}
}
ImGui::NewLine(); ImGui::NewLine();
if (DrawSettingsSectionHeader("BIOS")) if (DrawSettingsSectionHeader("BIOS"))
{ {
@ -1017,11 +1040,6 @@ void SDLHostInterface::DrawSettingsWindow()
if (ImGui::Checkbox("Fullscreen", &m_settings.display_fullscreen)) if (ImGui::Checkbox("Fullscreen", &m_settings.display_fullscreen))
UpdateFullscreen(); UpdateFullscreen();
if (ImGui::Checkbox("VSync", &m_settings.gpu_vsync))
{
UpdateSpeedLimiterState();
settings_changed = true;
}
if (ImGui::Checkbox("Linear Filtering", &m_settings.display_linear_filtering)) if (ImGui::Checkbox("Linear Filtering", &m_settings.display_linear_filtering))
{ {
m_display->SetDisplayLinearFiltering(m_settings.display_linear_filtering); m_display->SetDisplayLinearFiltering(m_settings.display_linear_filtering);