summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar lat9nq2023-06-05 20:41:50 -0400
committerGravatar lat9nq2023-07-21 10:56:07 -0400
commit413316560784348b8ea2684d272b974fd0428267 (patch)
treed3a9015a0dcf29744d45d630246a19d1fae83dd9 /src
parentsettings: Pool SetGlobal functions (diff)
downloadyuzu-413316560784348b8ea2684d272b974fd0428267.tar.gz
yuzu-413316560784348b8ea2684d272b974fd0428267.tar.xz
yuzu-413316560784348b8ea2684d272b974fd0428267.zip
settings,core,config_sys: Remove optional type from custom_rtc, rng_seed
core: Fix MSVC errors
Diffstat (limited to 'src')
-rw-r--r--src/common/settings.cpp3
-rw-r--r--src/common/settings.h6
-rw-r--r--src/core/core.cpp4
-rw-r--r--src/core/hle/kernel/k_process.cpp3
-rw-r--r--src/core/hle/service/spl/spl_module.cpp3
-rw-r--r--src/yuzu/configuration/configure_system.cpp40
6 files changed, 33 insertions, 26 deletions
diff --git a/src/common/settings.cpp b/src/common/settings.cpp
index e3f30f7e3..696929479 100644
--- a/src/common/settings.cpp
+++ b/src/common/settings.cpp
@@ -62,7 +62,8 @@ void LogSettings() {
62 62
63 LOG_INFO(Config, "yuzu Configuration:"); 63 LOG_INFO(Config, "yuzu Configuration:");
64 log_setting("Controls_UseDockedMode", values.use_docked_mode.GetValue()); 64 log_setting("Controls_UseDockedMode", values.use_docked_mode.GetValue());
65 log_setting("System_RngSeed", values.rng_seed.GetValue().value_or(0)); 65 log_setting("System_RngSeedEnabled", values.rng_seed_enabled.GetValue());
66 log_setting("System_RngSeed", values.rng_seed.GetValue());
66 log_setting("System_DeviceName", values.device_name.GetValue()); 67 log_setting("System_DeviceName", values.device_name.GetValue());
67 log_setting("System_CurrentUser", values.current_user.GetValue()); 68 log_setting("System_CurrentUser", values.current_user.GetValue());
68 log_setting("System_LanguageIndex", values.language_index.GetValue()); 69 log_setting("System_LanguageIndex", values.language_index.GetValue());
diff --git a/src/common/settings.h b/src/common/settings.h
index 61d15467d..999f8b5be 100644
--- a/src/common/settings.h
+++ b/src/common/settings.h
@@ -505,10 +505,12 @@ struct Values {
505 SwitchableSetting<u8> bg_blue{0, "bg_blue"}; 505 SwitchableSetting<u8> bg_blue{0, "bg_blue"};
506 506
507 // System 507 // System
508 SwitchableSetting<std::optional<u32>> rng_seed{std::optional<u32>(), "rng_seed"}; 508 SwitchableSetting<bool> rng_seed_enabled{false, "rng_seed_enabled"};
509 SwitchableSetting<u32> rng_seed{0, "rng_seed"};
509 Setting<std::string> device_name{"Yuzu", "device_name"}; 510 Setting<std::string> device_name{"Yuzu", "device_name"};
510 // Measured in seconds since epoch 511 // Measured in seconds since epoch
511 std::optional<s64> custom_rtc; 512 SwitchableSetting<bool> custom_rtc_enabled{false, "custom_rtc_enabled"};
513 SwitchableSetting<s64> custom_rtc{0, "custom_rtc"};
512 // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc` 514 // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc`
513 s64 custom_rtc_differential; 515 s64 custom_rtc_differential;
514 516
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 9e3eb3795..da1baa892 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -149,7 +149,9 @@ struct System::Impl {
149 const auto current_time = 149 const auto current_time =
150 std::chrono::duration_cast<std::chrono::seconds>(posix_time).count(); 150 std::chrono::duration_cast<std::chrono::seconds>(posix_time).count();
151 Settings::values.custom_rtc_differential = 151 Settings::values.custom_rtc_differential =
152 Settings::values.custom_rtc.value_or(current_time) - current_time; 152 (Settings::values.custom_rtc_enabled ? Settings::values.custom_rtc.GetValue()
153 : current_time) -
154 current_time;
153 155
154 // Create a default fs if one doesn't already exist. 156 // Create a default fs if one doesn't already exist.
155 if (virtual_filesystem == nullptr) { 157 if (virtual_filesystem == nullptr) {
diff --git a/src/core/hle/kernel/k_process.cpp b/src/core/hle/kernel/k_process.cpp
index efe86ad27..ae064ee04 100644
--- a/src/core/hle/kernel/k_process.cpp
+++ b/src/core/hle/kernel/k_process.cpp
@@ -81,7 +81,8 @@ Result KProcess::Initialize(KProcess* process, Core::System& system, std::string
81 process->m_capabilities.InitializeForMetadatalessProcess(); 81 process->m_capabilities.InitializeForMetadatalessProcess();
82 process->m_is_initialized = true; 82 process->m_is_initialized = true;
83 83
84 std::mt19937 rng(Settings::values.rng_seed.GetValue().value_or(std::time(nullptr))); 84 std::mt19937 rng(Settings::values.rng_seed_enabled ? Settings::values.rng_seed.GetValue()
85 : static_cast<u32>(std::time(nullptr)));
85 std::uniform_int_distribution<u64> distribution; 86 std::uniform_int_distribution<u64> distribution;
86 std::generate(process->m_random_entropy.begin(), process->m_random_entropy.end(), 87 std::generate(process->m_random_entropy.begin(), process->m_random_entropy.end(),
87 [&] { return distribution(rng); }); 88 [&] { return distribution(rng); });
diff --git a/src/core/hle/service/spl/spl_module.cpp b/src/core/hle/service/spl/spl_module.cpp
index 0227d4393..cd631b2ea 100644
--- a/src/core/hle/service/spl/spl_module.cpp
+++ b/src/core/hle/service/spl/spl_module.cpp
@@ -19,7 +19,8 @@ namespace Service::SPL {
19Module::Interface::Interface(Core::System& system_, std::shared_ptr<Module> module_, 19Module::Interface::Interface(Core::System& system_, std::shared_ptr<Module> module_,
20 const char* name) 20 const char* name)
21 : ServiceFramework{system_, name}, module{std::move(module_)}, 21 : ServiceFramework{system_, name}, module{std::move(module_)},
22 rng(Settings::values.rng_seed.GetValue().value_or(std::time(nullptr))) {} 22 rng(Settings::values.rng_seed_enabled ? Settings::values.rng_seed.GetValue()
23 : static_cast<u32>(std::time(nullptr))) {}
23 24
24Module::Interface::~Interface() = default; 25Module::Interface::~Interface() = default;
25 26
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp
index f1ae312c6..c892635b8 100644
--- a/src/yuzu/configuration/configure_system.cpp
+++ b/src/yuzu/configuration/configure_system.cpp
@@ -95,19 +95,20 @@ void ConfigureSystem::RetranslateUI() {
95 95
96void ConfigureSystem::SetConfiguration() { 96void ConfigureSystem::SetConfiguration() {
97 enabled = !system.IsPoweredOn(); 97 enabled = !system.IsPoweredOn();
98 const auto rng_seed = 98 const auto rng_seed = QStringLiteral("%1")
99 QStringLiteral("%1") 99 .arg(Settings::values.rng_seed.GetValue(), 8, 16, QLatin1Char{'0'})
100 .arg(Settings::values.rng_seed.GetValue().value_or(0), 8, 16, QLatin1Char{'0'}) 100 .toUpper();
101 .toUpper(); 101 const auto rtc_time = Settings::values.custom_rtc_enabled
102 const auto rtc_time = Settings::values.custom_rtc.value_or(QDateTime::currentSecsSinceEpoch()); 102 ? Settings::values.custom_rtc.GetValue()
103 103 : QDateTime::currentSecsSinceEpoch();
104 ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.GetValue().has_value()); 104
105 ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.GetValue().has_value() && 105 ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed_enabled.GetValue());
106 ui->rng_seed_edit->setEnabled(Settings::values.rng_seed_enabled.GetValue() &&
106 Settings::values.rng_seed.UsingGlobal()); 107 Settings::values.rng_seed.UsingGlobal());
107 ui->rng_seed_edit->setText(rng_seed); 108 ui->rng_seed_edit->setText(rng_seed);
108 109
109 ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.has_value()); 110 ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc_enabled.GetValue());
110 ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.has_value()); 111 ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc_enabled.GetValue());
111 ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time)); 112 ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time));
112 ui->device_name_edit->setText( 113 ui->device_name_edit->setText(
113 QString::fromUtf8(Settings::values.device_name.GetValue().c_str())); 114 QString::fromUtf8(Settings::values.device_name.GetValue().c_str()));
@@ -142,13 +143,15 @@ void ConfigureSystem::ApplyConfiguration() {
142 // to allow in-game time to be fast forwarded 143 // to allow in-game time to be fast forwarded
143 if (Settings::IsConfiguringGlobal()) { 144 if (Settings::IsConfiguringGlobal()) {
144 if (ui->custom_rtc_checkbox->isChecked()) { 145 if (ui->custom_rtc_checkbox->isChecked()) {
146 Settings::values.custom_rtc_enabled = true;
145 Settings::values.custom_rtc = ui->custom_rtc_edit->dateTime().toSecsSinceEpoch(); 147 Settings::values.custom_rtc = ui->custom_rtc_edit->dateTime().toSecsSinceEpoch();
146 if (system.IsPoweredOn()) { 148 if (system.IsPoweredOn()) {
147 const s64 posix_time{*Settings::values.custom_rtc}; 149 const s64 posix_time{Settings::values.custom_rtc.GetValue() +
150 Service::Time::TimeManager::GetExternalTimeZoneOffset()};
148 system.GetTimeManager().UpdateLocalSystemClockTime(posix_time); 151 system.GetTimeManager().UpdateLocalSystemClockTime(posix_time);
149 } 152 }
150 } else { 153 } else {
151 Settings::values.custom_rtc = std::nullopt; 154 Settings::values.custom_rtc_enabled = false;
152 } 155 }
153 } 156 }
154 157
@@ -169,26 +172,23 @@ void ConfigureSystem::ApplyConfiguration() {
169 if (Settings::IsConfiguringGlobal()) { 172 if (Settings::IsConfiguringGlobal()) {
170 // Guard if during game and set to game-specific value 173 // Guard if during game and set to game-specific value
171 if (Settings::values.rng_seed.UsingGlobal()) { 174 if (Settings::values.rng_seed.UsingGlobal()) {
175 Settings::values.rng_seed_enabled = ui->rng_seed_checkbox->isChecked();
172 if (ui->rng_seed_checkbox->isChecked()) { 176 if (ui->rng_seed_checkbox->isChecked()) {
173 Settings::values.rng_seed.SetValue(ui->rng_seed_edit->text().toUInt(nullptr, 16)); 177 Settings::values.rng_seed.SetValue(ui->rng_seed_edit->text().toUInt(nullptr, 16));
174 } else {
175 Settings::values.rng_seed.SetValue(std::nullopt);
176 } 178 }
177 } 179 }
178 } else { 180 } else {
179 switch (use_rng_seed) { 181 switch (use_rng_seed) {
180 case ConfigurationShared::CheckState::On: 182 case ConfigurationShared::CheckState::On:
181 case ConfigurationShared::CheckState::Off: 183 case ConfigurationShared::CheckState::Off:
184 Settings::values.rng_seed_enabled.SetGlobal(false);
182 Settings::values.rng_seed.SetGlobal(false); 185 Settings::values.rng_seed.SetGlobal(false);
183 if (ui->rng_seed_checkbox->isChecked()) { 186 if (ui->rng_seed_checkbox->isChecked()) {
184 Settings::values.rng_seed.SetValue(ui->rng_seed_edit->text().toUInt(nullptr, 16)); 187 Settings::values.rng_seed.SetValue(ui->rng_seed_edit->text().toUInt(nullptr, 16));
185 } else {
186 Settings::values.rng_seed.SetValue(std::nullopt);
187 } 188 }
188 break; 189 break;
189 case ConfigurationShared::CheckState::Global: 190 case ConfigurationShared::CheckState::Global:
190 Settings::values.rng_seed.SetGlobal(false); 191 Settings::values.rng_seed_enabled.SetGlobal(true);
191 Settings::values.rng_seed.SetValue(std::nullopt);
192 Settings::values.rng_seed.SetGlobal(true); 192 Settings::values.rng_seed.SetGlobal(true);
193 break; 193 break;
194 case ConfigurationShared::CheckState::Count: 194 case ConfigurationShared::CheckState::Count:
@@ -217,8 +217,8 @@ void ConfigureSystem::SetupPerGameUI() {
217 217
218 ConfigurationShared::SetColoredTristate( 218 ConfigurationShared::SetColoredTristate(
219 ui->rng_seed_checkbox, Settings::values.rng_seed.UsingGlobal(), 219 ui->rng_seed_checkbox, Settings::values.rng_seed.UsingGlobal(),
220 Settings::values.rng_seed.GetValue().has_value(), 220 Settings::values.rng_seed_enabled.GetValue(),
221 Settings::values.rng_seed.GetValue(true).has_value(), use_rng_seed); 221 Settings::values.rng_seed_enabled.GetValue(true), use_rng_seed);
222 222
223 ConfigurationShared::SetColoredTristate(ui->use_unsafe_extended_memory_layout, 223 ConfigurationShared::SetColoredTristate(ui->use_unsafe_extended_memory_layout,
224 Settings::values.use_unsafe_extended_memory_layout, 224 Settings::values.use_unsafe_extended_memory_layout,