1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-08-13 19:54:17 +02:00

No longer save/load common game state to/from client file

This commit is contained in:
Adriankhl
2023-03-13 10:10:44 +01:00
parent f054064322
commit eba4e4dd2c
3 changed files with 20 additions and 33 deletions

View File

@@ -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<CLoadFile> 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<CLoadFile> 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();
}

View File

@@ -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)

View File

@@ -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;