diff options
| author | 2018-12-28 20:24:24 -0500 | |
|---|---|---|
| committer | 2019-01-07 19:19:40 -0500 | |
| commit | 05dbb47af51fb00826912155da85469cb74022db (patch) | |
| tree | 3162febaeb374ee6310491f75d94b2ec4918b5ae | |
| parent | time: Use custom RTC settings if applicable for game (diff) | |
| download | yuzu-05dbb47af51fb00826912155da85469cb74022db.tar.gz yuzu-05dbb47af51fb00826912155da85469cb74022db.tar.xz yuzu-05dbb47af51fb00826912155da85469cb74022db.zip | |
settings: Use std::chrono::seconds instead of s64 for RTC
| -rw-r--r-- | src/core/core.cpp | 3 | ||||
| -rw-r--r-- | src/core/hle/service/time/time.cpp | 10 | ||||
| -rw-r--r-- | src/core/settings.h | 8 | ||||
| -rw-r--r-- | src/yuzu/configuration/config.cpp | 6 | ||||
| -rw-r--r-- | src/yuzu/configuration/configure_system.cpp | 8 | ||||
| -rw-r--r-- | src/yuzu_cmd/config.cpp | 3 |
6 files changed, 21 insertions, 17 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index 7459c0851..123b11409 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -96,8 +96,7 @@ struct System::Impl { | |||
| 96 | kernel.Initialize(); | 96 | kernel.Initialize(); |
| 97 | 97 | ||
| 98 | const auto current_time = std::chrono::duration_cast<std::chrono::seconds>( | 98 | const auto current_time = std::chrono::duration_cast<std::chrono::seconds>( |
| 99 | std::chrono::system_clock::now().time_since_epoch()) | 99 | std::chrono::system_clock::now().time_since_epoch()); |
| 100 | .count(); | ||
| 101 | Settings::values.custom_rtc_differential = | 100 | Settings::values.custom_rtc_differential = |
| 102 | Settings::values.custom_rtc.value_or(current_time) - current_time; | 101 | Settings::values.custom_rtc.value_or(current_time) - current_time; |
| 103 | 102 | ||
diff --git a/src/core/hle/service/time/time.cpp b/src/core/hle/service/time/time.cpp index ef8c9f2b7..c13640ad8 100644 --- a/src/core/hle/service/time/time.cpp +++ b/src/core/hle/service/time/time.cpp | |||
| @@ -16,10 +16,9 @@ | |||
| 16 | 16 | ||
| 17 | namespace Service::Time { | 17 | namespace Service::Time { |
| 18 | 18 | ||
| 19 | static s64 GetSecondsSinceEpoch() { | 19 | static std::chrono::seconds GetSecondsSinceEpoch() { |
| 20 | return std::chrono::duration_cast<std::chrono::seconds>( | 20 | return std::chrono::duration_cast<std::chrono::seconds>( |
| 21 | std::chrono::system_clock::now().time_since_epoch()) | 21 | std::chrono::system_clock::now().time_since_epoch()) + |
| 22 | .count() + | ||
| 23 | Settings::values.custom_rtc_differential; | 22 | Settings::values.custom_rtc_differential; |
| 24 | } | 23 | } |
| 25 | 24 | ||
| @@ -76,7 +75,7 @@ public: | |||
| 76 | 75 | ||
| 77 | private: | 76 | private: |
| 78 | void GetCurrentTime(Kernel::HLERequestContext& ctx) { | 77 | void GetCurrentTime(Kernel::HLERequestContext& ctx) { |
| 79 | const s64 time_since_epoch{GetSecondsSinceEpoch()}; | 78 | const s64 time_since_epoch{GetSecondsSinceEpoch().count()}; |
| 80 | LOG_DEBUG(Service_Time, "called"); | 79 | LOG_DEBUG(Service_Time, "called"); |
| 81 | 80 | ||
| 82 | IPC::ResponseBuilder rb{ctx, 4}; | 81 | IPC::ResponseBuilder rb{ctx, 4}; |
| @@ -272,8 +271,7 @@ void Module::Interface::GetClockSnapshot(Kernel::HLERequestContext& ctx) { | |||
| 272 | IPC::RequestParser rp{ctx}; | 271 | IPC::RequestParser rp{ctx}; |
| 273 | const auto initial_type = rp.PopRaw<u8>(); | 272 | const auto initial_type = rp.PopRaw<u8>(); |
| 274 | 273 | ||
| 275 | const s64 time_since_epoch{GetSecondsSinceEpoch()}; | 274 | const s64 time_since_epoch{GetSecondsSinceEpoch().count()}; |
| 276 | |||
| 277 | const std::time_t time(time_since_epoch); | 275 | const std::time_t time(time_since_epoch); |
| 278 | const std::tm* tm = std::localtime(&time); | 276 | const std::tm* tm = std::localtime(&time); |
| 279 | if (tm == nullptr) { | 277 | if (tm == nullptr) { |
diff --git a/src/core/settings.h b/src/core/settings.h index 5b211a716..bb5aafa0c 100644 --- a/src/core/settings.h +++ b/src/core/settings.h | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | 6 | ||
| 7 | #include <array> | 7 | #include <array> |
| 8 | #include <atomic> | 8 | #include <atomic> |
| 9 | #include <chrono> | ||
| 9 | #include <map> | 10 | #include <map> |
| 10 | #include <optional> | 11 | #include <optional> |
| 11 | #include <string> | 12 | #include <string> |
| @@ -350,9 +351,10 @@ struct Values { | |||
| 350 | bool use_docked_mode; | 351 | bool use_docked_mode; |
| 351 | bool enable_nfc; | 352 | bool enable_nfc; |
| 352 | std::optional<u32> rng_seed; | 353 | std::optional<u32> rng_seed; |
| 353 | std::optional<s64> custom_rtc; // Measured in seconds since epoch | 354 | std::optional<std::chrono::seconds> custom_rtc; // Measured in seconds since epoch |
| 354 | s64 custom_rtc_differential; // Set on game boot, reset on stop. Seconds difference between | 355 | std::chrono::seconds |
| 355 | // current time and `custom_rtc` | 356 | custom_rtc_differential; // Set on game boot, reset on stop. Seconds difference between |
| 357 | // current time and `custom_rtc` | ||
| 356 | s32 current_user; | 358 | s32 current_user; |
| 357 | s32 language_index; | 359 | s32 language_index; |
| 358 | 360 | ||
diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index 6e034ef19..6c5284db5 100644 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp | |||
| @@ -428,7 +428,8 @@ void Config::ReadValues() { | |||
| 428 | 428 | ||
| 429 | const auto custom_rtc_enabled = qt_config->value("custom_rtc_enabled", false).toBool(); | 429 | const auto custom_rtc_enabled = qt_config->value("custom_rtc_enabled", false).toBool(); |
| 430 | if (custom_rtc_enabled) { | 430 | if (custom_rtc_enabled) { |
| 431 | Settings::values.custom_rtc = qt_config->value("custom_rtc", 0).toULongLong(); | 431 | Settings::values.custom_rtc = |
| 432 | std::chrono::seconds(qt_config->value("custom_rtc", 0).toULongLong()); | ||
| 432 | } else { | 433 | } else { |
| 433 | Settings::values.custom_rtc = std::nullopt; | 434 | Settings::values.custom_rtc = std::nullopt; |
| 434 | } | 435 | } |
| @@ -661,7 +662,8 @@ void Config::SaveValues() { | |||
| 661 | qt_config->setValue("rng_seed", Settings::values.rng_seed.value_or(0)); | 662 | qt_config->setValue("rng_seed", Settings::values.rng_seed.value_or(0)); |
| 662 | 663 | ||
| 663 | qt_config->setValue("custom_rtc_enabled", Settings::values.custom_rtc.has_value()); | 664 | qt_config->setValue("custom_rtc_enabled", Settings::values.custom_rtc.has_value()); |
| 664 | qt_config->setValue("custom_rtc", Settings::values.custom_rtc.value_or(0)); | 665 | qt_config->setValue("custom_rtc", |
| 666 | Settings::values.custom_rtc.value_or(std::chrono::seconds{}).count()); | ||
| 665 | 667 | ||
| 666 | qt_config->endGroup(); | 668 | qt_config->endGroup(); |
| 667 | 669 | ||
diff --git a/src/yuzu/configuration/configure_system.cpp b/src/yuzu/configuration/configure_system.cpp index 753db75d2..94e27349d 100644 --- a/src/yuzu/configuration/configure_system.cpp +++ b/src/yuzu/configuration/configure_system.cpp | |||
| @@ -77,8 +77,9 @@ void ConfigureSystem::setConfiguration() { | |||
| 77 | ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.has_value()); | 77 | ui->custom_rtc_checkbox->setChecked(Settings::values.custom_rtc.has_value()); |
| 78 | ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.has_value()); | 78 | ui->custom_rtc_edit->setEnabled(Settings::values.custom_rtc.has_value()); |
| 79 | 79 | ||
| 80 | const auto rtc_time = Settings::values.custom_rtc.value_or(QDateTime::currentSecsSinceEpoch()); | 80 | const auto rtc_time = Settings::values.custom_rtc.value_or( |
| 81 | ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time)); | 81 | std::chrono::seconds(QDateTime::currentSecsSinceEpoch())); |
| 82 | ui->custom_rtc_edit->setDateTime(QDateTime::fromSecsSinceEpoch(rtc_time.count())); | ||
| 82 | } | 83 | } |
| 83 | 84 | ||
| 84 | void ConfigureSystem::ReadSystemSettings() {} | 85 | void ConfigureSystem::ReadSystemSettings() {} |
| @@ -95,7 +96,8 @@ void ConfigureSystem::applyConfiguration() { | |||
| 95 | Settings::values.rng_seed = std::nullopt; | 96 | Settings::values.rng_seed = std::nullopt; |
| 96 | 97 | ||
| 97 | if (ui->custom_rtc_checkbox->isChecked()) | 98 | if (ui->custom_rtc_checkbox->isChecked()) |
| 98 | Settings::values.custom_rtc = ui->custom_rtc_edit->dateTime().toSecsSinceEpoch(); | 99 | Settings::values.custom_rtc = |
| 100 | std::chrono::seconds(ui->custom_rtc_edit->dateTime().toSecsSinceEpoch()); | ||
| 99 | else | 101 | else |
| 100 | Settings::values.custom_rtc = std::nullopt; | 102 | Settings::values.custom_rtc = std::nullopt; |
| 101 | 103 | ||
diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 8f3b74cdf..7a77f76e8 100644 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp | |||
| @@ -334,7 +334,8 @@ void Config::ReadValues() { | |||
| 334 | 334 | ||
| 335 | const auto custom_rtc_enabled = sdl2_config->GetBoolean("System", "custom_rtc_enabled", false); | 335 | const auto custom_rtc_enabled = sdl2_config->GetBoolean("System", "custom_rtc_enabled", false); |
| 336 | if (custom_rtc_enabled) { | 336 | if (custom_rtc_enabled) { |
| 337 | Settings::values.custom_rtc = sdl2_config->GetInteger("System", "custom_rtc", 0); | 337 | Settings::values.custom_rtc = |
| 338 | std::chrono::seconds(sdl2_config->GetInteger("System", "custom_rtc", 0)); | ||
| 338 | } else { | 339 | } else { |
| 339 | Settings::values.custom_rtc = std::nullopt; | 340 | Settings::values.custom_rtc = std::nullopt; |
| 340 | } | 341 | } |