mirror of
https://git.suyu.dev/suyu/suyu.git
synced 2024-11-30 10:42:47 +01:00
Merge pull request #7198 from ameerj/settings-chrono
settings: Remove std::chrono usage
This commit is contained in:
commit
c871320760
7 changed files with 20 additions and 24 deletions
|
@ -7,7 +7,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <array>
|
#include <array>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
@ -487,9 +486,9 @@ struct Values {
|
||||||
// System
|
// System
|
||||||
Setting<std::optional<u32>> rng_seed{std::optional<u32>(), "rng_seed"};
|
Setting<std::optional<u32>> rng_seed{std::optional<u32>(), "rng_seed"};
|
||||||
// Measured in seconds since epoch
|
// Measured in seconds since epoch
|
||||||
std::optional<std::chrono::seconds> custom_rtc;
|
std::optional<s64> custom_rtc;
|
||||||
// Set on game boot, reset on stop. Seconds difference between current time and `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<s32> current_user{0, "current_user"};
|
BasicSetting<s32> current_user{0, "current_user"};
|
||||||
RangedSetting<s32> language_index{1, 0, 17, "language_index"};
|
RangedSetting<s32> language_index{1, 0, 17, "language_index"};
|
||||||
|
|
|
@ -196,8 +196,9 @@ struct System::Impl {
|
||||||
cpu_manager.Initialize();
|
cpu_manager.Initialize();
|
||||||
core_timing.Initialize([&system]() { system.RegisterHostThread(); });
|
core_timing.Initialize([&system]() { system.RegisterHostThread(); });
|
||||||
|
|
||||||
const auto current_time = std::chrono::duration_cast<std::chrono::seconds>(
|
const auto posix_time = std::chrono::system_clock::now().time_since_epoch();
|
||||||
std::chrono::system_clock::now().time_since_epoch());
|
const auto current_time =
|
||||||
|
std::chrono::duration_cast<std::chrono::seconds>(posix_time).count();
|
||||||
Settings::values.custom_rtc_differential =
|
Settings::values.custom_rtc_differential =
|
||||||
Settings::values.custom_rtc.value_or(current_time) - current_time;
|
Settings::values.custom_rtc.value_or(current_time) - current_time;
|
||||||
|
|
||||||
|
|
|
@ -13,18 +13,19 @@
|
||||||
#include "core/hle/service/time/time_manager.h"
|
#include "core/hle/service/time/time_manager.h"
|
||||||
|
|
||||||
namespace Service::Time {
|
namespace Service::Time {
|
||||||
|
namespace {
|
||||||
constexpr Clock::TimeSpanType standard_network_clock_accuracy{0x0009356907420000ULL};
|
constexpr Clock::TimeSpanType standard_network_clock_accuracy{0x0009356907420000ULL};
|
||||||
|
|
||||||
static std::chrono::seconds GetSecondsSinceEpoch() {
|
s64 GetSecondsSinceEpoch() {
|
||||||
return std::chrono::duration_cast<std::chrono::seconds>(
|
const auto time_since_epoch = std::chrono::system_clock::now().time_since_epoch();
|
||||||
std::chrono::system_clock::now().time_since_epoch()) +
|
return std::chrono::duration_cast<std::chrono::seconds>(time_since_epoch).count() +
|
||||||
Settings::values.custom_rtc_differential;
|
Settings::values.custom_rtc_differential;
|
||||||
}
|
}
|
||||||
|
|
||||||
static s64 GetExternalRtcValue() {
|
s64 GetExternalRtcValue() {
|
||||||
return GetSecondsSinceEpoch().count() + TimeManager::GetExternalTimeZoneOffset();
|
return GetSecondsSinceEpoch() + TimeManager::GetExternalTimeZoneOffset();
|
||||||
}
|
}
|
||||||
|
} // Anonymous namespace
|
||||||
|
|
||||||
struct TimeManager::Impl final {
|
struct TimeManager::Impl final {
|
||||||
explicit Impl(Core::System& system)
|
explicit Impl(Core::System& system)
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <limits>
|
#include <limits>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <span>
|
#include <span>
|
||||||
|
#include <stdexcept>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <glad/glad.h>
|
#include <glad/glad.h>
|
||||||
|
|
|
@ -918,8 +918,7 @@ void Config::ReadSystemValues() {
|
||||||
const auto custom_rtc_enabled =
|
const auto custom_rtc_enabled =
|
||||||
ReadSetting(QStringLiteral("custom_rtc_enabled"), false).toBool();
|
ReadSetting(QStringLiteral("custom_rtc_enabled"), false).toBool();
|
||||||
if (custom_rtc_enabled) {
|
if (custom_rtc_enabled) {
|
||||||
Settings::values.custom_rtc =
|
Settings::values.custom_rtc = ReadSetting(QStringLiteral("custom_rtc"), 0).toLongLong();
|
||||||
std::chrono::seconds(ReadSetting(QStringLiteral("custom_rtc"), 0).toULongLong());
|
|
||||||
} else {
|
} else {
|
||||||
Settings::values.custom_rtc = std::nullopt;
|
Settings::values.custom_rtc = std::nullopt;
|
||||||
}
|
}
|
||||||
|
@ -1450,9 +1449,7 @@ void Config::SaveSystemValues() {
|
||||||
WriteSetting(QStringLiteral("custom_rtc_enabled"), Settings::values.custom_rtc.has_value(),
|
WriteSetting(QStringLiteral("custom_rtc_enabled"), Settings::values.custom_rtc.has_value(),
|
||||||
false);
|
false);
|
||||||
WriteSetting(QStringLiteral("custom_rtc"),
|
WriteSetting(QStringLiteral("custom_rtc"),
|
||||||
QVariant::fromValue<long long>(
|
QVariant::fromValue<long long>(Settings::values.custom_rtc.value_or(0)), 0);
|
||||||
Settings::values.custom_rtc.value_or(std::chrono::seconds{}).count()),
|
|
||||||
0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WriteGlobalSetting(Settings::values.sound_index);
|
WriteGlobalSetting(Settings::values.sound_index);
|
||||||
|
|
|
@ -65,8 +65,7 @@ void ConfigureSystem::SetConfiguration() {
|
||||||
QStringLiteral("%1")
|
QStringLiteral("%1")
|
||||||
.arg(Settings::values.rng_seed.GetValue().value_or(0), 8, 16, QLatin1Char{'0'})
|
.arg(Settings::values.rng_seed.GetValue().value_or(0), 8, 16, QLatin1Char{'0'})
|
||||||
.toUpper();
|
.toUpper();
|
||||||
const auto rtc_time = Settings::values.custom_rtc.value_or(
|
const auto rtc_time = Settings::values.custom_rtc.value_or(QDateTime::currentSecsSinceEpoch());
|
||||||
std::chrono::seconds(QDateTime::currentSecsSinceEpoch()));
|
|
||||||
|
|
||||||
ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.GetValue().has_value());
|
ui->rng_seed_checkbox->setChecked(Settings::values.rng_seed.GetValue().has_value());
|
||||||
ui->rng_seed_edit->setEnabled(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_checkbox->setChecked(Settings::values.custom_rtc.has_value());
|
||||||
ui->custom_rtc_edit->setEnabled(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()) {
|
if (Settings::IsConfiguringGlobal()) {
|
||||||
ui->combo_language->setCurrentIndex(Settings::values.language_index.GetValue());
|
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
|
// to allow in-game time to be fast forwarded
|
||||||
if (Settings::IsConfiguringGlobal()) {
|
if (Settings::IsConfiguringGlobal()) {
|
||||||
if (ui->custom_rtc_checkbox->isChecked()) {
|
if (ui->custom_rtc_checkbox->isChecked()) {
|
||||||
Settings::values.custom_rtc =
|
Settings::values.custom_rtc = ui->custom_rtc_edit->dateTime().toSecsSinceEpoch();
|
||||||
std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch());
|
|
||||||
if (system.IsPoweredOn()) {
|
if (system.IsPoweredOn()) {
|
||||||
const s64 posix_time{Settings::values.custom_rtc->count() +
|
const s64 posix_time{*Settings::values.custom_rtc +
|
||||||
Service::Time::TimeManager::GetExternalTimeZoneOffset()};
|
Service::Time::TimeManager::GetExternalTimeZoneOffset()};
|
||||||
system.GetTimeManager().UpdateLocalSystemClockTime(posix_time);
|
system.GetTimeManager().UpdateLocalSystemClockTime(posix_time);
|
||||||
}
|
}
|
||||||
|
|
|
@ -412,8 +412,7 @@ void Config::ReadValues() {
|
||||||
|
|
||||||
const auto custom_rtc_enabled = sdl2_config->GetBoolean("System", "custom_rtc_enabled", false);
|
const auto custom_rtc_enabled = sdl2_config->GetBoolean("System", "custom_rtc_enabled", false);
|
||||||
if (custom_rtc_enabled) {
|
if (custom_rtc_enabled) {
|
||||||
Settings::values.custom_rtc =
|
Settings::values.custom_rtc = sdl2_config->GetInteger("System", "custom_rtc", 0);
|
||||||
std::chrono::seconds(sdl2_config->GetInteger("System", "custom_rtc", 0));
|
|
||||||
} else {
|
} else {
|
||||||
Settings::values.custom_rtc = std::nullopt;
|
Settings::values.custom_rtc = std::nullopt;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue