System: Move settings to HostInterface

This commit is contained in:
Connor McLaughlin 2019-11-08 01:07:39 +10:00
parent e8ebead23d
commit 8c51abaf37
10 changed files with 229 additions and 199 deletions

View file

@ -19,7 +19,6 @@ bool GPU_HW::Initialize(HostDisplay* host_display, System* system, DMA* dma, Int
return false;
m_resolution_scale = std::clamp<u32>(m_system->GetSettings().gpu_resolution_scale, 1, m_max_resolution_scale);
m_system->GetSettings().gpu_resolution_scale = m_resolution_scale;
m_system->GetSettings().max_gpu_resolution_scale = m_max_resolution_scale;
m_true_color = m_system->GetSettings().gpu_true_color;
return true;
@ -53,7 +52,6 @@ void GPU_HW::UpdateSettings()
GPU::UpdateSettings();
m_resolution_scale = std::clamp<u32>(m_system->GetSettings().gpu_resolution_scale, 1, m_max_resolution_scale);
m_system->GetSettings().gpu_resolution_scale = m_resolution_scale;
m_true_color = m_system->GetSettings().gpu_true_color;
}

View file

@ -2,19 +2,20 @@
#include "YBaseLib/ByteStream.h"
#include "YBaseLib/Log.h"
#include "common/audio_stream.h"
#include "host_display.h"
#include "system.h"
Log_SetChannel(HostInterface);
HostInterface::HostInterface()
{
m_settings.Load("settings.ini");
m_settings.SetDefaults();
}
HostInterface::~HostInterface() = default;
bool HostInterface::InitializeSystem(const char* filename, const char* exp1_filename)
{
m_system = std::make_unique<System>(this, m_settings);
m_system = std::make_unique<System>(this);
if (!m_system->Initialize())
{
m_system.reset();
@ -54,6 +55,13 @@ bool HostInterface::InitializeSystem(const char* filename, const char* exp1_file
return true;
}
void HostInterface::ShutdownSystem()
{
m_system.reset();
m_paused = false;
UpdateAudioVisualSync();
}
bool HostInterface::LoadState(const char* filename)
{
ByteStream* stream;
@ -99,3 +107,15 @@ bool HostInterface::SaveState(const char* filename)
stream->Release();
return result;
}
void HostInterface::UpdateAudioVisualSync()
{
const bool speed_limiter_enabled = m_settings.speed_limiter_enabled && !m_speed_limiter_temp_disabled;
const bool audio_sync_enabled = speed_limiter_enabled;
const bool vsync_enabled = !m_system || (speed_limiter_enabled && m_settings.gpu_vsync);
Log_InfoPrintf("Syncing to %s%s", audio_sync_enabled ? "audio" : "",
(speed_limiter_enabled && vsync_enabled) ? " and video" : "");
m_audio_stream->SetSync(false);
m_display->SetVSync(vsync_enabled);
}

View file

@ -14,11 +14,19 @@ public:
HostInterface();
virtual ~HostInterface();
/// Access to host display.
ALWAYS_INLINE HostDisplay* GetDisplay() const { return m_display.get(); }
/// Access to host audio stream.
AudioStream* GetAudioStream() const { return m_audio_stream.get(); }
bool InitializeSystem(const char* filename, const char* exp1_filename);
/// Returns a settings object which can be modified.
Settings& GetSettings() { return m_settings; }
bool InitializeSystem(const char* filename, const char* exp1_filename);
void ShutdownSystem();
virtual HostDisplay* GetDisplay() const = 0;
virtual void ReportMessage(const char* message) = 0;
@ -29,8 +37,13 @@ public:
bool SaveState(const char* filename);
protected:
void UpdateAudioVisualSync();
std::unique_ptr<HostDisplay> m_display;
std::unique_ptr<AudioStream> m_audio_stream;
std::unique_ptr<System> m_system;
Settings m_settings;
bool m_paused = false;
bool m_speed_limiter_temp_disabled = false;
};

View file

@ -78,7 +78,13 @@ bool Settings::Save(const char* filename) const
ini.DeleteValue("MemoryCard", "CardBPath", nullptr);
err = ini.SaveFile(filename, false);
return (err == SI_OK);
if (err != SI_OK)
{
Log_WarningPrintf("Failed to save settings to '%s'.", filename);
return false;
}
return true;
}
static std::array<const char*, 3> s_gpu_renderer_names = {{"D3D11", "OpenGL", "Software"}};

