Skip to content
Permalink
Browse files
Merge pull request #5876 from leoetlino/sysconf-onion
Config: Port SYSCONF and parts of Movie to new config system
  • Loading branch information
leoetlino committed Aug 11, 2017
2 parents e86f5ac + 940cc84 commit d896988
Show file tree
Hide file tree
Showing 33 changed files with 548 additions and 307 deletions.
@@ -101,8 +101,7 @@ void ClearCurrentRunLayer()
static const std::map<System, std::string> system_to_name = {
{System::Main, "Dolphin"}, {System::GCPad, "GCPad"}, {System::WiiPad, "Wiimote"},
{System::GCKeyboard, "GCKeyboard"}, {System::GFX, "Graphics"}, {System::Logger, "Logger"},
{System::Debugger, "Debugger"}, {System::UI, "UI"},
};
{System::Debugger, "Debugger"}, {System::UI, "UI"}, {System::SYSCONF, "SYSCONF"}};

const std::string& GetSystemName(System system)
{
@@ -66,9 +66,7 @@ LayerType GetActiveLayerForConfig(const ConfigLocation&);
template <typename T>
T Get(LayerType layer, const ConfigInfo<T>& info)
{
return GetLayer(layer)
->GetOrCreateSection(info.location.system, info.location.section)
->template Get<T>(info.location.key, info.default_value);
return GetLayer(layer)->Get(info);
}

template <typename T>
@@ -92,9 +90,7 @@ LayerType GetActiveLayerForConfig(const ConfigInfo<T>& info)
template <typename T>
void Set(LayerType layer, const ConfigInfo<T>& info, const T& value)
{
GetLayer(layer)
->GetOrCreateSection(info.location.system, info.location.section)
->Set(info.location.key, value);
GetLayer(layer)->Set(info, value);
InvokeConfigChangedCallbacks();
}

@@ -23,6 +23,7 @@ enum class LayerType
enum class System
{
Main,
SYSCONF,
GCPad,
WiiPad,
GCKeyboard,
@@ -109,11 +109,6 @@ const LayerMap& Layer::GetLayerMap() const
return m_sections;
}

ConfigLayerLoader* Layer::GetLoader() const
{
return m_loader.get();
}

bool Layer::IsDirty() const
{
return std::any_of(m_sections.begin(), m_sections.end(), [](const auto& system) {
@@ -14,6 +14,9 @@

namespace Config
{
template <typename T>
struct ConfigInfo;

using LayerMap = std::map<System, std::vector<std::unique_ptr<Section>>>;

class ConfigLayerLoader
@@ -52,14 +55,26 @@ class Layer
virtual Section* GetSection(System system, const std::string& section_name);
virtual Section* GetOrCreateSection(System system, const std::string& section_name);

template <typename T>
T Get(const ConfigInfo<T>& config_info)
{
return GetOrCreateSection(config_info.location.system, config_info.location.section)
->template Get<T>(config_info.location.key, config_info.default_value);
}

template <typename T>
void Set(const ConfigInfo<T>& config_info, const T& value)
{
GetOrCreateSection(config_info.location.system, config_info.location.section)
->Set(config_info.location.key, value);
}

// Explicit load and save of layers
void Load();
void Save();

LayerType GetLayer() const;
const LayerMap& GetLayerMap() const;
// Stay away from this routine as much as possible
ConfigLayerLoader* GetLoader() const;

protected:
bool IsDirty() const;
@@ -14,7 +14,6 @@
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
#include "Common/Swap.h"
#include "Core/Movie.h"

constexpr size_t SYSCONF_SIZE = 0x4000;

@@ -61,8 +60,6 @@ void SysConf::Load()
WARN_LOG(CORE, "No valid SYSCONF detected. Creating a new one.");
InsertDefaultEntries();
}

ApplySettingsFromMovie();
}

bool SysConf::LoadFromFile(const std::string& file_name)
@@ -257,17 +254,6 @@ void SysConf::RemoveEntry(const std::string& key)
m_entries.end());
}

// Apply Wii settings from normal SYSCONF on Movie recording/playback
void SysConf::ApplySettingsFromMovie()
{
if (!Movie::IsMovieActive())
return;

SetData<u8>("IPL.LNG", Entry::Type::Byte, Movie::GetLanguage());
SetData<u8>("IPL.E60", Entry::Type::Byte, Movie::IsPAL60());
SetData<u8>("IPL.PGS", Entry::Type::Byte, Movie::IsProgressive());
}

void SysConf::InsertDefaultEntries()
{
AddEntry({Entry::Type::BigArray, "BT.DINF", std::vector<u8>(0x460 + 1)});
@@ -84,7 +84,6 @@ class SysConf final
}

private:
void ApplySettingsFromMovie();
void InsertDefaultEntries();
bool LoadFromFile(const std::string& file_name);

@@ -20,6 +20,7 @@
#include "Common/CDUtils.h"
#include "Common/CommonPaths.h"
#include "Common/CommonTypes.h"
#include "Common/Config/Config.h"
#include "Common/File.h"
#include "Common/FileUtil.h"
#include "Common/Logging/Log.h"
@@ -29,6 +30,7 @@
#include "Core/Boot/DolReader.h"
#include "Core/Boot/ElfReader.h"
#include "Core/CommonTitles.h"
#include "Core/Config/SYSCONFSettings.h"
#include "Core/ConfigManager.h"
#include "Core/FifoPlayer/FifoPlayer.h"
#include "Core/HLE/HLE.h"
@@ -289,7 +291,8 @@ bool CBoot::BootUp(std::unique_ptr<BootParameters> boot)
g_symbolDB.Clear();

// PAL Wii uses NTSC framerate and linecount in 60Hz modes
VideoInterface::Preset(DiscIO::IsNTSC(config.m_region) || (config.bWii && config.bPAL60));
VideoInterface::Preset(DiscIO::IsNTSC(config.m_region) ||
(config.bWii && Config::Get(Config::SYSCONF_PAL60)));

struct BootTitle
{
@@ -33,7 +33,11 @@

#include "Common/Config/Config.h"
#include "Core/Boot/Boot.h"
#include "Core/Config/MainSettings.h"
#include "Core/Config/SYSCONFSettings.h"
#include "Core/ConfigLoaders/BaseConfigLoader.h"
#include "Core/ConfigLoaders/GameConfigLoader.h"
#include "Core/ConfigLoaders/MovieConfigLoader.h"
#include "Core/ConfigLoaders/NetPlayConfigLoader.h"
#include "Core/ConfigManager.h"
#include "Core/Core.h"
@@ -83,12 +87,9 @@ struct ConfigCache
bool bFastDiscSpeed;
bool bDSPHLE;
bool bHLE_BS2;
bool bProgressive;
bool bPAL60;
int iSelectedLanguage;
int iCPUCore;
int Volume;
int m_wii_language;
float m_EmulationSpeed;
float m_OCFactor;
bool m_OCEnable;
@@ -116,16 +117,13 @@ void ConfigCache::SaveConfig(const SConfig& config)
bFastDiscSpeed = config.bFastDiscSpeed;
bDSPHLE = config.bDSPHLE;
bHLE_BS2 = config.bHLE_BS2;
bProgressive = config.bProgressive;
bPAL60 = config.bPAL60;
iSelectedLanguage = config.SelectedLanguage;
iCPUCore = config.iCPUCore;
Volume = config.m_Volume;
m_EmulationSpeed = config.m_EmulationSpeed;
strBackend = config.m_strVideoBackend;
sBackend = config.sBackend;
m_strGPUDeterminismMode = config.m_strGPUDeterminismMode;
m_wii_language = config.m_wii_language;
m_OCFactor = config.m_OCFactor;
m_OCEnable = config.m_OCEnable;

@@ -160,8 +158,6 @@ void ConfigCache::RestoreConfig(SConfig* config)
config->bFastDiscSpeed = bFastDiscSpeed;
config->bDSPHLE = bDSPHLE;
config->bHLE_BS2 = bHLE_BS2;
config->bProgressive = bProgressive;
config->bPAL60 = bPAL60;
config->SelectedLanguage = iSelectedLanguage;
config->iCPUCore = iCPUCore;

@@ -180,8 +176,6 @@ void ConfigCache::RestoreConfig(SConfig* config)
WiimoteReal::ChangeWiimoteSource(i, iWiimoteSource[i]);
}
}

