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

Removed broken & unused serialization of player interface and AI

This commit is contained in:
Ivan Savenko 2024-05-17 16:35:53 +00:00
parent 69e33e406d
commit f3de2cfe1c
19 changed files with 0 additions and 457 deletions

View File

@ -14,14 +14,6 @@
#include "../../lib/CStack.h"
#include "../../lib/battle/BattleAction.h"
void CEmptyAI::saveGame(BinarySerializer & h)
{
}
void CEmptyAI::loadGame(BinaryDeserializer & h)
{
}
void CEmptyAI::initGameInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CCallback> CB)
{
cb = CB;

View File

@ -19,9 +19,6 @@ class CEmptyAI : public CGlobalAI
std::shared_ptr<CCallback> cb;
public:
void saveGame(BinarySerializer & h) override;
void loadGame(BinaryDeserializer & h) override;
void initGameInterface(std::shared_ptr<Environment> ENV, std::shared_ptr<CCallback> CB) override;
void yourTurn(QueryID queryID) override;
void yourTacticPhase(const BattleID & battleID, int distance) override;

View File

@ -773,27 +773,6 @@ void AIGateway::showMapObjectSelectDialog(QueryID askID, const Component & icon,
requestActionASAP([=](){ answerQuery(askID, selectedObject.getNum()); });
}
void AIGateway::saveGame(BinarySerializer & h)
{
NET_EVENT_HANDLER;
nullkiller->memory->removeInvisibleObjects(myCb.get());
CAdventureAI::saveGame(h);
serializeInternal(h);
}
void AIGateway::loadGame(BinaryDeserializer & h)
{
//NET_EVENT_HANDLER;
#if 0
//disabled due to issue 2890
registerGoals(h);
#endif // 0
CAdventureAI::loadGame(h);
serializeInternal(h);
}
bool AIGateway::makePossibleUpgrades(const CArmedInstance * obj)
{
if(!obj)

View File

@ -60,15 +60,6 @@ public:
void attemptedAnsweringQuery(QueryID queryID, int answerRequestID);
void receivedAnswerConfirmation(int answerRequestID, int result);
void heroVisit(const CGObjectInstance * obj, bool started);
template<typename Handler> void serialize(Handler & h)
{
h & battle;
h & remainingQueries;
h & requestToQueryID;
h & havingTurn;
}
};
// The gateway is responsible for AI events handling. Copied from VCAI.h and refined a bit
@ -120,8 +111,6 @@ public:
void showGarrisonDialog(const CArmedInstance * up, const CGHeroInstance * down, bool removableUnits, QueryID queryID) override; //all stacks operations between these objects become allowed, interface has to call onEnd when done
void showTeleportDialog(const CGHeroInstance * hero, TeleportChannelID channel, TTeleportExitsList exits, bool impassable, QueryID askID) override;
void showMapObjectSelectDialog(QueryID askID, const Component & icon, const MetaString & title, const MetaString & description, const std::vector<ObjectInstanceID> & objects) override;
void saveGame(BinarySerializer & h) override; //saving
void loadGame(BinaryDeserializer & h) override; //loading
void finish() override;
void availableCreaturesChanged(const CGDwelling * town) override;
@ -203,19 +192,6 @@ public:
void answerQuery(QueryID queryID, int selection);
//special function that can be called ONLY from game events handling thread and will send request ASAP
void requestActionASAP(std::function<void()> whatToDo);
template<typename Handler> void serializeInternal(Handler & h)
{
#if 0
h & nullkiller->memory->knownTeleportChannels;
h & nullkiller->memory->knownSubterraneanGates;
h & destinationTeleport;
h & nullkiller->memory->visitableObjs;
h & nullkiller->memory->alreadyVisited;
h & status;
h & battlename;
#endif
}
};
}

View File

@ -111,14 +111,6 @@ public:
const CGHeroInstance * get(bool doWeExpectNull = false) const;
const CGHeroInstance * get(const CPlayerSpecificInfoCallback * cb, bool doWeExpectNull = false) const;
bool validAndSet() const;
template<typename Handler> void serialize(Handler & handler)
{
handler & h;
handler & hid;
handler & name;
}
};
enum BattleState
@ -143,12 +135,6 @@ struct ObjectIdRef
ObjectIdRef(const CGObjectInstance * obj);
bool operator<(const ObjectIdRef & rhs) const;
template<typename Handler> void serialize(Handler & h)
{
h & id;
}
};
template<Obj::Type id>

