From ef811c64259f0b83aa72c99bad9d4e48082129f8 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Sat, 16 Oct 2021 02:07:18 -0400 Subject: [PATCH] settings: Remove std::chrono usage Alleviates the dependency on chrono for all files that include settings.h --- src/common/settings.h | 5 ++--- src/core/core.cpp | 5 +++-- src/core/hle/service/time/time_manager.cpp | 13 +++++++------ src/video_core/renderer_opengl/gl_device.cpp | 1 + src/yuzu/configuration/config.cpp | 7 ++----- src/yuzu/configuration/configure_system.cpp | 10 ++++------ src/yuzu_cmd/config.cpp | 3 +-- 7 files changed, 20 insertions(+), 24 deletions(-) diff --git a/src/common/settings.h b/src/common/settings.h index 402339443a..9ff4cf85db 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -7,7 +7,6 @@ #include #include #include -#include #include #include #include @@ -487,9 +486,9 @@ struct Values { // System Setting> rng_seed{std::optional(), "rng_seed"}; // Measured in seconds since epoch - std::optional custom_rtc; + std::optional custom_rtc; // Set on game boot, reset on stop. Seconds difference between current time and `custom_rtc` - std::chrono::seconds custom_rtc_differential; + s64 custom_rtc_differential; BasicSetting current_user{0, "current_user"}; RangedSetting language_index{1, 0, 17, "language_index"}; diff --git a/src/core/core.cpp b/src/core/core.cpp index 3042d611b6..3c75f42ae9 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -196,8 +196,9 @@ struct System::Impl { cpu_manager.Initialize(); core_timing.Initialize([&system]() { system.RegisterHostThread(); }); - const auto current_time = std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()); + const auto posix_time = std::chrono::system_clock::now().time_since_epoch(); + const auto current_time = + std::chrono::duration_cast(posix_time).count(); Settings::values.custom_rtc_differential = Settings::values.custom_rtc.value_or(current_time) - current_time; diff --git a/src/core/hle/service/time/time_manager.cpp b/src/core/hle/service/time/time_manager.cpp index 4bbc606a16..9c4c960ef4 100644 --- a/src/core/hle/service/time/time_manager.cpp +++ b/src/core/hle/service/time/time_manager.cpp @@ -13,18 +13,19 @@ #include "core/hle/service/time/time_manager.h" namespace Service::Time { - +namespace { constexpr Clock::TimeSpanType standard_network_clock_accuracy{0x0009356907420000ULL}; -static std::chrono::seconds GetSecondsSinceEpoch() { - return std::chrono::duration_cast( - std::chrono::system_clock::now().time_since_epoch()) + +s64 GetSecondsSinceEpoch() { + const auto time_since_epoch = std::chrono::system_clock::now().time_since_epoch(); + return std::chrono::duration_cast(time_since_epoch).count() + Settings::values.custom_rtc_differential; } -static s64 GetExternalRtcValue() { - return GetSecondsSinceEpoch().count() + TimeManager::GetExternalTimeZoneOffset(); +s64 GetExternalRtcValue() { + return GetSecondsSinceEpoch() + TimeManager::GetExternalTimeZoneOffset(); } +} // Anonymous namespace struct TimeManager::Impl final { explicit Impl(Core::System& system) diff --git a/src/video_core/renderer_opengl/gl_device.cpp b/src/video_core/renderer_opengl/gl_device.cpp index 9692b8e946..1e1d1d0209 100644 --- a/src/video_core/renderer_opengl/gl_device.cpp +++ b/src/video_core/renderer_opengl/gl_device.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 30a8641354..faea5dda11 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -918,8 +918,7 @@ void Config::ReadSystemValues() { const auto custom_rtc_enabled = ReadSetting(QStringLiteral("custom_rtc_enabled"), false).toBool(); if (custom_rtc_enabled) { - Settings::values.custom_rtc = - std::chrono::seconds(ReadSetting(QStringLiteral("custom_rtc"), 0).toULongLong()); + Settings::values.custom_rtc = ReadSetting(QStringLiteral("custom_rtc"), 0).toLongLong(); } else { Settings::values.custom_rtc = std::nullopt; } @@ -1450,9 +1449,7 @@ void Config::SaveSystemValues() { WriteSetting(QStringLiteral("custom_rtc_enabled"), Settings::values.custom_rtc.has_value(), false); WriteSetting(QStringLiteral("custom_rtc"), - QVariant::fromValue( - Settings::values.custom_rtc.value_or(std::chrono::seconds{}).count()), - 0); + QVariant::fromValue(Settings::values.custom_rtc.value_or(0)), 0); } WriteGlobalSetting(Settings::values.sound_index); diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index eea45f8eaa..56c762d643 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp @@ -65,8 +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.value_or( - std::chrono::seconds(QDateTime::currentSecsSinceEpoch())); + const auto rtc_time = Settings::values.custom_rtc.value_or(QDateTime::currentSecsSinceEpoch()); ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.GetValue().has_value()); ui->rng_seed_edit->setEnabled(Settings::values.rng_seed.GetValue().has_value() && @@ -75,7 +74,7 @@ void ConfigureSystem::SetConfiguration() { 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())); + ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time)); if (Settings::IsConfiguringGlobal()) { ui->combo_language->setCurrentIndex(Settings::values.language_index.GetValue()); @@ -108,10 +107,9 @@ void ConfigureSystem::ApplyConfiguration() { // to allow in-game time to be fast forwarded if (Settings::IsConfiguringGlobal()) { if (ui->custom_rtc_checkbox->isChecked()) { - Settings::values.custom_rtc = - std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch()); + Settings::values.custom_rtc = ui->custom_rtc_edit->dateTime().toSecsSinceEpoch(); if (system.IsPoweredOn()) { - const s64 posix_time{Settings::values.custom_rtc->count() + + const s64 posix_time{*Settings::values.custom_rtc + Service::Time::TimeManager::GetExternalTimeZoneOffset()}; system.GetTimeManager().UpdateLocalSystemClockTime(posix_time); } diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 8ca20679ad..0b8fde691f 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -412,8 +412,7 @@ void Config::ReadValues() { const auto custom_rtc_enabled = sdl2_config->GetBoolean("System", "custom_rtc_enabled", false); if (custom_rtc_enabled) { - Settings::values.custom_rtc = - std::chrono::seconds(sdl2_config->GetInteger("System", "custom_rtc", 0)); + Settings::values.custom_rtc = sdl2_config->GetInteger("System", "custom_rtc", 0); } else { Settings::values.custom_rtc = std::nullopt; }