1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Pass loaded game over network too

This commit is contained in:
nordsoft 2022-09-29 21:33:44 +04:00
parent b888e640f3
commit 8a8716ce8a
3 changed files with 44 additions and 35 deletions

View File

@ -541,7 +541,7 @@ void CServerHandler::startGameplay(CGameState * gameState)
client->newGame(gameState); client->newGame(gameState);
break; break;
case StartInfo::LOAD_GAME: case StartInfo::LOAD_GAME:
client->loadGame(); client->loadGame(gameState);
break; break;
default: default:
throw std::runtime_error("Invalid mode"); throw std::runtime_error("Invalid mode");

View File

@ -197,10 +197,17 @@ void CClient::newGame(CGameState * gameState)
initPlayerInterfaces(); initPlayerInterfaces();
} }
void CClient::loadGame() void CClient::loadGame(CGameState * gameState)
{ {
logNetwork->info("Loading procedure started!"); logNetwork->info("Loading procedure started!");
if(gameState)
{
logNetwork->info("Game state was transferred over network, loading.");
gs = gameState;
}
else
{
std::unique_ptr<CLoadFile> loader; std::unique_ptr<CLoadFile> loader;
try try
{ {
@ -228,6 +235,7 @@ void CClient::loadGame()
loader = checkingLoader.decay(); loader = checkingLoader.decay();
} }
serialize(loader->serializer, loader->serializer.fileVersion);
} }
catch(std::exception & e) catch(std::exception & e)
{ {
@ -235,16 +243,17 @@ void CClient::loadGame()
throw; //obviously we cannot continue here throw; //obviously we cannot continue here
} }
logNetwork->trace("Loaded common part of save %d ms", CSH->th->getDiff()); logNetwork->trace("Loaded common part of save %d ms", CSH->th->getDiff());
}
gs->preInit(VLC); gs->preInit(VLC);
gs->updateOnLoad(CSH->si.get()); gs->updateOnLoad(CSH->si.get());
logNetwork->info("Game loaded, initialize interfaces.");
initMapHandler(); initMapHandler();
reinitScripting(); reinitScripting();
initPlayerEnvironments(); initPlayerEnvironments();
serialize(loader->serializer, loader->serializer.fileVersion);
initPlayerInterfaces(); initPlayerInterfaces();
} }

View File

@ -151,7 +151,7 @@ public:
events::EventBus * eventBus() const override; events::EventBus * eventBus() const override;
void newGame(CGameState * gameState); void newGame(CGameState * gameState);
void loadGame(); void loadGame(CGameState * gameState);
void serialize(BinarySerializer & h, const int version); void serialize(BinarySerializer & h, const int version);
void serialize(BinaryDeserializer & h, const int version); void serialize(BinaryDeserializer & h, const int version);