View File

@ -36,12 +36,6 @@ namespace Goals
{
return new T(static_cast<T const &>(*this)); //casting enforces template instantiation
}
template<typename Handler> void serialize(Handler & h)
{
h & static_cast<AbstractGoal &>(*this);
//h & goalType & isElementar & isAbstract & priority;
//h & value & resID & objid & aid & tile & hero & town & bid;
}
bool operator==(const AbstractGoal & g) const override
{

View File

@ -68,14 +68,6 @@ public:
const CGHeroInstance * get(bool doWeExpectNull = false) const;
bool validAndSet() const;
template<typename Handler> void serialize(Handler & h)
{
h & this->h;
h & hid;
h & name;
}
};
enum BattleState
@ -100,12 +92,6 @@ struct ObjectIdRef
ObjectIdRef(const CGObjectInstance * obj);
bool operator<(const ObjectIdRef & rhs) const;
template<typename Handler> void serialize(Handler & h)
{
h & id;
}
};
struct TimeCheck

View File

@ -73,7 +73,6 @@ namespace Goals
public:
bool operator==(const TSubgoal & rhs) const;
bool operator<(const TSubgoal & rhs) const;
//TODO: serialize?
};
using TGoalVec = std::vector<TSubgoal>;
@ -175,21 +174,5 @@ namespace Goals
// {
// return !(*this == g);
// }
template<typename Handler> void serialize(Handler & h)
{
h & goalType;
h & isElementar;
h & isAbstract;
h & priority;
h & value;
h & resID;
h & objid;
h & aid;
h & tile;
h & hero;
h & town;
h & bid;
}
};
}

View File

@ -69,12 +69,6 @@ namespace Goals
return ptr;
}
template<typename Handler> void serialize(Handler & h)
{
h & static_cast<AbstractGoal &>(*this);
//h & goalType & isElementar & isAbstract & priority;
//h & value & resID & objid & aid & tile & hero & town & bid;
}
bool operator==(const AbstractGoal & g) const override
{

View File

@ -26,13 +26,6 @@ struct DLL_EXPORT ResourceObjective
TResources resources; //how many resoures do we need
Goals::TSubgoal goal; //what for (build, gather army etc...)
//TODO: register?
template<typename Handler> void serializeInternal(Handler & h)
{
h & resources;
//h & goal; //FIXME: goal serialization is broken
}
};
class DLL_EXPORT IResourceManager //: public: IAbstractManager
@ -103,11 +96,4 @@ private:
boost::heap::binomial_heap<ResourceObjective> queue;
void dumpToLog() const;
//TODO: register?
template<typename Handler> void serializeInternal(Handler & h)
{
h & saving;
h & queue;
}
};

View File

