Config: Remove recursive layer

This commit is contained in:
MerryMage 2017-10-29 19:17:58 +00:00
parent f612569718
commit c8f970e2b0
13 changed files with 30 additions and 139 deletions

View File

@ -17,11 +17,6 @@ static std::list<ConfigChangedCallback> s_callbacks;
void InvokeConfigChangedCallbacks();
Section* GetOrCreateSection(System system, const std::string& section_name)
{
return s_layers[LayerType::Meta]->GetOrCreateSection(system, section_name);
}
Layers* GetLayers()
{
return &s_layers;
@ -83,8 +78,6 @@ void Init()
{
// These layers contain temporary values
ClearCurrentRunLayer();
// This layer always has to exist
s_layers[LayerType::Meta] = std::make_unique<RecursiveLayer>();
}
void Shutdown()
@ -129,7 +122,6 @@ const std::string& GetLayerName(LayerType layer)
{LayerType::Movie, "Movie"},
{LayerType::CommandLine, "Command Line"},
{LayerType::CurrentRun, "Current Run"},
{LayerType::Meta, "Top"},
};
return layer_to_name.at(layer);
}

View File

@ -36,9 +36,6 @@ struct ConfigInfo
using Layers = std::map<LayerType, std::unique_ptr<Layer>>;
using ConfigChangedCallback = std::function<void()>;
// Common function used for getting configuration
Section* GetOrCreateSection(System system, const std::string& section_name);
// Layer management
Layers* GetLayers();
void AddLayer(std::unique_ptr<Layer> layer);
@ -66,13 +63,15 @@ LayerType GetActiveLayerForConfig(const ConfigLocation&);
template <typename T>
T Get(LayerType layer, const ConfigInfo<T>& info)
{
if (layer == LayerType::Meta)
return Get(info);
return GetLayer(layer)->Get(info);
}
template <typename T>
T Get(const ConfigInfo<T>& info)
{
return Get(LayerType::Meta, info);
return GetLayer(GetActiveLayerForConfig(info.location))->Get(info);
}
template <typename T>

View File

@ -34,7 +34,6 @@ enum class System
};
constexpr std::array<LayerType, 7> SEARCH_ORDER{{
// Skip the meta layer
LayerType::CurrentRun, LayerType::CommandLine, LayerType::Movie, LayerType::Netplay,
LayerType::LocalGame, LayerType::GlobalGame, LayerType::Base,
}};

View File

@ -67,15 +67,7 @@ Section* Layer::GetOrCreateSection(System system, const std::string& section_nam
Section* section = GetSection(system, section_name);
if (!section)
{
if (m_layer == LayerType::Meta)
{
m_sections[system].emplace_back(
std::make_unique<RecursiveSection>(m_layer, system, section_name));
}
else
{
m_sections[system].emplace_back(std::make_unique<Section>(m_layer, system, section_name));
}
m_sections[system].emplace_back(std::make_unique<Section>(m_layer, system, section_name));
section = m_sections[system].back().get();
}
return section;
@ -124,26 +116,4 @@ void Layer::ClearDirty()
[](auto& section) { section->ClearDirty(); });
});
}
RecursiveLayer::RecursiveLayer() : Layer(LayerType::Meta)
{
}
Section* RecursiveLayer::GetSection(System system, const std::string& section_name)
{
// Always queries backwards recursively, so it doesn't matter if it exists or not on this layer
return GetOrCreateSection(system, section_name);
}
Section* RecursiveLayer::GetOrCreateSection(System system, const std::string& section_name)
{
Section* section = Layer::GetSection(system, section_name);
if (!section)
{
m_sections[system].emplace_back(
std::make_unique<RecursiveSection>(m_layer, system, section_name));
section = m_sections[system].back().get();
}
return section;
}
}

View File

@ -84,12 +84,4 @@ protected:
const LayerType m_layer;
std::unique_ptr<ConfigLayerLoader> m_loader;
};
class RecursiveLayer final : public Layer
{
public:
RecursiveLayer();
Section* GetSection(System system, const std::string& section_name) override;
Section* GetOrCreateSection(System system, const std::string& section_name) override;
};
}
} // namespace Config

