mirror of
https://github.com/vcmi/vcmi.git
synced 2025-06-17 00:07:41 +02:00
Fix game startup
This commit is contained in:
@ -633,7 +633,6 @@ void CServerHandler::startGameplay(std::shared_ptr<CGameState> gameState)
|
|||||||
throw std::runtime_error("Invalid mode");
|
throw std::runtime_error("Invalid mode");
|
||||||
}
|
}
|
||||||
// After everything initialized we can accept CPackToClient netpacks
|
// After everything initialized we can accept CPackToClient netpacks
|
||||||
logicConnection->setCallback(&client->gameState());
|
|
||||||
setState(EClientState::GAMEPLAY);
|
setState(EClientState::GAMEPLAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,6 @@ void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyPrepareStartGame(LobbyPrepareS
|
|||||||
{
|
{
|
||||||
handler.client = std::make_unique<CClient>();
|
handler.client = std::make_unique<CClient>();
|
||||||
handler.logicConnection->enterLobbyConnectionMode();
|
handler.logicConnection->enterLobbyConnectionMode();
|
||||||
handler.logicConnection->setCallback(&handler.client->gameInfo());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack)
|
void ApplyOnLobbyHandlerNetPackVisitor::visitLobbyStartGame(LobbyStartGame & pack)
|
||||||
|
@ -135,6 +135,13 @@ private:
|
|||||||
////that const cast is evil because it allows to implicitly overwrite const objects when deserializing
|
////that const cast is evil because it allows to implicitly overwrite const objects when deserializing
|
||||||
typedef typename std::remove_const_t<T> nonConstT;
|
typedef typename std::remove_const_t<T> nonConstT;
|
||||||
auto & hlp = const_cast<nonConstT &>(data);
|
auto & hlp = const_cast<nonConstT &>(data);
|
||||||
|
|
||||||
|
if constexpr(std::is_base_of_v<IGameInfoCallback, std::remove_pointer_t<nonConstT>>)
|
||||||
|
{
|
||||||
|
assert(cb == nullptr);
|
||||||
|
cb = &data;
|
||||||
|
}
|
||||||
|
|
||||||
hlp.serialize(*this);
|
hlp.serialize(*this);
|
||||||
}
|
}
|
||||||
template<typename T, typename std::enable_if_t<std::is_array_v<T>, int> = 0>
|
template<typename T, typename std::enable_if_t<std::is_array_v<T>, int> = 0>
|
||||||
|
@ -124,9 +124,9 @@ void CConnection::enterLobbyConnectionMode()
|
|||||||
serializer->clear();
|
serializer->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConnection::setCallback(IGameInfoCallback * cb)
|
void CConnection::setCallback(IGameInfoCallback & cb)
|
||||||
{
|
{
|
||||||
deserializer->cb = cb;
|
deserializer->cb = &cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CConnection::setSerializationVersion(ESerializationVersion version)
|
void CConnection::setSerializationVersion(ESerializationVersion version)
|
||||||
|
@ -50,7 +50,7 @@ public:
|
|||||||
std::unique_ptr<CPack> retrievePack(const std::vector<std::byte> & data);
|
std::unique_ptr<CPack> retrievePack(const std::vector<std::byte> & data);
|
||||||
|
|
||||||
void enterLobbyConnectionMode();
|
void enterLobbyConnectionMode();
|
||||||
void setCallback(IGameInfoCallback * cb);
|
void setCallback(IGameInfoCallback & cb);
|
||||||
void setSerializationVersion(ESerializationVersion version);
|
void setSerializationVersion(ESerializationVersion version);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ struct ClassObjectCreator<T, typename std::enable_if_t<std::is_base_of_v<GameCal
|
|||||||
static T *invoke(IGameInfoCallback *cb)
|
static T *invoke(IGameInfoCallback *cb)
|
||||||
{
|
{
|
||||||
static_assert(!std::is_abstract_v<T>, "Cannot call new upon abstract classes!");
|
static_assert(!std::is_abstract_v<T>, "Cannot call new upon abstract classes!");
|
||||||
|
assert(cb != nullptr);
|
||||||
return new T(cb);
|
return new T(cb);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -541,14 +541,13 @@ void CGameHandler::reinitScripting()
|
|||||||
|
|
||||||
void CGameHandler::init(StartInfo *si, Load::ProgressAccumulator & progressTracking)
|
void CGameHandler::init(StartInfo *si, Load::ProgressAccumulator & progressTracking)
|
||||||
{
|
{
|
||||||
|
CMapService mapService;
|
||||||
|
gs = std::make_shared<CGameState>();
|
||||||
int requestedSeed = settings["server"]["seed"].Integer();
|
int requestedSeed = settings["server"]["seed"].Integer();
|
||||||
|
randomizer = std::make_unique<GameRandomizer>(*gs);
|
||||||
if (requestedSeed != 0)
|
if (requestedSeed != 0)
|
||||||
randomizer->setSeed(requestedSeed);
|
randomizer->setSeed(requestedSeed);
|
||||||
logGlobal->info("Using random seed: %d", randomizer->getDefault().nextInt());
|
logGlobal->info("Using random seed: %d", randomizer->getDefault().nextInt());
|
||||||
|
|
||||||
CMapService mapService;
|
|
||||||
gs = std::make_shared<CGameState>();
|
|
||||||
randomizer = std::make_unique<GameRandomizer>(*gs);
|
|
||||||
gs->preInit(LIBRARY);
|
gs->preInit(LIBRARY);
|
||||||
logGlobal->info("Gamestate created!");
|
logGlobal->info("Gamestate created!");
|
||||||
gs->init(&mapService, si, *randomizer, progressTracking);
|
gs->init(&mapService, si, *randomizer, progressTracking);
|
||||||
|
@ -294,7 +294,7 @@ bool CVCMIServer::prepareToStartGame()
|
|||||||
void CVCMIServer::startGameImmediately()
|
void CVCMIServer::startGameImmediately()
|
||||||
{
|
{
|
||||||
for(auto activeConnection : activeConnections)
|
for(auto activeConnection : activeConnections)
|
||||||
activeConnection->setCallback(&gh->gameInfo());
|
activeConnection->setCallback(gh->gameInfo());
|
||||||
|
|
||||||
gh->start(si->mode == EStartMode::LOAD_GAME);
|
gh->start(si->mode == EStartMode::LOAD_GAME);
|
||||||
setState(EServerState::GAMEPLAY);
|
setState(EServerState::GAMEPLAY);
|
||||||
|
@ -241,7 +241,7 @@ void ApplyOnServerAfterAnnounceNetPackVisitor::visitLobbyStartGame(LobbyStartGam
|
|||||||
{
|
{
|
||||||
if(connection->connectionID == pack.clientId)
|
if(connection->connectionID == pack.clientId)
|
||||||
{
|
{
|
||||||
connection->setCallback(&srv.gh->gameInfo());
|
connection->setCallback(srv.gh->gameInfo());
|
||||||
srv.reconnectPlayer(pack.clientId);
|
srv.reconnectPlayer(pack.clientId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user