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 2392fe136..dd9de948c 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp | |||
| @@ -40,9 +40,14 @@ | |||
| 40 | #include "core/hle/service/apm/apm_controller.h" | 40 | #include "core/hle/service/apm/apm_controller.h" |
| 41 | #include "core/hle/service/filesystem/filesystem.h" | 41 | #include "core/hle/service/filesystem/filesystem.h" |
| 42 | #include "core/hle/service/glue/glue_manager.h" | 42 | #include "core/hle/service/glue/glue_manager.h" |
| 43 | #include "core/hle/service/glue/time/static.h" | ||
| 44 | #include "core/hle/service/psc/time/static.h" | ||
| 45 | #include "core/hle/service/psc/time/steady_clock.h" | ||
| 46 | #include "core/hle/service/psc/time/system_clock.h" | ||
| 47 | #include "core/hle/service/psc/time/time_zone_service.h" | ||
| 43 | #include "core/hle/service/service.h" | 48 | #include "core/hle/service/service.h" |
| 49 | #include "core/hle/service/set/system_settings_server.h" | ||
| 44 | #include "core/hle/service/sm/sm.h" | 50 | #include "core/hle/service/sm/sm.h" |
| 45 | #include "core/hle/service/time/time_manager.h" | ||
| 46 | #include "core/internal_network/network.h" | 51 | #include "core/internal_network/network.h" |
| 47 | #include "core/loader/loader.h" | 52 | #include "core/loader/loader.h" |
| 48 | #include "core/memory.h" | 53 | #include "core/memory.h" |
| @@ -130,8 +135,8 @@ FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs, | |||
| 130 | 135 | ||
| 131 | struct System::Impl { | 136 | struct System::Impl { |
| 132 | explicit Impl(System& system) | 137 | explicit Impl(System& system) |
| 133 | : kernel{system}, fs_controller{system}, hid_core{}, room_network{}, cpu_manager{system}, | 138 | : kernel{system}, fs_controller{system}, hid_core{}, room_network{}, |
| 134 | reporter{system}, applet_manager{system}, profile_manager{}, time_manager{system} {} | 139 | cpu_manager{system}, reporter{system}, applet_manager{system}, profile_manager{} {} |
| 135 | 140 | ||
| 136 | void Initialize(System& system) { | 141 | void Initialize(System& system) { |
| 137 | device_memory = std::make_unique<Core::DeviceMemory>(); | 142 | device_memory = std::make_unique<Core::DeviceMemory>(); |
| @@ -143,8 +148,6 @@ struct System::Impl { | |||
| 143 | core_timing.SetMulticore(is_multicore); | 148 | core_timing.SetMulticore(is_multicore); |
| 144 | core_timing.Initialize([&system]() { system.RegisterHostThread(); }); | 149 | core_timing.Initialize([&system]() { system.RegisterHostThread(); }); |
| 145 | 150 | ||
| 146 | RefreshTime(); | ||
| 147 | |||
| 148 | // Create a default fs if one doesn't already exist. | 151 | // Create a default fs if one doesn't already exist. |
| 149 | if (virtual_filesystem == nullptr) { | 152 | if (virtual_filesystem == nullptr) { |
| 150 | virtual_filesystem = std::make_shared<FileSys::RealVfsFilesystem>(); | 153 | virtual_filesystem = std::make_shared<FileSys::RealVfsFilesystem>(); |
| @@ -182,14 +185,57 @@ struct System::Impl { | |||
| 182 | Initialize(system); | 185 | Initialize(system); |
| 183 | } | 186 | } |
| 184 | 187 | ||
| 185 | void RefreshTime() { | 188 | void RefreshTime(System& system) { |
| 189 | if (!system.IsPoweredOn()) { | ||
| 190 | return; | ||
| 191 | } | ||
| 192 | |||
| 193 | auto settings_service = | ||
| 194 | system.ServiceManager().GetService<Service::Set::ISystemSettingsServer>("set:sys", | ||
| 195 | true); | ||
| 196 | auto static_service_a = | ||
| 197 | system.ServiceManager().GetService<Service::Glue::Time::StaticService>("time:a", true); | ||
| 198 | |||
| 199 | auto static_service_s = | ||
| 200 | system.ServiceManager().GetService<Service::PSC::Time::StaticService>("time:s", true); | ||
| 201 | |||
| 202 | std::shared_ptr<Service::PSC::Time::SystemClock> user_clock; | ||
| 203 | static_service_a->GetStandardUserSystemClock(user_clock); | ||
| 204 | |||
| 205 | std::shared_ptr<Service::PSC::Time::SystemClock> local_clock; | ||
| 206 | static_service_a->GetStandardLocalSystemClock(local_clock); | ||
| 207 | |||
| 208 | std::shared_ptr<Service::PSC::Time::SystemClock> network_clock; | ||
| 209 | static_service_s->GetStandardNetworkSystemClock(network_clock); | ||
| 210 | |||
| 211 | std::shared_ptr<Service::Glue::Time::TimeZoneService> timezone_service; | ||
| 212 | static_service_a->GetTimeZoneService(timezone_service); | ||
| 213 | |||
| 214 | Service::PSC::Time::LocationName name{}; | ||
| 215 | auto new_name = Settings::GetTimeZoneString(Settings::values.time_zone_index.GetValue()); | ||
| 216 | std::memcpy(name.name.data(), new_name.data(), std::min(name.name.size(), new_name.size())); | ||
| 217 | |||
| 218 | timezone_service->SetDeviceLocation(name); | ||
| 219 | |||
| 220 | u64 time_offset = 0; | ||
| 221 | if (Settings::values.custom_rtc_enabled) { | ||
| 222 | time_offset = Settings::values.custom_rtc_offset.GetValue(); | ||
| 223 | } | ||
| 224 | |||
| 186 | const auto posix_time = std::chrono::system_clock::now().time_since_epoch(); | 225 | const auto posix_time = std::chrono::system_clock::now().time_since_epoch(); |
| 187 | const auto current_time = | 226 | const u64 current_time = |
| 188 | std::chrono::duration_cast<std::chrono::seconds>(posix_time).count(); | 227 | +std::chrono::duration_cast<std::chrono::seconds>(posix_time).count(); |
| 189 | Settings::values.custom_rtc_differential = | 228 | const u64 new_time = current_time + time_offset; |
| 190 | (Settings::values.custom_rtc_enabled ? Settings::values.custom_rtc.GetValue() | 229 | |
| 191 | : current_time) - | 230 | Service::PSC::Time::SystemClockContext context{}; |
| 192 | current_time; | 231 | settings_service->SetUserSystemClockContext(context); |
| 232 | user_clock->SetCurrentTime(new_time); | ||
| 233 | |||
| 234 | local_clock->SetCurrentTime(new_time); | ||
| 235 | |||
| 236 | network_clock->GetSystemClockContext(context); | ||
| 237 | settings_service->SetNetworkSystemClockContext(context); | ||
| 238 | network_clock->SetCurrentTime(new_time); | ||
| 193 | } | 239 | } |
| 194 | 240 | ||
| 195 | void Run() { | 241 | void Run() { |
| @@ -265,9 +311,6 @@ struct System::Impl { | |||
| 265 | service_manager = std::make_shared<Service::SM::ServiceManager>(kernel); | 311 | service_manager = std::make_shared<Service::SM::ServiceManager>(kernel); |
| 266 | services = std::make_unique<Service::Services>(service_manager, system); | 312 | services = std::make_unique<Service::Services>(service_manager, system); |
| 267 | 313 | ||
| 268 | // Initialize time manager, which must happen after kernel is created | ||
| 269 | time_manager.Initialize(); | ||
| 270 | |||
| 271 | is_powered_on = true; | 314 | is_powered_on = true; |
| 272 | exit_locked = false; | 315 | exit_locked = false; |
| 273 | exit_requested = false; | 316 | exit_requested = false; |
| @@ -417,7 +460,6 @@ struct System::Impl { | |||
| 417 | fs_controller.Reset(); | 460 | fs_controller.Reset(); |
| 418 | cheat_engine.reset(); | 461 | cheat_engine.reset(); |
| 419 | telemetry_session.reset(); | 462 | telemetry_session.reset(); |
| 420 | time_manager.Shutdown(); | ||
| 421 | core_timing.ClearPendingEvents(); | 463 | core_timing.ClearPendingEvents(); |
| 422 | app_loader.reset(); | 464 | app_loader.reset(); |
| 423 | audio_core.reset(); | 465 | audio_core.reset(); |
| @@ -533,7 +575,6 @@ struct System::Impl { | |||
| 533 | /// Service State | 575 | /// Service State |
| 534 | Service::Glue::ARPManager arp_manager; | 576 | Service::Glue::ARPManager arp_manager; |
| 535 | Service::Account::ProfileManager profile_manager; | 577 | Service::Account::ProfileManager profile_manager; |
| 536 | Service::Time::TimeManager time_manager; | ||
| 537 | 578 | ||
| 538 | /// Service manager | 579 | /// Service manager |
| 539 | std::shared_ptr<Service::SM::ServiceManager> service_manager; | 580 | std::shared_ptr<Service::SM::ServiceManager> service_manager; |
| @@ -911,14 +952,6 @@ const Service::Account::ProfileManager& System::GetProfileManager() const { | |||
| 911 | return impl->profile_manager; | 952 | return impl->profile_manager; |
| 912 | } | 953 | } |
| 913 | 954 | ||
| 914 | Service::Time::TimeManager& System::GetTimeManager() { | ||
| 915 | return impl->time_manager; | ||
| 916 | } | ||
| 917 | |||
| 918 | const Service::Time::TimeManager& System::GetTimeManager() const { | ||
| 919 | return impl->time_manager; | ||
| 920 | } | ||
| 921 | |||
| 922 | void System::SetExitLocked(bool locked) { | 955 | void System::SetExitLocked(bool locked) { |
| 923 | impl->exit_locked = locked; | 956 | impl->exit_locked = locked; |
| 924 | } | 957 | } |
| @@ -1030,13 +1063,9 @@ void System::Exit() { | |||
| 1030 | } | 1063 | } |
| 1031 | 1064 | ||
| 1032 | void System::ApplySettings() { | 1065 | void System::ApplySettings() { |
| 1033 | impl->RefreshTime(); | 1066 | impl->RefreshTime(*this); |
| 1034 | 1067 | ||
| 1035 | if (IsPoweredOn()) { | 1068 | if (IsPoweredOn()) { |
| 1036 | if (Settings::values.custom_rtc_enabled) { | ||
| 1037 | const s64 posix_time{Settings::values.custom_rtc.GetValue()}; | ||
| 1038 | GetTimeManager().UpdateLocalSystemClockTime(posix_time); | ||
| 1039 | } | ||
| 1040 | Renderer().RefreshBaseSettings(); | 1069 | Renderer().RefreshBaseSettings(); |
| 1041 | } | 1070 | } |
| 1042 | } | 1071 | } |