View File

@ -246,51 +246,4 @@ void Section::ClearDirty()
{
m_dirty = false;
}
RecursiveSection::RecursiveSection(LayerType layer, System system, const std::string& name)
: Section(layer, system, name)
{
}
bool RecursiveSection::Exists(const std::string& key) const
{
auto layers_it = Config::GetLayers()->find(LayerType::Meta);
do
{
const Section* layer_section = layers_it->second->GetSection(m_system, m_name);
if (layer_section && layer_section->Exists(key))
{
return true;
}
} while (--layers_it != Config::GetLayers()->end());
return false;
}
bool RecursiveSection::Get(const std::string& key, std::string* value,
const std::string& default_value) const
{
for (auto layer_id : SEARCH_ORDER)
{
auto layers_it = Config::GetLayers()->find(layer_id);
if (layers_it == Config::GetLayers()->end())
continue;
const Section* layer_section = layers_it->second->GetSection(m_system, m_name);
if (layer_section && layer_section->Exists(key))
{
return layer_section->Get(key, value, default_value);
}
}
return Section::Get(key, value, default_value);
}
void RecursiveSection::Set(const std::string& key, const std::string& value)
{
// The RecursiveSection can't set since it is used to recursively get values from the layer
// map.
// It is only a part of the meta layer, and the meta layer isn't allowed to set any values.
_assert_msg_(COMMON, false, "Don't try to set values here!");
}
}

View File

@ -96,18 +96,4 @@ protected:
std::vector<std::string> m_lines;
};
// Only to be used with the meta-layer
class RecursiveSection final : public Section
{
public:
RecursiveSection(LayerType layer, System system, const std::string& name);
bool Exists(const std::string& key) const override;
bool Get(const std::string& key, std::string* value,
const std::string& default_value = NULL_STRING) const override;
void Set(const std::string& key, const std::string& value) override;
};
}

View File

@ -376,7 +376,7 @@ bool BootCore(std::unique_ptr<BootParameters> boot)
// Ensure any new settings are written to the SYSCONF
if (StartUp.bWii)
ConfigLoaders::SaveToSYSCONF(Config::GetLayer(Config::LayerType::Meta));
ConfigLoaders::SaveToSYSCONF(Config::LayerType::Meta);
const bool load_ipl = !StartUp.bWii && !StartUp.bHLE_BS2 &&
std::holds_alternative<BootParameters::Disc>(boot->parameters);

View File

