From eba4e4dd2ca4686275c3810d3578b3dcf40d64c2 Mon Sep 17 00:00:00 2001 From: Adriankhl Date: Mon, 13 Mar 2023 10:10:44 +0100 Subject: [PATCH] No longer save/load common game state to/from client file --- client/Client.cpp | 48 +++++++++++++---------------------- client/NetPacksClient.cpp | 1 - client/lobby/SelectionTab.cpp | 4 +-- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/client/Client.cpp b/client/Client.cpp index 126b84b50..936d7e7d7 100644 --- a/client/Client.cpp +++ b/client/Client.cpp @@ -201,9 +201,21 @@ void CClient::newGame(CGameState * initializedGameState) void CClient::loadGame(CGameState * initializedGameState) { logNetwork->info("Loading procedure started!"); + + logNetwork->info("Game state was transferred over network, loading."); + gs = initializedGameState; + + gs->preInit(VLC); + gs->updateOnLoad(CSH->si.get()); + logNetwork->info("Game loaded, initialize interfaces."); + + initMapHandler(); + + reinitScripting(); + + initPlayerEnvironments(); - std::unique_ptr loader; - // try to assign loader, which is needed to deserialize data such as sleepingHeroes + // try to deserialize client data including sleepingHeroes try { boost::filesystem::path clientSaveName = *CResourceHandler::get("local")->getResourceName(ResourceID(CSH->si->mapname, EResType::CLIENT_SAVEGAME)); @@ -225,40 +237,16 @@ void CClient::loadGame(CGameState * initializedGameState) throw std::runtime_error("Cannot open server part of " + CSH->si->mapname); CLoadIntegrityValidator checkingLoader(clientSaveName, controlServerSaveName, MINIMAL_SERIALIZATION_VERSION); - loadCommonState(checkingLoader); - loader = checkingLoader.decay(); + std::unique_ptr loader = checkingLoader.decay(); + serialize(loader->serializer, loader->serializer.fileVersion); - logNetwork->trace("Loaded common part of save %d ms", CSH->th->getDiff()); + logNetwork->info("Client data loaded."); } catch(std::exception & e) { - if(initializedGameState) - { - logNetwork->info("Game state was transferred over network, loading."); - // if loader can't be assigned, use the game state transferred from network if exist - gs = initializedGameState; - } - else - { - logGlobal->error("Cannot load game %s. Error: %s", CSH->si->mapname, e.what()); - throw; //obviously we cannot continue here - } + logGlobal->info("Cannot load client data for game %s. Error: %s", CSH->si->mapname, e.what()); } - gs->preInit(VLC); - gs->updateOnLoad(CSH->si.get()); - logNetwork->info("Game loaded, initialize interfaces."); - - initMapHandler(); - - reinitScripting(); - - initPlayerEnvironments(); - - // deserialize data including sleepingHeroes - if(loader) - serialize(loader->serializer, loader->serializer.fileVersion); - initPlayerInterfaces(); } diff --git a/client/NetPacksClient.cpp b/client/NetPacksClient.cpp index e9e859018..a9992d483 100644 --- a/client/NetPacksClient.cpp +++ b/client/NetPacksClient.cpp @@ -833,7 +833,6 @@ void ApplyClientNetPackVisitor::visitSaveGameClient(SaveGameClient & pack) try { CSaveFile save(*CResourceHandler::get()->getResourceName(ResourceID(stem.to_string(), EResType::CLIENT_SAVEGAME))); - cl.saveCommonState(save); save << cl; } catch(std::exception &e) diff --git a/client/lobby/SelectionTab.cpp b/client/lobby/SelectionTab.cpp index d9cde524f..ab83cb5ab 100644 --- a/client/lobby/SelectionTab.cpp +++ b/client/lobby/SelectionTab.cpp @@ -224,11 +224,11 @@ void SelectionTab::toggleMode() case ESelectionScreen::loadGame: inputName->disable(); - parseSaves(getFiles("Saves/", EResType::CLIENT_SAVEGAME)); + parseSaves(getFiles("Saves/", EResType::SERVER_SAVEGAME)); break; case ESelectionScreen::saveGame: - parseSaves(getFiles("Saves/", EResType::CLIENT_SAVEGAME)); + parseSaves(getFiles("Saves/", EResType::SERVER_SAVEGAME)); inputName->enable(); restoreLastSelection(); break;