config->m_wii_language = m_wii_language;
}

for (unsigned int i = 0; i < SerialInterface::MAX_SI_CHANNELS; ++i)
@@ -263,8 +257,6 @@ bool BootCore(std::unique_ptr<BootParameters> boot)
core_section->Get("GFXBackend", &StartUp.m_strVideoBackend, StartUp.m_strVideoBackend);
core_section->Get("CPUCore", &StartUp.iCPUCore, StartUp.iCPUCore);
core_section->Get("HLE_BS2", &StartUp.bHLE_BS2, StartUp.bHLE_BS2);
core_section->Get("ProgressiveScan", &StartUp.bProgressive, StartUp.bProgressive);
core_section->Get("PAL60", &StartUp.bPAL60, StartUp.bPAL60);
core_section->Get("GameCubeLanguage", &StartUp.SelectedLanguage, StartUp.SelectedLanguage);
if (core_section->Get("EmulationSpeed", &StartUp.m_EmulationSpeed, StartUp.m_EmulationSpeed))
config_cache.bSetEmulationSpeed = true;
@@ -293,10 +285,6 @@ bool BootCore(std::unique_ptr<BootParameters> boot)
// Wii settings
if (StartUp.bWii)
{
IniFile::Section* wii_section = game_ini.GetOrCreateSection("Wii");
wii_section->Get("Widescreen", &StartUp.m_wii_aspect_ratio, !!StartUp.m_wii_aspect_ratio);
wii_section->Get("Language", &StartUp.m_wii_language, StartUp.m_wii_language);

int source;
for (unsigned int i = 0; i < MAX_WIIMOTES; ++i)
{
@@ -325,16 +313,14 @@ bool BootCore(std::unique_ptr<BootParameters> boot)
// Movie settings
if (Movie::IsPlayingInput() && Movie::IsConfigSaved())
{
Config::AddLayer(std::make_unique<Config::Layer>(Config::LayerType::Movie));
StartUp.bCPUThread = Movie::IsDualCore();
StartUp.bDSPHLE = Movie::IsDSPHLE();
StartUp.bProgressive = Movie::IsProgressive();
StartUp.bPAL60 = Movie::IsPAL60();
StartUp.bFastDiscSpeed = Movie::IsFastDiscSpeed();
StartUp.iCPUCore = Movie::GetCPUMode();
StartUp.bSyncGPU = Movie::IsSyncGPU();
// TODO: remove this once ConfigManager starts using OnionConfig.
StartUp.bCPUThread = Config::Get(Config::MAIN_CPU_THREAD);
StartUp.bDSPHLE = Config::Get(Config::MAIN_DSP_HLE);
StartUp.bFastDiscSpeed = Config::Get(Config::MAIN_FAST_DISC_SPEED);
StartUp.iCPUCore = Config::Get(Config::MAIN_CPU_CORE);
StartUp.bSyncGPU = Config::Get(Config::MAIN_SYNC_GPU);
if (!StartUp.bWii)
StartUp.SelectedLanguage = Movie::GetLanguage();
StartUp.SelectedLanguage = Config::Get(Config::MAIN_GC_LANGUAGE);
for (int i = 0; i < 2; ++i)
{
if (Movie::IsUsingMemcard(i) && Movie::IsStartingFromClearSave() && !StartUp.bWii)
@@ -360,8 +346,6 @@ bool BootCore(std::unique_ptr<BootParameters> boot)
StartUp.iCPUCore = g_NetPlaySettings.m_CPUcore;
StartUp.SelectedLanguage = g_NetPlaySettings.m_SelectedLanguage;
StartUp.bOverrideGCLanguage = g_NetPlaySettings.m_OverrideGCLanguage;
StartUp.bProgressive = g_NetPlaySettings.m_ProgressiveScan;
StartUp.bPAL60 = g_NetPlaySettings.m_PAL60;
StartUp.m_DSPEnableJIT = g_NetPlaySettings.m_DSPEnableJIT;
StartUp.m_OCEnable = g_NetPlaySettings.m_OCEnable;
StartUp.m_OCFactor = g_NetPlaySettings.m_OCFactor;
@@ -388,12 +372,11 @@ bool BootCore(std::unique_ptr<BootParameters> boot)
// Some NTSC Wii games such as Doc Louis's Punch-Out!! and
// 1942 (Virtual Console) crash if the PAL60 option is enabled
if (StartUp.bWii && ntsc)
{
StartUp.bPAL60 = false;
}
Config::SetCurrent(Config::SYSCONF_PAL60, false);

// Ensure any new settings are written to the SYSCONF
if (StartUp.bWii)
StartUp.SaveSettingsToSysconf();
ConfigLoaders::SaveToSYSCONF(Config::GetLayer(Config::LayerType::Meta));

const bool load_ipl = !StartUp.bWii && !StartUp.bHLE_BS2 &&
std::holds_alternative<BootParameters::Disc>(boot->parameters);
@@ -411,14 +394,41 @@ void Stop()
RestoreConfig();
}

// SYSCONF can be modified during emulation by the user and internally, which makes it
// a bad idea to just always overwrite it with the settings from the base layer.
//
// Conversely, we also shouldn't just ignore any changes to SYSCONF, as it may cause
// temporary settings (from Movie, Netplay, game INIs, etc.) to stick around.
//
// To avoid inconveniences in most cases, we always restore only the overridden settings.
static void RestoreSYSCONF()
{
// This layer contains the new SYSCONF settings (including any temporary settings).
auto layer = std::make_unique<Config::Layer>(ConfigLoaders::GenerateBaseConfigLoader());
for (const auto& setting : Config::SYSCONF_SETTINGS)
{
std::visit(
[&](auto& info) {
// If this setting was overridden, then we copy the base layer value back to the SYSCONF.
// Otherwise we leave the new value in the SYSCONF.
if (Config::GetActiveLayerForConfig(info) != Config::LayerType::Base)
layer->Set(info, Config::GetBase(info));
},
setting.config_info);
}
// Save the SYSCONF.
layer->Save();
Config::AddLayer(std::move(layer));
}

void RestoreConfig()
{
RestoreSYSCONF();
Config::ClearCurrentRunLayer();
Config::RemoveLayer(Config::LayerType::Movie);
Config::RemoveLayer(Config::LayerType::Netplay);
Config::RemoveLayer(Config::LayerType::GlobalGame);
Config::RemoveLayer(Config::LayerType::LocalGame);
SConfig::GetInstance().LoadSettingsFromSysconf();
SConfig::GetInstance().ResetRunningGameMetadata();
config_cache.RestoreConfig(&SConfig::GetInstance());
}
@@ -26,7 +26,9 @@ set(SRCS
Boot/DolReader.cpp
Boot/ElfReader.cpp
Config/GraphicsSettings.cpp
Config/MainSettings.cpp
Config/NetplaySettings.cpp
Config/SYSCONFSettings.cpp
ConfigLoaders/BaseConfigLoader.cpp
ConfigLoaders/GameConfigLoader.cpp
ConfigLoaders/IsSettingSaveable.cpp

0 comments on commit d896988

Please sign in to comment.