@ -747,31 +747,6 @@ void VCAI::showMapObjectSelectDialog(QueryID askID, const Component & icon, cons
requestActionASAP([=](){ answerQuery(askID, selectedObject.getNum()); });
}
void VCAI::saveGame(BinarySerializer & h)
{
NET_EVENT_HANDLER;
validateVisitableObjs();
#if 0
//disabled due to issue 2890
registerGoals(h);
#endif // 0
CAdventureAI::saveGame(h);
serializeInternal(h);
}
void VCAI::loadGame(BinaryDeserializer & h)
{
//NET_EVENT_HANDLER;
#if 0
//disabled due to issue 2890
registerGoals(h);
#endif // 0
CAdventureAI::loadGame(h);
serializeInternal(h);
}
void makePossibleUpgrades(const CArmedInstance * obj)
{
if(!obj)

View File

@ -66,15 +66,6 @@ public:
void attemptedAnsweringQuery(QueryID queryID, int answerRequestID);
void receivedAnswerConfirmation(int answerRequestID, int result);
void heroVisit(const CGObjectInstance * obj, bool started);
template<typename Handler> void serialize(Handler & h)
{
h & battle;
h & remainingQueries;
h & requestToQueryID;
h & havingTurn;
}
};
class DLL_EXPORT VCAI : public CAdventureAI
@ -152,8 +143,6 @@ public:
void showGarrisonDialog(const CArmedInstance * up, const CGHeroInstance * down, bool removableUnits, QueryID queryID) override; //all stacks operations between these objects become allowed, interface has to call onEnd when done
void showTeleportDialog(const CGHeroInstance * hero, TeleportChannelID channel, TTeleportExitsList exits, bool impassable, QueryID askID) override;
void showMapObjectSelectDialog(QueryID askID, const Component & icon, const MetaString & title, const MetaString & description, const std::vector<ObjectInstanceID> & objects) override;
void saveGame(BinarySerializer & h) override; //saving
void loadGame(BinaryDeserializer & h) override; //loading
void finish() override;
void availableCreaturesChanged(const CGDwelling * town) override;
@ -273,95 +262,6 @@ public:
void answerQuery(QueryID queryID, int selection);
//special function that can be called ONLY from game events handling thread and will send request ASAP
void requestActionASAP(std::function<void()> whatToDo);
#if 0
//disabled due to issue 2890
template<typename Handler> void registerGoals(Handler & h)
{
//h.template registerType<Goals::AbstractGoal, Goals::BoostHero>();
h.template registerType<Goals::AbstractGoal, Goals::Build>();
h.template registerType<Goals::AbstractGoal, Goals::BuildThis>();
//h.template registerType<Goals::AbstractGoal, Goals::CIssueCommand>();
h.template registerType<Goals::AbstractGoal, Goals::ClearWayTo>();
h.template registerType<Goals::AbstractGoal, Goals::CollectRes>();
h.template registerType<Goals::AbstractGoal, Goals::Conquer>();
h.template registerType<Goals::AbstractGoal, Goals::DigAtTile>();
h.template registerType<Goals::AbstractGoal, Goals::Explore>();
h.template registerType<Goals::AbstractGoal, Goals::FindObj>();
h.template registerType<Goals::AbstractGoal, Goals::GatherArmy>();
h.template registerType<Goals::AbstractGoal, Goals::GatherTroops>();
h.template registerType<Goals::AbstractGoal, Goals::GetArtOfType>();
h.template registerType<Goals::AbstractGoal, Goals::VisitObj>();
h.template registerType<Goals::AbstractGoal, Goals::Invalid>();
//h.template registerType<Goals::AbstractGoal, Goals::NotLose>();
h.template registerType<Goals::AbstractGoal, Goals::RecruitHero>();
h.template registerType<Goals::AbstractGoal, Goals::VisitHero>();
h.template registerType<Goals::AbstractGoal, Goals::VisitTile>();
h.template registerType<Goals::AbstractGoal, Goals::Win>();
}
#endif
template<typename Handler> void serializeInternal(Handler & h)
{
#if 0
// serialization of client-side data is broken and not performed at the moment
h & knownTeleportChannels;
h & knownSubterraneanGates;
h & destinationTeleport;
h & townVisitsThisWeek;
#if 0
//disabled due to issue 2890
h & lockedHeroes;
#else
{
ui32 length = 0;
h & length;
if(!h.saving)
{
std::set<ui32> loadedPointers;
lockedHeroes.clear();
for(ui32 index = 0; index < length; index++)
{
HeroPtr ignored1;
h & ignored1;
ui8 flag = 0;
h & flag;
if(flag)
{
ui32 pid = 0xffffffff;
h & pid;
if(!vstd::contains(loadedPointers, pid))
{
loadedPointers.insert(pid);
ui16 typeId = 0;
//this is the problem requires such hack
//we have to explicitly ignore invalid goal class type id
h & typeId;
Goals::AbstractGoal ignored2;
ignored2.serialize(h);
}
}
}
}
}
#endif
h & reservedHeroesMap; //FIXME: cannot instantiate abstract class
h & visitableObjs;
h & alreadyVisited;
h & reservedObjs;
h & status;
h & battlename;
h & heroesUnableToExplore;
//myCB is restored after load by init call
#endif
}
};
class cannotFulfillGoalException : public std::exception

View File