@ -26,7 +26,7 @@
namespace ConfigLoaders
{
void SaveToSYSCONF(Config::Layer* layer)
void SaveToSYSCONF(Config::LayerType layer)
{
if (Core::IsRunning())
return;
@ -40,9 +40,9 @@ void SaveToSYSCONF(Config::Layer* layer)
const std::string key = info.location.section + "." + info.location.key;
if (setting.type == SysConf::Entry::Type::Long)
sysconf.SetData<u32>(key, setting.type, layer->Get(info));
sysconf.SetData<u32>(key, setting.type, Config::Get(layer, info));
else if (setting.type == SysConf::Entry::Type::Byte)
sysconf.SetData<u8>(key, setting.type, static_cast<u8>(layer->Get(info)));
sysconf.SetData<u8>(key, setting.type, static_cast<u8>(Config::Get(layer, info)));
},
setting.config_info);
}
@ -106,7 +106,7 @@ public:
{
if (system.first == Config::System::SYSCONF)
{
SaveToSYSCONF(config_layer);
SaveToSYSCONF(config_layer->GetLayer());
continue;
}

View File

@ -9,11 +9,11 @@
namespace Config
{
class ConfigLayerLoader;
class Layer;
enum class LayerType;
}
namespace ConfigLoaders
{
void SaveToSYSCONF(Config::Layer* layer);
void SaveToSYSCONF(Config::LayerType layer);
std::unique_ptr<Config::ConfigLayerLoader> GenerateBaseConfigLoader();
}

View File

@ -46,27 +46,27 @@ static void LoadFromDTM(Config::Layer* config_layer, Movie::DTMHeader* dtm)
config_layer->Set(Config::GFX_HACK_EFB_EMULATE_FORMAT_CHANGES, dtm->bEFBEmulateFormatChanges);
}
void SaveToDTM(Config::Layer* config_layer, Movie::DTMHeader* dtm)
void SaveToDTM(Movie::DTMHeader* dtm)
{
dtm->bDualCore = config_layer->Get(Config::MAIN_CPU_THREAD);
dtm->bDSPHLE = config_layer->Get(Config::MAIN_DSP_HLE);
dtm->bFastDiscSpeed = config_layer->Get(Config::MAIN_FAST_DISC_SPEED);
dtm->CPUCore = config_layer->Get(Config::MAIN_CPU_CORE);
dtm->bSyncGPU = config_layer->Get(Config::MAIN_SYNC_GPU);
const std::string video_backend = config_layer->Get(Config::MAIN_GFX_BACKEND);
dtm->bDualCore = Config::Get(Config::MAIN_CPU_THREAD);
dtm->bDSPHLE = Config::Get(Config::MAIN_DSP_HLE);
dtm->bFastDiscSpeed = Config::Get(Config::MAIN_FAST_DISC_SPEED);
dtm->CPUCore = Config::Get(Config::MAIN_CPU_CORE);
dtm->bSyncGPU = Config::Get(Config::MAIN_SYNC_GPU);
const std::string video_backend = Config::Get(Config::MAIN_GFX_BACKEND);
dtm->bProgressive = config_layer->Get(Config::SYSCONF_PROGRESSIVE_SCAN);
dtm->bPAL60 = config_layer->Get(Config::SYSCONF_PAL60);
dtm->bProgressive = Config::Get(Config::SYSCONF_PROGRESSIVE_SCAN);
dtm->bPAL60 = Config::Get(Config::SYSCONF_PAL60);
if (dtm->bWii)
dtm->language = config_layer->Get(Config::SYSCONF_LANGUAGE);
dtm->language = Config::Get(Config::SYSCONF_LANGUAGE);
else
dtm->language = config_layer->Get(Config::MAIN_GC_LANGUAGE);
dtm->language = Config::Get(Config::MAIN_GC_LANGUAGE);
dtm->bUseXFB = config_layer->Get(Config::GFX_USE_XFB);
dtm->bUseRealXFB = config_layer->Get(Config::GFX_USE_REAL_XFB);
dtm->bEFBAccessEnable = config_layer->Get(Config::GFX_HACK_EFB_ACCESS_ENABLE);
dtm->bSkipEFBCopyToRam = config_layer->Get(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM);
dtm->bEFBEmulateFormatChanges = config_layer->Get(Config::GFX_HACK_EFB_EMULATE_FORMAT_CHANGES);
dtm->bUseXFB = Config::Get(Config::GFX_USE_XFB);
dtm->bUseRealXFB = Config::Get(Config::GFX_USE_REAL_XFB);
dtm->bEFBAccessEnable = Config::Get(Config::GFX_HACK_EFB_ACCESS_ENABLE);
dtm->bSkipEFBCopyToRam = Config::Get(Config::GFX_HACK_SKIP_EFB_COPY_TO_RAM);
dtm->bEFBEmulateFormatChanges = Config::Get(Config::GFX_HACK_EFB_EMULATE_FORMAT_CHANGES);
// This never used the regular config
dtm->bSkipIdle = true;

View File

@ -30,6 +30,6 @@ private:
Movie::DTMHeader* m_header;
};
void SaveToDTM(Config::Layer* layer, Movie::DTMHeader* header);
void SaveToDTM(Movie::DTMHeader* header);
std::unique_ptr<Config::ConfigLayerLoader> GenerateMovieConfigLoader(Movie::DTMHeader* header);
}

View File

@ -1306,7 +1306,7 @@ void SaveRecording(const std::string& filename)
header.recordingStartTime = s_recordingStartTime;
header.bSaveConfig = true;
ConfigLoaders::SaveToDTM(Config::GetLayer(Config::LayerType::Meta), &header);
ConfigLoaders::SaveToDTM(&header);
header.memcards = s_memcards;
header.bClearSave = s_bClearSave;
header.bNetPlay = s_bNetPlay;