general: Demote custom_rtc to regular setting

This commit is contained in:
lat9nq 2021-05-16 01:17:18 -04:00
parent ab2677f0a1
commit 339dc4f806
6 changed files with 30 additions and 58 deletions

View File

@ -136,7 +136,6 @@ void RestoreGlobalState(bool is_powered_on) {
values.region_index.SetGlobal(true);
values.time_zone_index.SetGlobal(true);
values.rng_seed.SetGlobal(true);
values.custom_rtc.SetGlobal(true);
values.sound_index.SetGlobal(true);
// Controls

View File

@ -157,7 +157,7 @@ struct Values {
// System
Setting<std::optional<u32>> rng_seed;
// Measured in seconds since epoch
Setting<std::optional<std::chrono::seconds>> custom_rtc;
std::optional<std::chrono::seconds> custom_rtc;
// Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc`
std::chrono::seconds custom_rtc_differential;

View File

@ -173,7 +173,7 @@ struct System::Impl {
const auto current_time = std::chrono::duration_cast<std::chrono::seconds>(
std::chrono::system_clock::now().time_since_epoch());
Settings::values.custom_rtc_differential =
Settings::values.custom_rtc.GetValue().value_or(current_time) - current_time;
Settings::values.custom_rtc.value_or(current_time) - current_time;
// Create a default fs if one doesn't already exist.
if (virtual_filesystem == nullptr)

View File

@ -868,17 +868,14 @@ void Config::ReadSystemValues() {
}
}
bool custom_rtc_enabled;
ReadSettingGlobal(custom_rtc_enabled, QStringLiteral("custom_rtc_enabled"), false);
bool custom_rtc_global =
global || qt_config->value(QStringLiteral("custom_rtc/use_global"), true).toBool();
Settings::values.custom_rtc.SetGlobal(custom_rtc_global);
if (global || !custom_rtc_global) {
if (global) {
const auto custom_rtc_enabled =
ReadSetting(QStringLiteral("custom_rtc_enabled"), false).toBool();
if (custom_rtc_enabled) {
Settings::values.custom_rtc.SetValue(
std::chrono::seconds(ReadSetting(QStringLiteral("custom_rtc"), 0).toULongLong()));
Settings::values.custom_rtc =
std::chrono::seconds(ReadSetting(QStringLiteral("custom_rtc"), 0).toULongLong());
} else {
Settings::values.custom_rtc.SetValue(std::nullopt);
Settings::values.custom_rtc = std::nullopt;
}
}
@ -1433,14 +1430,14 @@ void Config::SaveSystemValues() {
Settings::values.rng_seed.GetValue(global).value_or(0),
Settings::values.rng_seed.UsingGlobal(), 0);
WriteSettingGlobal(QStringLiteral("custom_rtc_enabled"),
Settings::values.custom_rtc.GetValue(global).has_value(),
Settings::values.custom_rtc.UsingGlobal(), false);
WriteSettingGlobal(
QStringLiteral("custom_rtc"),
if (global) {
WriteSetting(QStringLiteral("custom_rtc_enabled"), Settings::values.custom_rtc.has_value(),
false);
WriteSetting(QStringLiteral("custom_rtc"),
QVariant::fromValue<long long>(
Settings::values.custom_rtc.GetValue(global).value_or(std::chrono::seconds{}).count()),
Settings::values.custom_rtc.UsingGlobal(), 0);
Settings::values.custom_rtc.value_or(std::chrono::seconds{}).count()),
0);
}
WriteSettingGlobal(QStringLiteral("sound_index"), Settings::values.sound_index, 1);

View File

@ -65,7 +65,7 @@ void ConfigureSystem::SetConfiguration() {
QStringLiteral("%1")
.arg(Settings::values.rng_seed.GetValue().value_or(0), 8, 16, QLatin1Char{'0'})
.toUpper();
const auto rtc_time = Settings::values.custom_rtc.GetValue().value_or(
const auto rtc_time = Settings::values.custom_rtc.value_or(
std::chrono::seconds(QDateTime::currentSecsSinceEpoch()));
ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.GetValue().has_value());
@ -73,9 +73,8 @@ void ConfigureSystem::SetConfiguration() {
Settings::values.rng_seed.UsingGlobal());
ui->rng_seed_edit->setText(rng_seed);
ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.GetValue().has_value());
ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.GetValue().has_value() &&
Settings::values.rng_seed.UsingGlobal());
ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.has_value());
ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.has_value());
ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time.count()));
if (Settings::IsConfiguringGlobal()) {
@ -109,17 +108,17 @@ void ConfigureSystem::ApplyConfiguration() {
// Allow setting custom RTC even if system is powered on,
// to allow in-game time to be fast forwarded
if (Settings::values.custom_rtc.UsingGlobal()) {
if (Settings::IsConfiguringGlobal()) {
if (ui->custom_rtc_checkbox->isChecked()) {
Settings::values.custom_rtc.SetValue(
std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch()));
Settings::values.custom_rtc =
std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch());
if (system.IsPoweredOn()) {
const s64 posix_time{Settings::values.custom_rtc.GetValue()->count() +
const s64 posix_time{Settings::values.custom_rtc->count() +
Service::Time::TimeManager::GetExternalTimeZoneOffset()};
system.GetTimeManager().UpdateLocalSystemClockTime(posix_time);
}
} else {
Settings::values.custom_rtc.SetValue(std::nullopt);
Settings::values.custom_rtc = std::nullopt;
}
}
@ -163,26 +162,6 @@ void ConfigureSystem::ApplyConfiguration() {
case ConfigurationShared::CheckState::Count:
break;
}
switch (use_custom_rtc) {
case ConfigurationShared::CheckState::On:
case ConfigurationShared::CheckState::Off:
Settings::values.custom_rtc.SetGlobal(false);
if (ui->custom_rtc_checkbox->isChecked()) {
Settings::values.custom_rtc.SetValue(
std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch()));
} else {
Settings::values.custom_rtc.SetValue(std::nullopt);
}
break;
case ConfigurationShared::CheckState::Global:
Settings::values.custom_rtc.SetGlobal(false);
Settings::values.custom_rtc.SetValue(std::nullopt);
Settings::values.custom_rtc.SetGlobal(true);
break;
case ConfigurationShared::CheckState::Count:
break;
}
}
system.ApplySettings();
@ -213,8 +192,6 @@ void ConfigureSystem::SetupPerGameUI() {
ui->combo_sound->setEnabled(Settings::values.sound_index.UsingGlobal());
ui->rng_seed_checkbox->setEnabled(Settings::values.rng_seed.UsingGlobal());
ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.UsingGlobal());
ui->custom_rtc_checkbox->setEnabled(Settings::values.custom_rtc.UsingGlobal());
ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.UsingGlobal());
return;
}
@ -232,8 +209,7 @@ void ConfigureSystem::SetupPerGameUI() {
ui->rng_seed_checkbox, Settings::values.rng_seed.UsingGlobal(),
Settings::values.rng_seed.GetValue().has_value(),
Settings::values.rng_seed.GetValue(true).has_value(), use_rng_seed);
ConfigurationShared::SetColoredTristate(
ui->custom_rtc_checkbox, Settings::values.custom_rtc.UsingGlobal(),
Settings::values.custom_rtc.GetValue().has_value(),
Settings::values.custom_rtc.GetValue(true).has_value(), use_custom_rtc);
ui->custom_rtc_checkbox->setVisible(false);
ui->custom_rtc_edit->setVisible(false);
}

View File

@ -361,10 +361,10 @@ void Config::ReadValues() {
const auto custom_rtc_enabled = sdl2_config->GetBoolean("System", "custom_rtc_enabled", false);
if (custom_rtc_enabled) {
Settings::values.custom_rtc.SetValue(
std::chrono::seconds(sdl2_config->GetInteger("System", "custom_rtc", 0)));
Settings::values.custom_rtc =
std::chrono::seconds(sdl2_config->GetInteger("System", "custom_rtc", 0));
} else {
Settings::values.custom_rtc.SetValue(std::nullopt);
Settings::values.custom_rtc = std::nullopt;
}
Settings::values.language_index.SetValue(