@ -142,7 +142,6 @@ CPlayerInterface::CPlayerInterface(PlayerColor Player):
makingTurn = false;
showingDialog = new CondSh<bool>(false);
cingconsole = new CInGameConsole();
firstCall = 1; //if loading will be overwritten in serialize
autosaveCount = 0;
isAutoFightOn = false;
isAutoFightEndBattle = false;
@ -1201,19 +1200,6 @@ void CPlayerInterface::heroBonusChanged( const CGHeroInstance *hero, const Bonus
}
}
void CPlayerInterface::saveGame( BinarySerializer & h )
{
EVENT_HANDLER_CALLED_BY_CLIENT;
localState->serialize(h);
}
void CPlayerInterface::loadGame( BinaryDeserializer & h )
{
EVENT_HANDLER_CALLED_BY_CLIENT;
localState->serialize(h);
firstCall = -1;
}
void CPlayerInterface::moveHero( const CGHeroInstance *h, const CGPath& path )
{
assert(h);

View File

@ -61,8 +61,6 @@ class CPlayerInterface : public CGameInterface, public IUpdateable
bool ignoreEvents;
size_t numOfMovedArts;
// -1 - just loaded game; 1 - just started game; 0 otherwise
int firstCall;
int autosaveCount;
std::list<std::shared_ptr<CInfoWindow>> dialogs; //queue of dialogs awaiting to be shown (not currently shown!)
@ -146,8 +144,6 @@ protected: // Call-ins from server, should not be called directly, but only via
void gameOver(PlayerColor player, const EVictoryLossCheckResult & victoryLossCheckResult) override;
void playerStartsTurn(PlayerColor player) override; //called before yourTurn on active itnerface
void playerEndsTurn(PlayerColor player) override;
void saveGame(BinarySerializer & h) override; //saving
void loadGame(BinaryDeserializer & h) override; //loading
void showWorldViewEx(const std::vector<ObjectPosInfo> & objectPositions, bool showTerrain) override;
//for battles

View File

@ -203,137 +203,9 @@ void CClient::loadGame(CGameState * initializedGameState)
reinitScripting();
initPlayerEnvironments();
// Loading of client state - disabled for now
// Since client no longer writes or loads its own state and instead receives it from server
// client state serializer will serialize its own copies of all pointers, e.g. heroes/towns/objects
// and on deserialize will create its own copies (instead of using copies from state received from server)
// Potential solutions:
// 1) Use server gamestate to deserialize pointers, so any pointer to same object will point to server instance and not our copy
// 2) Remove all serialization of pointers with instance ID's and restore them on load (including AI deserializer code)
// 3) Completely remove client savegame and send all information, like hero paths and sleeping status to server (either in form of hero properties or as some generic "client options" message
#ifdef BROKEN_CLIENT_STATE_SERIALIZATION_HAS_BEEN_FIXED
// try to deserialize client data including sleepingHeroes
try
{
boost::filesystem::path clientSaveName = *CResourceHandler::get()->getResourceName(ResourcePath(CSH->si->mapname, EResType::CLIENT_SAVEGAME));
if(clientSaveName.empty())
throw std::runtime_error("Cannot open client part of " + CSH->si->mapname);
std::unique_ptr<CLoadFile> loader (new CLoadFile(clientSaveName));
serialize(loader->serializer, loader->serializer.version);
logNetwork->info("Client data loaded.");
}
catch(std::exception & e)
{
logGlobal->info("Cannot load client data for game %s. Error: %s", CSH->si->mapname, e.what());
}
#endif
initPlayerInterfaces();
}
void CClient::serialize(BinarySerializer & h)
{
assert(h.saving);
ui8 players = static_cast<ui8>(playerint.size());
h & players;
for(auto i = playerint.begin(); i != playerint.end(); i++)
{
logGlobal->trace("Saving player %s interface", i->first);
assert(i->first == i->second->playerID);
h & i->first;
h & i->second->dllName;
h & i->second->human;
i->second->saveGame(h);
}
#if SCRIPTING_ENABLED
JsonNode scriptsState;
clientScripts->serializeState(h.saving, scriptsState);
h & scriptsState;
#endif
}
void CClient::serialize(BinaryDeserializer & h)
{
assert(!h.saving);
ui8 players = 0;
h & players;
for(int i = 0; i < players; i++)
{
std::string dllname;
PlayerColor pid;
bool isHuman = false;
auto prevInt = LOCPLINT;
h & pid;
h & dllname;
h & isHuman;
assert(dllname.length() == 0 || !isHuman);
if(pid == PlayerColor::NEUTRAL)
{
logGlobal->trace("Neutral battle interfaces are not serialized.");
continue;
}
logGlobal->trace("Loading player %s interface", pid);
std::shared_ptr<CGameInterface> nInt;
if(dllname.length())
nInt = CDynLibHandler::getNewAI(dllname);
else
nInt = std::make_shared<CPlayerInterface>(pid);
nInt->dllName = dllname;
nInt->human = isHuman;
nInt->playerID = pid;
bool shouldResetInterface = true;
// Client no longer handle this player at all
if(!vstd::contains(CSH->getAllClientPlayers(CSH->logicConnection->connectionID), pid))
{
logGlobal->trace("Player %s is not belong to this client. Destroying interface", pid);
}
else if(isHuman && !vstd::contains(CSH->getHumanColors(), pid))
{
logGlobal->trace("Player %s is no longer controlled by human. Destroying interface", pid);
}
else if(!isHuman && vstd::contains(CSH->getHumanColors(), pid))
{
logGlobal->trace("Player %s is no longer controlled by AI. Destroying interface", pid);
}
else
{
installNewPlayerInterface(nInt, pid);
shouldResetInterface = false;
}
// loadGame needs to be called after initGameInterface to load paths correctly
// initGameInterface is called in installNewPlayerInterface
nInt->loadGame(h);
if (shouldResetInterface)
{
nInt.reset();
LOCPLINT = prevInt;
}
}
#if SCRIPTING_ENABLED
{
JsonNode scriptsState;
h & scriptsState;
clientScripts->serializeState(h.saving, scriptsState);
}
#endif
logNetwork->trace("Loaded client part of save %d ms", CSH->th->getDiff());
}
void CClient::save(const std::string & fname)
{
if(!gs->currentBattles.empty())

View File

@ -131,8 +131,6 @@ public:
void newGame(CGameState * gameState);
void loadGame(CGameState * gameState);
void serialize(BinarySerializer & h);
void serialize(BinaryDeserializer & h);
void save(const std::string & fname);
void endGame();

View File

@ -45,15 +45,6 @@ public:
int spellbookLastPageAdvmap = 0;
int spellbookLastTabBattle = 4;
int spellbookLastTabAdvmap = 4;
template<typename Handler>
void serialize(Handler & h)
{
h & spellbookLastPageBattle;
h & spellbookLastPageAdvmap;
h & spellbookLastTabBattle;
h & spellbookLastTabAdvmap;
}
} spellbookSettings;
explicit PlayerLocalState(CPlayerInterface & owner);
@ -92,22 +83,4 @@ public:
/// Changes currently selected object
void setSelection(const CArmedInstance *sel);
template<typename Handler>
void serialize(Handler & h)
{
//WARNING: this code is broken and not used. See CClient::loadGame
std::map<const CGHeroInstance *, int3> pathsMap; //hero -> dest
if(h.saving)
saveHeroPaths(pathsMap);
h & pathsMap;
if(!h.saving)
loadHeroPaths(pathsMap);
h & ownedTowns;
h & wanderingHeroes;
h & sleepingHeroes;
}
};