View file

@ -19,7 +19,7 @@ struct Settings
GPURenderer gpu_renderer = GPURenderer::Software;
u32 gpu_resolution_scale = 1;
u32 max_gpu_resolution_scale = 1;
mutable u32 max_gpu_resolution_scale = 1;
bool gpu_vsync = true;
bool gpu_true_color = false;
bool display_linear_filtering = true;
@ -27,15 +27,16 @@ struct Settings
struct DebugSettings
{
bool show_gpu_state = false;
bool show_vram = false;
bool dump_cpu_to_vram_copies = false;
bool dump_vram_to_cpu_copies = false;
bool show_cdrom_state = false;
bool show_spu_state = false;
bool show_timers_state = false;
bool show_mdec_state = false;
// Mutable because the imgui window can close itself.
mutable bool show_gpu_state = false;
mutable bool show_cdrom_state = false;
mutable bool show_spu_state = false;
mutable bool show_timers_state = false;
mutable bool show_mdec_state = false;
} debugging;
// TODO: Controllers, memory cards, etc.

View file

@ -19,8 +19,8 @@
#include <imgui.h>
Log_SetChannel(System);
System::System(HostInterface* host_interface, const Settings& settings)
: m_host_interface(host_interface), m_settings(settings)
System::System(HostInterface* host_interface)
: m_host_interface(host_interface)
{
m_cpu = std::make_unique<CPU::Core>();
m_bus = std::make_unique<Bus>();
@ -107,7 +107,7 @@ bool System::Initialize()
bool System::CreateGPU()
{
switch (m_settings.gpu_renderer)
switch (m_host_interface->GetSettings().gpu_renderer)
{
case Settings::GPURenderer::HardwareOpenGL:
m_gpu = GPU::CreateHardwareOpenGLRenderer();
@ -130,7 +130,7 @@ bool System::CreateGPU()
{
Log_ErrorPrintf("Failed to initialize GPU, falling back to software");
m_gpu.reset();
m_settings.gpu_renderer = Settings::GPURenderer::Software;
m_host_interface->GetSettings().gpu_renderer = Settings::GPURenderer::Software;
m_gpu = GPU::CreateSoftwareRenderer();
if (!m_gpu->Initialize(m_host_interface->GetDisplay(), this, m_dma.get(), m_interrupt_controller.get(),
m_timers.get()))
@ -376,16 +376,17 @@ void System::UpdateMemoryCards()
m_pad->SetMemoryCard(0, nullptr);
m_pad->SetMemoryCard(1, nullptr);
if (!m_settings.memory_card_a_path.empty())
const Settings& settings = m_host_interface->GetSettings();
if (!settings.memory_card_a_path.empty())
{
std::shared_ptr<MemoryCard> card = MemoryCard::Open(this, m_settings.memory_card_a_path);
std::shared_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_a_path);
if (card)
m_pad->SetMemoryCard(0, std::move(card));
}
if (!m_settings.memory_card_b_path.empty())
if (!settings.memory_card_b_path.empty())
{
std::shared_ptr<MemoryCard> card = MemoryCard::Open(this, m_settings.memory_card_b_path);
std::shared_ptr<MemoryCard> card = MemoryCard::Open(this, settings.memory_card_b_path);
if (card)
m_pad->SetMemoryCard(1, std::move(card));
}

View file

@ -1,13 +1,11 @@
#pragma once
#include "settings.h"
#include "types.h"
#include "host_interface.h"
#include <memory>
class ByteStream;
class StateWrapper;
class HostInterface;
namespace CPU {
class Core;
}
@ -26,7 +24,7 @@ class MDEC;
class System
{
public:
System(HostInterface* host_interface, const Settings& settings);
System(HostInterface* host_interface);
~System();
// Accessing components.
@ -48,7 +46,7 @@ public:
void IncrementFrameNumber() { m_frame_number++; }
void IncrementInternalFrameNumber() { m_internal_frame_number++; }
Settings& GetSettings() { return m_settings; }
const Settings& GetSettings() { return m_host_interface->GetSettings(); }
bool Initialize();
void Reset();
@ -95,6 +93,4 @@ private:
u32 m_frame_number = 1;
u32 m_internal_frame_number = 1;
u32 m_global_tick_counter = 0;
Settings m_settings;
};

View file

@ -62,5 +62,5 @@ void ImGui::StyleColorsDarker(ImGuiStyle* dst)
void ImGui::AddRobotoRegularFont(float size /*= 15.0f*/)
{
ImGui::GetIO().Fonts->AddFontFromMemoryCompressedTTF(s_font_roboto_regular_compressed_data,
s_font_roboto_regular_compressed_size, 15.0f);
s_font_roboto_regular_compressed_size, size);
}

View file

@ -26,7 +26,7 @@
#include <nfd.h>
Log_SetChannel(SDLHostInterface);
SDLHostInterface::SDLHostInterface() = default;
SDLHostInterface::SDLHostInterface() : m_settings_filename("settings.ini") {}
SDLHostInterface::~SDLHostInterface()
{
@ -85,7 +85,7 @@ bool SDLHostInterface::CreateDisplay()
return true;
}
bool SDLHostInterface::CreateImGuiContext()
void SDLHostInterface::CreateImGuiContext()
{
ImGui::CreateContext();
ImGui::GetIO().IniFilename = nullptr;
@ -94,32 +94,12 @@ bool SDLHostInterface::CreateImGuiContext()
ImGui::StyleColorsDarker();
ImGui::AddRobotoRegularFont();
return true;
}
bool SDLHostInterface::CreateAudioStream()
{
m_audio_stream = std::make_unique<SDLAudioStream>();
if (!m_audio_stream->Reconfigure(44100, 2))
{
Panic("Failed to open audio stream");
return false;
}
return true;
}
void SDLHostInterface::UpdateAudioVisualSync()
{
const bool speed_limiter_enabled =
!m_system || (m_system->GetSettings().speed_limiter_enabled && !m_speed_limiter_temp_disabled);
const bool audio_sync_enabled = speed_limiter_enabled;
const bool vsync_enabled = !m_system || (speed_limiter_enabled && m_system->GetSettings().gpu_vsync);
Log_InfoPrintf("Syncing to %s%s", audio_sync_enabled ? "audio" : "",
(speed_limiter_enabled && vsync_enabled) ? " and video" : "");
m_audio_stream->SetSync(false);
m_display->SetVSync(vsync_enabled);
return m_audio_stream->Reconfigure(44100, 2);
}
void SDLHostInterface::OpenGameControllers()
@ -146,6 +126,11 @@ void SDLHostInterface::CloseGameControllers()
m_sdl_controllers.clear();
}
void SDLHostInterface::SaveSettings()
{
m_settings.Save(m_settings_filename.c_str());
}
bool SDLHostInterface::InitializeSystem(const char* filename, const char* exp1_filename)
{
if (!HostInterface::InitializeSystem(filename, exp1_filename))
@ -185,20 +170,33 @@ void SDLHostInterface::ResetPerformanceCounters()
void SDLHostInterface::SwitchGPURenderer() {}
void SDLHostInterface::ShutdownSystem()
{
m_system.reset();
m_paused = false;
UpdateAudioVisualSync();
}
std::unique_ptr<SDLHostInterface> SDLHostInterface::Create(const char* filename /* = nullptr */,
const char* exp1_filename /* = nullptr */,
const char* save_state_filename /* = nullptr */)
{
std::unique_ptr<SDLHostInterface> intf = std::make_unique<SDLHostInterface>();
if (!intf->CreateSDLWindow() || !intf->CreateImGuiContext() || !intf->CreateDisplay() || !intf->CreateAudioStream())
// Settings need to be loaded prior to creating the window for OpenGL bits.
intf->m_settings.Load(intf->m_settings_filename.c_str());
if (!intf->CreateSDLWindow())
{
Log_ErrorPrintf("Failed to create SDL window");
return nullptr;
}
intf->CreateImGuiContext();
if (!intf->CreateDisplay())
{
Log_ErrorPrintf("Failed to create host display");
return nullptr;
}
if (!intf->CreateAudioStream())
{
Log_ErrorPrintf("Failed to create host audio stream");
return nullptr;
}
ImGui::NewFrame();
@ -224,11 +222,6 @@ TinyString SDLHostInterface::GetSaveStateFilename(u32 index)
return TinyString::FromFormat("savestate_%u.bin", index);
}
HostDisplay* SDLHostInterface::GetDisplay() const
{
return m_display.get();
}
void SDLHostInterface::ReportMessage(const char* message)
{
AddOSDMessage(message, 3.0f);
@ -521,7 +514,7 @@ void SDLHostInterface::HandleSDLKeyEvent(const SDL_Event* event)
{
if (pressed && !repeat && m_system)
{
m_system->GetSettings().speed_limiter_enabled = !m_system->GetSettings().speed_limiter_enabled;
m_settings.speed_limiter_enabled = !m_settings.speed_limiter_enabled;
UpdateAudioVisualSync();
AddOSDMessage(m_system->GetSettings().speed_limiter_enabled ? "Speed limiter enabled." :
"Speed limiter disabled.");
@ -644,74 +637,20 @@ void SDLHostInterface::DrawMainMenuBar()
if (ImGui::BeginMenu("Settings"))
{
Settings& settings = m_system ? m_system->GetSettings() : m_settings;
if (ImGui::MenuItem("Enable Speed Limiter", nullptr, &settings.speed_limiter_enabled, system_enabled))
{
UpdateAudioVisualSync();
}
if (ImGui::MenuItem("Change Settings..."))
m_settings_window_open = true;
ImGui::Separator();
if (ImGui::MenuItem("Fullscreen", nullptr, IsWindowFullscreen()))
SDL_SetWindowFullscreen(m_window, IsWindowFullscreen() ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
ImGui::Separator();
if (ImGui::BeginMenu("GPU", system_enabled))
{
if (ImGui::BeginMenu("Renderer"))
{
const Settings::GPURenderer current = m_system->GetSettings().gpu_renderer;
for (u32 i = 0; i < static_cast<u32>(Settings::GPURenderer::Count); i++)
{
if (ImGui::MenuItem(Settings::GetRendererDisplayName(static_cast<Settings::GPURenderer>(i)), nullptr,
i == static_cast<u32>(current)))
{
m_system->GetSettings().gpu_renderer = static_cast<Settings::GPURenderer>(i);
m_system->RecreateGPU();
}
}
DrawQuickSettingsMenu();
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Internal Resolution"))
if (ImGui::BeginMenu("Debug", system_enabled))
{
const u32 current_internal_resolution = m_system->GetSettings().gpu_resolution_scale;
for (u32 scale = 1; scale <= m_system->GetSettings().max_gpu_resolution_scale; scale++)
{
if (ImGui::MenuItem(
TinyString::FromFormat("%ux (%ux%u)", scale, scale * GPU::VRAM_WIDTH, scale * GPU::VRAM_HEIGHT),
nullptr, current_internal_resolution == scale))
{
m_system->GetSettings().gpu_resolution_scale = scale;
m_system->GetGPU()->UpdateSettings();
}
}
ImGui::EndMenu();
}
if (ImGui::MenuItem("VSync", nullptr, &m_system->GetSettings().gpu_vsync))
UpdateAudioVisualSync();
if (ImGui::MenuItem("True (24-Bit) Color", nullptr, &m_system->GetSettings().gpu_true_color))
m_system->GetGPU()->UpdateSettings();
if (ImGui::MenuItem("Display Linear Filtering", nullptr, &m_system->GetSettings().display_linear_filtering))
{
// this has to update the display texture for now..
m_system->GetGPU()->UpdateSettings();
}
ImGui::EndMenu();
}
ImGui::EndMenu();
}
if (m_system)
DrawDebugMenu();
ImGui::EndMenu();
}
if (ImGui::BeginMenu("Help"))
{
@ -759,6 +698,100 @@ void SDLHostInterface::DrawMainMenuBar()
ImGui::EndMainMenuBar();
}
void SDLHostInterface::DrawQuickSettingsMenu()
{
bool settings_changed = false;
bool gpu_settings_changed = false;
if (ImGui::MenuItem("Enable Speed Limiter", nullptr, &m_settings.speed_limiter_enabled))
{
settings_changed = true;
UpdateAudioVisualSync();
}
ImGui::Separator();
if (ImGui::BeginMenu("Renderer"))
{
const Settings::GPURenderer current = m_settings.gpu_renderer;
for (u32 i = 0; i < static_cast<u32>(Settings::GPURenderer::Count); i++)
{
if (ImGui::MenuItem(Settings::GetRendererDisplayName(static_cast<Settings::GPURenderer>(i)), nullptr,
i == static_cast<u32>(current)))
{
m_settings.gpu_renderer = static_cast<Settings::GPURenderer>(i);
settings_changed = true;
if (m_system)
SwitchGPURenderer();
}
}
ImGui::EndMenu();
}
if (ImGui::MenuItem("Fullscreen", nullptr, IsWindowFullscreen()))
SDL_SetWindowFullscreen(m_window, IsWindowFullscreen() ? 0 : SDL_WINDOW_FULLSCREEN_DESKTOP);
if (ImGui::MenuItem("VSync", nullptr, &m_settings.gpu_vsync))
{
settings_changed = true;
UpdateAudioVisualSync();
}
ImGui::Separator();
if (ImGui::BeginMenu("Resolution Scale"))
{
const u32 current_internal_resolution = m_settings.gpu_resolution_scale;
for (u32 scale = 1; scale <= m_settings.max_gpu_resolution_scale; scale++)
{
if (ImGui::MenuItem(
TinyString::FromFormat("%ux (%ux%u)", scale, scale * GPU::VRAM_WIDTH, scale * GPU::VRAM_HEIGHT), nullptr,
current_internal_resolution == scale))
{
m_settings.gpu_resolution_scale = scale;
gpu_settings_changed = true;
}
}
ImGui::EndMenu();
}
gpu_settings_changed |= ImGui::MenuItem("True (24-Bit) Color", nullptr, &m_settings.gpu_true_color);
settings_changed |= ImGui::MenuItem("Display Linear Filtering", nullptr, &m_settings.display_linear_filtering);
if (settings_changed || gpu_settings_changed)
SaveSettings();
if (gpu_settings_changed && m_system)
m_system->GetGPU()->UpdateSettings();
}
void SDLHostInterface::DrawDebugMenu()
{
Settings::DebugSettings& debug_settings = m_settings.debugging;
ImGui::MenuItem("Show System State");
ImGui::Separator();
ImGui::MenuItem("Show GPU State", nullptr, &debug_settings.show_gpu_state);
ImGui::MenuItem("Show VRAM", nullptr, &debug_settings.show_vram);
ImGui::MenuItem("Dump CPU to VRAM Copies", nullptr, &debug_settings.dump_cpu_to_vram_copies);
ImGui::MenuItem("Dump VRAM to CPU Copies", nullptr, &debug_settings.dump_vram_to_cpu_copies);
ImGui::Separator();
ImGui::MenuItem("Show CDROM State", nullptr, &debug_settings.show_cdrom_state);
ImGui::Separator();
ImGui::MenuItem("Show SPU State", nullptr, &debug_settings.show_spu_state);
ImGui::Separator();
ImGui::MenuItem("Show Timers State", nullptr, &debug_settings.show_timers_state);
ImGui::Separator();
ImGui::MenuItem("Show MDEC State", nullptr, &debug_settings.show_mdec_state);
ImGui::Separator();
}
void SDLHostInterface::DrawPoweredOffWindow()
{
constexpr int WINDOW_WIDTH = 400;
@ -854,7 +887,6 @@ void SDLHostInterface::DrawSettingsWindow()
return;
}
Settings& settings = m_system ? m_system->GetSettings() : m_settings;
bool settings_changed = false;
bool gpu_settings_changed = false;
@ -871,11 +903,11 @@ void SDLHostInterface::DrawSettingsWindow()
ImGui::Text("BIOS Path:");
ImGui::SameLine(indent);
DrawFileChooser("##bios_path", &settings.bios_path);
DrawFileChooser("##bios_path", &m_settings.bios_path);
ImGui::Checkbox("Enable Speed Limiter", &settings.speed_limiter_enabled);
ImGui::Checkbox("Enable Speed Limiter", &m_settings.speed_limiter_enabled);
ImGui::Checkbox("Pause On Start", &settings.start_paused);
ImGui::Checkbox("Pause On Start", &m_settings.start_paused);
ImGui::EndTabItem();
}
@ -892,7 +924,7 @@ void SDLHostInterface::DrawSettingsWindow()
ImGui::Text("Path:");
ImGui::SameLine(indent);
std::string* path_ptr = (i == 0) ? &settings.memory_card_a_path : &settings.memory_card_b_path;
std::string* path_ptr = (i == 0) ? &m_settings.memory_card_a_path : &m_settings.memory_card_b_path;
if (DrawFileChooser(TinyString::FromFormat("##memcard_%c_path", 'a' + i), path_ptr))
{
settings_changed = true;
@ -921,7 +953,7 @@ void SDLHostInterface::DrawSettingsWindow()
ImGui::Text("Renderer:");
ImGui::SameLine(indent);
int gpu_renderer = static_cast<int>(settings.gpu_renderer);
int gpu_renderer = static_cast<int>(m_settings.gpu_renderer);
if (ImGui::Combo(
"##gpu_renderer", &gpu_renderer,
[](void*, int index, const char** out_text) {
@ -930,7 +962,7 @@ void SDLHostInterface::DrawSettingsWindow()
},
nullptr, static_cast<int>(Settings::GPURenderer::Count)))
{
settings.gpu_renderer = static_cast<Settings::GPURenderer>(gpu_renderer);
m_settings.gpu_renderer = static_cast<Settings::GPURenderer>(gpu_renderer);
SwitchGPURenderer();
}
}
@ -939,10 +971,10 @@ void SDLHostInterface::DrawSettingsWindow()
if (DrawSettingsSectionHeader("Display Output"))
{
ImGui::Checkbox("Fullscreen", &settings.display_fullscreen);
if (ImGui::Checkbox("VSync", &settings.gpu_vsync))
ImGui::Checkbox("Fullscreen", &m_settings.display_fullscreen);
if (ImGui::Checkbox("VSync", &m_settings.gpu_vsync))
UpdateAudioVisualSync();
ImGui::Checkbox("Linear Filtering", &settings.display_linear_filtering);
ImGui::Checkbox("Linear Filtering", &m_settings.display_linear_filtering);
}
ImGui::NewLine();
@ -971,15 +1003,15 @@ void SDLHostInterface::DrawSettingsWindow()
"16x (16384x8192)",
}};
int current_resolution_index = static_cast<int>(settings.gpu_resolution_scale) - 1;
int current_resolution_index = static_cast<int>(m_settings.gpu_resolution_scale) - 1;
if (ImGui::Combo("##gpu_resolution_scale", &current_resolution_index, resolutions.data(),
static_cast<int>(resolutions.size())))
{
settings.gpu_resolution_scale = static_cast<u32>(current_resolution_index + 1);
m_settings.gpu_resolution_scale = static_cast<u32>(current_resolution_index + 1);
gpu_settings_changed = true;
}
ImGui::Checkbox("True 24-bit Color (disables dithering)", &settings.gpu_true_color);
ImGui::Checkbox("True 24-bit Color (disables dithering)", &m_settings.gpu_true_color);
}
ImGui::EndTabItem();
@ -1034,37 +1066,6 @@ void SDLHostInterface::DrawAboutWindow()
ImGui::EndPopup();
}
void SDLHostInterface::DrawDebugMenu()
{
if (!ImGui::BeginMenu("Debug", m_system != nullptr))
return;
Settings::DebugSettings& debug_settings = m_system->GetSettings().debugging;
ImGui::MenuItem("Show System State");
ImGui::Separator();
ImGui::MenuItem("Show GPU State", nullptr, &debug_settings.show_gpu_state);
ImGui::MenuItem("Show VRAM", nullptr, &debug_settings.show_vram);
ImGui::MenuItem("Dump CPU to VRAM Copies", nullptr, &debug_settings.dump_cpu_to_vram_copies);
ImGui::MenuItem("Dump VRAM to CPU Copies", nullptr, &debug_settings.dump_vram_to_cpu_copies);
ImGui::Separator();
ImGui::MenuItem("Show CDROM State", nullptr, &debug_settings.show_cdrom_state);
ImGui::Separator();
ImGui::MenuItem("Show SPU State", nullptr, &debug_settings.show_spu_state);
ImGui::Separator();
ImGui::MenuItem("Show Timers State", nullptr, &debug_settings.show_timers_state);
ImGui::Separator();
ImGui::MenuItem("Show MDEC State", nullptr, &debug_settings.show_mdec_state);
ImGui::Separator();
ImGui::EndMenu();
}
void SDLHostInterface::DrawDebugWindows()
{
const Settings::DebugSettings& debug_settings = m_system->GetSettings().debugging;
@ -1270,15 +1271,14 @@ void SDLHostInterface::DoToggleSoftwareRendering()
if (!m_system)
return;
auto& settings = m_system->GetSettings();
if (settings.gpu_renderer != Settings::GPURenderer::Software)
if (m_settings.gpu_renderer != Settings::GPURenderer::Software)
{
settings.gpu_renderer = Settings::GPURenderer::Software;
m_settings.gpu_renderer = Settings::GPURenderer::Software;
AddOSDMessage("Switched to software GPU renderer.");
}
else
{
settings.gpu_renderer = m_display->GetRenderAPI() == HostDisplay::RenderAPI::D3D11 ?
m_settings.gpu_renderer = m_display->GetRenderAPI() == HostDisplay::RenderAPI::D3D11 ?
Settings::GPURenderer::HardwareD3D11 :
Settings::GPURenderer::HardwareOpenGL;
AddOSDMessage("Switched to hardware GPU renderer.");
@ -1289,22 +1289,19 @@ void SDLHostInterface::DoToggleSoftwareRendering()
void SDLHostInterface::DoModifyInternalResolution(s32 increment)
{
if (!m_system)
return;
auto& settings = m_system->GetSettings();
const u32 new_resolution_scale =
std::clamp<u32>(static_cast<u32>(static_cast<s32>(settings.gpu_resolution_scale) + increment), 1,
settings.max_gpu_resolution_scale);
if (new_resolution_scale == settings.gpu_resolution_scale)
std::clamp<u32>(static_cast<u32>(static_cast<s32>(m_settings.gpu_resolution_scale) + increment), 1,
m_settings.max_gpu_resolution_scale);
if (new_resolution_scale == m_settings.gpu_resolution_scale)
return;
settings.gpu_resolution_scale = new_resolution_scale;
m_settings.gpu_resolution_scale = new_resolution_scale;
if (m_system)
m_system->GetGPU()->UpdateSettings();
AddOSDMessage(TinyString::FromFormat("Resolution scale set to %ux (%ux%u)", settings.gpu_resolution_scale,
GPU::VRAM_WIDTH * settings.gpu_resolution_scale,
GPU::VRAM_HEIGHT * settings.gpu_resolution_scale));
AddOSDMessage(TinyString::FromFormat("Resolution scale set to %ux (%ux%u)", m_settings.gpu_resolution_scale,
GPU::VRAM_WIDTH * m_settings.gpu_resolution_scale,
GPU::VRAM_HEIGHT * m_settings.gpu_resolution_scale));
}
void SDLHostInterface::Run()

View file

@ -28,8 +28,6 @@ public:
static TinyString GetSaveStateFilename(u32 index);
HostDisplay* GetDisplay() const override;
void ReportMessage(const char* message) override;
// Adds OSD messages, duration is in seconds.
@ -58,18 +56,18 @@ private:
bool CreateSDLWindow();
bool CreateDisplay();
bool CreateImGuiContext();
void CreateImGuiContext();
bool CreateAudioStream();
void UpdateAudioVisualSync();
void OpenGameControllers();
void CloseGameControllers();
void SaveSettings();
bool InitializeSystem(const char* filename = nullptr, const char* exp1_filename = nullptr);
void ConnectDevices();
void ResetPerformanceCounters();
void SwitchGPURenderer();
void ShutdownSystem();
// We only pass mouse input through if it's grabbed
bool IsWindowFullscreen() const;
@ -92,18 +90,20 @@ private:
void ClearImGuiFocus();
void DrawMainMenuBar();
void DrawQuickSettingsMenu();
void DrawDebugMenu();
void DrawPoweredOffWindow();
void DrawSettingsWindow();
void DrawAboutWindow();
void DrawOSDMessages();
void DrawDebugMenu();
void DrawDebugWindows();
bool DrawFileChooser(const char* label, std::string* path, const char* filter = nullptr);
SDL_Window* m_window = nullptr;
std::unique_ptr<HostDisplay> m_display;
std::unique_ptr<HostDisplayTexture> m_app_icon_texture;
std::string m_settings_filename;
std::deque<OSDMessage> m_osd_messages;
std::mutex m_osd_messages_lock;
@ -119,11 +119,9 @@ private:
u32 m_last_global_tick_counter = 0;
Timer m_fps_timer;
bool m_paused = false;
bool m_quit_request = false;
bool m_frame_step_request = false;
bool m_focus_main_menu_bar = false;
bool m_settings_window_open = false;
bool m_about_window_open = false;
bool m_speed_limiter_temp_disabled = false;
};