Store pointers in Config::SYSCONF_SETTINGS

Not strictly necessary, but it reduces memory usage a little,
and the next commit will make copying an Info object slower.
This commit is contained in:
JosJuice 2020-09-20 19:11:20 +02:00
parent b285991b88
commit 633ab2dd7c
4 changed files with 25 additions and 25 deletions

View File

@ -472,11 +472,11 @@ static void RestoreSYSCONF()
for (const auto& setting : Config::SYSCONF_SETTINGS)
{
std::visit(
[&](auto& info) {
[&](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)
Config::SetBase(info, temp_layer.Get(info));
if (Config::GetActiveLayerForConfig(*info) == Config::LayerType::Base)
Config::SetBase(*info, temp_layer.Get(*info));
},
setting.config_info);
}

View File

@ -24,15 +24,15 @@ const Info<u32> SYSCONF_SPEAKER_VOLUME{{System::SYSCONF, "BT", "SPKV"}, 0x58};
const Info<bool> SYSCONF_WIIMOTE_MOTOR{{System::SYSCONF, "BT", "MOT"}, true};
const std::array<SYSCONFSetting, 11> SYSCONF_SETTINGS{
{{SYSCONF_SCREENSAVER, SysConf::Entry::Type::Byte},
{SYSCONF_LANGUAGE, SysConf::Entry::Type::Byte},
{SYSCONF_COUNTRY, SysConf::Entry::Type::BigArray},
{SYSCONF_WIDESCREEN, SysConf::Entry::Type::Byte},
{SYSCONF_PROGRESSIVE_SCAN, SysConf::Entry::Type::Byte},
{SYSCONF_PAL60, SysConf::Entry::Type::Byte},
{SYSCONF_SOUND_MODE, SysConf::Entry::Type::Byte},
{SYSCONF_SENSOR_BAR_POSITION, SysConf::Entry::Type::Byte},
{SYSCONF_SENSOR_BAR_SENSITIVITY, SysConf::Entry::Type::Long},
{SYSCONF_SPEAKER_VOLUME, SysConf::Entry::Type::Byte},
{SYSCONF_WIIMOTE_MOTOR, SysConf::Entry::Type::Byte}}};
{{&SYSCONF_SCREENSAVER, SysConf::Entry::Type::Byte},
{&SYSCONF_LANGUAGE, SysConf::Entry::Type::Byte},
{&SYSCONF_COUNTRY, SysConf::Entry::Type::BigArray},
{&SYSCONF_WIDESCREEN, SysConf::Entry::Type::Byte},
{&SYSCONF_PROGRESSIVE_SCAN, SysConf::Entry::Type::Byte},
{&SYSCONF_PAL60, SysConf::Entry::Type::Byte},
{&SYSCONF_SOUND_MODE, SysConf::Entry::Type::Byte},
{&SYSCONF_SENSOR_BAR_POSITION, SysConf::Entry::Type::Byte},
{&SYSCONF_SENSOR_BAR_SENSITIVITY, SysConf::Entry::Type::Long},
{&SYSCONF_SPEAKER_VOLUME, SysConf::Entry::Type::Byte},
{&SYSCONF_WIIMOTE_MOTOR, SysConf::Entry::Type::Byte}}};
} // namespace Config

View File

@ -33,7 +33,7 @@ extern const Info<bool> SYSCONF_WIIMOTE_MOTOR;
struct SYSCONFSetting
{
std::variant<Info<u32>, Info<bool>> config_info;
std::variant<const Info<u32>*, const Info<bool>*> config_info;
SysConf::Entry::Type type;
};

View File

@ -40,16 +40,16 @@ void SaveToSYSCONF(Config::LayerType layer)
for (const Config::SYSCONFSetting& setting : Config::SYSCONF_SETTINGS)
{
std::visit(
[layer, &setting, &sysconf](auto& info) {
const std::string key = info.GetLocation().section + "." + info.GetLocation().key;
[layer, &setting, &sysconf](auto* info) {
const std::string key = info->GetLocation().section + "." + info->GetLocation().key;
if (setting.type == SysConf::Entry::Type::Long)
{
sysconf.SetData<u32>(key, setting.type, Config::Get(layer, 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>(Config::Get(layer, info)));
sysconf.SetData<u8>(key, setting.type, static_cast<u8>(Config::Get(layer, *info)));
}
else if (setting.type == SysConf::Entry::Type::BigArray)
{
@ -58,7 +58,7 @@ void SaveToSYSCONF(Config::LayerType layer)
SysConf::Entry* entry = sysconf.GetOrAddEntry(key, setting.type);
if (entry->bytes.size() < 0x1007 + 1)
entry->bytes.resize(0x1007 + 1);
*reinterpret_cast<u32*>(entry->bytes.data()) = Config::Get(layer, info);
*reinterpret_cast<u32*>(entry->bytes.data()) = Config::Get(layer, *info);
}
},
setting.config_info);
@ -179,22 +179,22 @@ private:
for (const Config::SYSCONFSetting& setting : Config::SYSCONF_SETTINGS)
{
std::visit(
[&](auto& info) {
const Config::Location location = info.GetLocation();
[&](auto* info) {
const Config::Location location = info->GetLocation();
const std::string key = location.section + "." + location.key;
if (setting.type == SysConf::Entry::Type::Long)
{
layer->Set(location, sysconf.GetData<u32>(key, info.GetDefaultValue()));
layer->Set(location, sysconf.GetData<u32>(key, info->GetDefaultValue()));
}
else if (setting.type == SysConf::Entry::Type::Byte)
{
layer->Set(location, sysconf.GetData<u8>(key, info.GetDefaultValue()));
layer->Set(location, sysconf.GetData<u8>(key, info->GetDefaultValue()));
}
else if (setting.type == SysConf::Entry::Type::BigArray)
{
// Somewhat hacky support for IPL.SADR. The setting only stores the
// first 4 bytes even thought the SYSCONF entry is much bigger.
u32 value = info.GetDefaultValue();
u32 value = info->GetDefaultValue();
SysConf::Entry* entry = sysconf.GetEntry(key);
if (entry)
{