Browse Source

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

Adriankhl 2 years ago
parent
commit
eba4e4dd2c
3 changed files with 20 additions and 33 deletions
  1. 18 30
      client/Client.cpp
  2. 0 1
      client/NetPacksClient.cpp
  3. 2 2
      client/lobby/SelectionTab.cpp

+ 18 - 30
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<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();
 }
 

+ 0 - 1
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)

+ 2 - 2
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;