View File

@ -243,28 +243,4 @@ void CAdventureAI::yourTacticPhase(const BattleID & battleID, int distance)
battleAI->yourTacticPhase(battleID, distance);
}
void CAdventureAI::saveGame(BinarySerializer & h) /*saving */
{
bool hasBattleAI = static_cast<bool>(battleAI);
h & hasBattleAI;
if(hasBattleAI)
{
h & battleAI->dllName;
}
}
void CAdventureAI::loadGame(BinaryDeserializer & h) /*loading */
{
bool hasBattleAI = false;
h & hasBattleAI;
if(hasBattleAI)
{
std::string dllName;
h & dllName;
battleAI = CDynLibHandler::getNewBattleAI(dllName);
assert(cbc); //it should have been set by the one who new'ed us
battleAI->initBattleInterface(env, cbc);
}
}
VCMI_LIB_NAMESPACE_END

View File

@ -110,9 +110,6 @@ public:
virtual void showWorldViewEx(const std::vector<ObjectPosInfo> & objectPositions, bool showTerrain){};
virtual std::optional<BattleAction> makeSurrenderRetreatDecision(const BattleID & battleID, const BattleStateInfoForRetreat & battleState) = 0;
virtual void saveGame(BinarySerializer & h) = 0;
virtual void loadGame(BinaryDeserializer & h) = 0;
};
class DLL_LINKAGE CDynLibHandler
@ -161,9 +158,6 @@ public:
void battleSpellCast(const BattleID & battleID, const BattleSpellCast *sc) override;
void battleEnd(const BattleID & battleID, const BattleResult *br, QueryID queryID) override;
void battleUnitsChanged(const BattleID & battleID, const std::vector<UnitChanges> & units) override;
void saveGame(BinarySerializer & h) override;
void loadGame(BinaryDeserializer & h) override;
};
VCMI_LIB_NAMESPACE_END