mirror of
https://github.com/WinampDesktop/winamp.git
synced 2025-06-13 07:55:47 -04:00
System: Move settings to HostInterface
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
@ -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"}};
|
||||
|
@ -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.
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user