diff options
Diffstat (limited to 'src/core/core.cpp')
| -rw-r--r-- | src/core/core.cpp | 89 |
1 files changed, 59 insertions, 30 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp index 461eea9c8..33afc6049 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -39,9 +39,14 @@ | |||
| 39 | #include "core/hle/service/apm/apm_controller.h" | 39 | #include "core/hle/service/apm/apm_controller.h" |
| 40 | #include "core/hle/service/filesystem/filesystem.h" | 40 | #include "core/hle/service/filesystem/filesystem.h" |
| 41 | #include "core/hle/service/glue/glue_manager.h" | 41 | #include "core/hle/service/glue/glue_manager.h" |
| 42 | #include "core/hle/service/glue/time/static.h" | ||
| 43 | #include "core/hle/service/psc/time/static.h" | ||
| 44 | #include "core/hle/service/psc/time/steady_clock.h" | ||
| 45 | #include "core/hle/service/psc/time/system_clock.h" | ||
| 46 | #include "core/hle/service/psc/time/time_zone_service.h" | ||
| 42 | #include "core/hle/service/service.h" | 47 | #include "core/hle/service/service.h" |
| 48 | #include "core/hle/service/set/system_settings_server.h" | ||
| 43 | #include "core/hle/service/sm/sm.h" | 49 | #include "core/hle/service/sm/sm.h" |
| 44 | #include "core/hle/service/time/time_manager.h" | ||
| 45 | #include "core/internal_network/network.h" | 50 | #include "core/internal_network/network.h" |
| 46 | #include "core/loader/loader.h" | 51 | #include "core/loader/loader.h" |
| 47 | #include "core/memory.h" | 52 | #include "core/memory.h" |
| @@ -129,8 +134,8 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, | |||
| 129 | 134 | ||
| 130 | struct System::Impl { | 135 | struct System::Impl { |
| 131 | explicit Impl(System& system) | 136 | explicit Impl(System& system) |
| 132 | : kernel{system}, fs_controller{system}, hid_core{}, room_network{}, cpu_manager{system}, | 137 | : kernel{system}, fs_controller{system}, hid_core{}, room_network{}, |
| 133 | reporter{system}, applet_manager{system}, profile_manager{}, time_manager{system} {} | 138 | cpu_manager{system}, reporter{system}, applet_manager{system}, profile_manager{} {} |
| 134 | 139 | ||
| 135 | void Initialize(System& system) { | 140 | void Initialize(System& system) { |
| 136 | device_memory = std::make_unique<Core::DeviceMemory>(); | 141 | device_memory = std::make_unique<Core::DeviceMemory>(); |
| @@ -142,8 +147,6 @@ struct System::Impl { | |||
| 142 | core_timing.SetMulticore(is_multicore); | 147 | core_timing.SetMulticore(is_multicore); |
| 143 | core_timing.Initialize([&system]() { system.RegisterHostThread(); }); | 148 | core_timing.Initialize([&system]() { system.RegisterHostThread(); }); |
| 144 | 149 | ||
| 145 | RefreshTime(); | ||
| 146 | |||
| 147 | // Create a default fs if one doesn't already exist. | 150 | // Create a default fs if one doesn't already exist. |
| 148 | if (virtual_filesystem == nullptr) { | 151 | if (virtual_filesystem == nullptr) { |
| 149 | virtual_filesystem = std::make_shared<FileSys::RealVfsFilesystem>(); | 152 | virtual_filesystem = std::make_shared<FileSys::RealVfsFilesystem>(); |
| @@ -181,14 +184,57 @@ struct System::Impl { | |||
| 181 | Initialize(system); | 184 | Initialize(system); |
| 182 | } | 185 | } |
| 183 | 186 | ||
| 184 | void RefreshTime() { | 187 | void RefreshTime(System& system) { |
| 188 | if (!system.IsPoweredOn()) { | ||
| 189 | return; | ||
| 190 | } | ||
| 191 | |||
| 192 | auto settings_service = | ||
| 193 | system.ServiceManager().GetService<Service::Set::ISystemSettingsServer>("set:sys", | ||
| 194 | true); | ||
| 195 | auto static_service_a = | ||
| 196 | system.ServiceManager().GetService<Service::Glue::Time::StaticService>("time:a", true); | ||
| 197 | |||
| 198 | auto static_service_s = | ||
| 199 | system.ServiceManager().GetService<Service::PSC::Time::StaticService>("time:s", true); | ||
| 200 | |||
| 201 | std::shared_ptr<Service::PSC::Time::SystemClock> user_clock; | ||
| 202 | static_service_a->GetStandardUserSystemClock(user_clock); | ||
| 203 | |||
| 204 | std::shared_ptr<Service::PSC::Time::SystemClock> local_clock; | ||
| 205 | static_service_a->GetStandardLocalSystemClock(local_clock); | ||
| 206 | |||
| 207 | std::shared_ptr<Service::PSC::Time::SystemClock> network_clock; | ||
| 208 | static_service_s->GetStandardNetworkSystemClock(network_clock); | ||
| 209 | |||
| 210 | std::shared_ptr<Service::Glue::Time::TimeZoneService> timezone_service; | ||
| 211 | static_service_a->GetTimeZoneService(timezone_service); | ||
| 212 | |||
| 213 | Service::PSC::Time::LocationName name{}; | ||
| 214 | auto new_name = Settings::GetTimeZoneString(Settings::values.time_zone_index.GetValue()); | ||
| 215 | std::memcpy(name.name.data(), new_name.data(), std::min(name.name.size(), new_name.size())); | ||
| 216 | |||
| 217 | timezone_service->SetDeviceLocation(name); | ||
| 218 | |||
| 219 | u64 time_offset = 0; | ||
| 220 | if (Settings::values.custom_rtc_enabled) { | ||
| 221 | time_offset = Settings::values.custom_rtc_offset.GetValue(); | ||
| 222 | } | ||
| 223 | |||
| 185 | const auto posix_time = std::chrono::system_clock::now().time_since_epoch(); | 224 | const auto posix_time = std::chrono::system_clock::now().time_since_epoch(); |
| 186 | const auto current_time = | 225 | const u64 current_time = |
| 187 | std::chrono::duration_cast<std::chrono::seconds>(posix_time).count(); | 226 | +std::chrono::duration_cast<std::chrono::seconds>(posix_time).count(); |
| 188 | Settings::values.custom_rtc_differential = | 227 | const u64 new_time = current_time + time_offset; |
| 189 | (Settings::values.custom_rtc_enabled ? Settings::values.custom_rtc.GetValue() | 228 | |
| 190 | : current_time) - | 229 | Service::PSC::Time::SystemClockContext context{}; |
| 191 | current_time; | 230 | settings_service->SetUserSystemClockContext(context); |
| 231 | user_clock->SetCurrentTime(new_time); | ||
| 232 | |||
| 233 | local_clock->SetCurrentTime(new_time); | ||
| 234 | |||
| 235 | network_clock->GetSystemClockContext(context); | ||
| 236 | settings_service->SetNetworkSystemClockContext(context); | ||
| 237 | network_clock->SetCurrentTime(new_time); | ||
| 192 | } | 238 | } |
| 193 | 239 | ||
| 194 | void Run() { | 240 | void Run() { |
| @@ -264,9 +310,6 @@ struct System::Impl { | |||
| 264 | service_manager = std::make_shared<Service::SM::ServiceManager>(kernel); | 310 | service_manager = std::make_shared<Service::SM::ServiceManager>(kernel); |
| 265 | services = std::make_unique<Service::Services>(service_manager, system); | 311 | services = std::make_unique<Service::Services>(service_manager, system); |
| 266 | 312 | ||
| 267 | // Initialize time manager, which must happen after kernel is created | ||
| 268 | time_manager.Initialize(); | ||
| 269 | |||
| 270 | is_powered_on = true; | 313 | is_powered_on = true; |
| 271 | exit_locked = false; | 314 | exit_locked = false; |
| 272 | exit_requested = false; | 315 | exit_requested = false; |
| @@ -416,7 +459,6 @@ struct System::Impl { | |||
| 416 | fs_controller.Reset(); | 459 | fs_controller.Reset(); |
| 417 | cheat_engine.reset(); | 460 | cheat_engine.reset(); |
| 418 | telemetry_session.reset(); | 461 | telemetry_session.reset(); |
| 419 | time_manager.Shutdown(); | ||
| 420 | core_timing.ClearPendingEvents(); | 462 | core_timing.ClearPendingEvents(); |
| 421 | app_loader.reset(); | 463 | app_loader.reset(); |
| 422 | audio_core.reset(); | 464 | audio_core.reset(); |
| @@ -532,7 +574,6 @@ struct System::Impl { | |||
| 532 | /// Service State | 574 | /// Service State |
| 533 | Service::Glue::ARPManager arp_manager; | 575 | Service::Glue::ARPManager arp_manager; |
| 534 | Service::Account::ProfileManager profile_manager; | 576 | Service::Account::ProfileManager profile_manager; |
| 535 | Service::Time::TimeManager time_manager; | ||
| 536 | 577 | ||
| 537 | /// Service manager | 578 | /// Service manager |
| 538 | std::shared_ptr<Service::SM::ServiceManager> service_manager; | 579 | std::shared_ptr<Service::SM::ServiceManager> service_manager; |
| @@ -901,14 +942,6 @@ const Service::Account::ProfileManager& System::GetProfileManager() const { | |||
| 901 | return impl->profile_manager; | 942 | return impl->profile_manager; |
| 902 | } | 943 | } |
| 903 | 944 | ||
| 904 | Service::Time::TimeManager& System::GetTimeManager() { | ||
| 905 | return impl->time_manager; | ||
| 906 | } | ||
| 907 | |||
| 908 | const Service::Time::TimeManager& System::GetTimeManager() const { | ||
| 909 | return impl->time_manager; | ||
| 910 | } | ||
| 911 | |||
| 912 | void System::SetExitLocked(bool locked) { | 945 | void System::SetExitLocked(bool locked) { |
| 913 | impl->exit_locked = locked; | 946 | impl->exit_locked = locked; |
| 914 | } | 947 | } |
| @@ -1020,13 +1053,9 @@ void System::Exit() { | |||
| 1020 | } | 1053 | } |
| 1021 | 1054 | ||
| 1022 | void System::ApplySettings() { | 1055 | void System::ApplySettings() { |
| 1023 | impl->RefreshTime(); | 1056 | impl->RefreshTime(*this); |
| 1024 | 1057 | ||
| 1025 | if (IsPoweredOn()) { | 1058 | if (IsPoweredOn()) { |
| 1026 | if (Settings::values.custom_rtc_enabled) { | ||
| 1027 | const s64 posix_time{Settings::values.custom_rtc.GetValue()}; | ||
| 1028 | GetTimeManager().UpdateLocalSystemClockTime(posix_time); | ||
| 1029 | } | ||
| 1030 | Renderer().RefreshBaseSettings(); | 1059 | Renderer().RefreshBaseSettings(); |
| 1031 | } | 1060 | } |
| 1032 | } | 1061 | } |