| 554 | } |
| 555 | |
| 556 | void ClientApplication::changeState(MainAppState newState) { |
| 557 | MainAppState oldState = m_state; |
| 558 | m_state = newState; |
| 559 | auto& app = appController(); |
| 560 | |
| 561 | if (m_state == MainAppState::Quit) |
| 562 | app->quit(); |
| 563 | |
| 564 | if (newState == MainAppState::Mods) |
| 565 | m_cinematicOverlay->load(m_root->assets()->json("/cinematics/mods/modloading.cinematic")); |
| 566 | |
| 567 | if (newState == MainAppState::Splash) { |
| 568 | m_cinematicOverlay->load(m_root->assets()->json("/cinematics/splash.cinematic")); |
| 569 | m_rootLoader = Thread::invoke("Async root loader", [this]() { |
| 570 | m_root->fullyLoad(); |
| 571 | }); |
| 572 | } |
| 573 | |
| 574 | if (oldState > MainAppState::Title && m_state <= MainAppState::Title) { |
| 575 | if (m_universeClient) |
| 576 | m_universeClient->disconnect(); |
| 577 | |
| 578 | if (m_universeServer) { |
| 579 | m_universeServer->stop(); |
| 580 | m_universeServer->join(); |
| 581 | m_universeServer.reset(); |
| 582 | } |
| 583 | m_cinematicOverlay->stop(); |
| 584 | m_mainInterface.reset(); |
| 585 | |
| 586 | m_voice->clearSpeakers(); |
| 587 | |
| 588 | if (auto p2pNetworkingService = app->p2pNetworkingService()) { |
| 589 | p2pNetworkingService->setJoinUnavailable(); |
| 590 | p2pNetworkingService->setAcceptingP2PConnections(false); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | if (oldState > MainAppState::Title && m_state == MainAppState::Title) { |
| 595 | m_titleScreen->resetState(); |
| 596 | m_mainMixer->setUniverseClient({}); |
| 597 | } |
| 598 | if (oldState >= MainAppState::Title && m_state < MainAppState::Title) { |
| 599 | m_playerStorage.reset(); |
| 600 | |
| 601 | if (m_statistics) { |
| 602 | m_statistics->writeStatistics(); |
| 603 | m_statistics.reset(); |
| 604 | } |
| 605 | |
| 606 | m_universeClient.reset(); |
| 607 | m_mainMixer->setUniverseClient({}); |
| 608 | m_titleScreen.reset(); |
| 609 | } |
| 610 | |
| 611 | if (oldState < MainAppState::Title && m_state >= MainAppState::Title) { |
| 612 | if (m_rootLoader) |
| 613 | m_rootLoader.finish(); |
nothing calls this directly
no test coverage detected