diff --git a/AI/Nullkiller/AIGateway.h b/AI/Nullkiller/AIGateway.h index 00f1b7c2e..e4c52c23c 100644 --- a/AI/Nullkiller/AIGateway.h +++ b/AI/Nullkiller/AIGateway.h @@ -206,6 +206,7 @@ public: template void serializeInternal(Handler & h) { +#if 0 h & nullkiller->memory->knownTeleportChannels; h & nullkiller->memory->knownSubterraneanGates; h & destinationTeleport; @@ -213,6 +214,7 @@ public: h & nullkiller->memory->alreadyVisited; h & status; h & battlename; +#endif } }; diff --git a/AI/VCAI/Goals/Explore.cpp b/AI/VCAI/Goals/Explore.cpp index 4c25c74c0..294103598 100644 --- a/AI/VCAI/Goals/Explore.cpp +++ b/AI/VCAI/Goals/Explore.cpp @@ -53,7 +53,7 @@ namespace Goals { int3 tile = int3(0, 0, ourPos.z); - const auto & slice = (*(ts->fogOfWarMap))[ourPos.z]; + const auto & slice = ts->fogOfWarMap[ourPos.z]; for(tile.x = ourPos.x - scanRadius; tile.x <= ourPos.x + scanRadius; tile.x++) { @@ -81,13 +81,13 @@ namespace Goals foreach_tile_pos([&](const int3 & pos) { - if((*(ts->fogOfWarMap))[pos.z][pos.x][pos.y]) + if(ts->fogOfWarMap[pos.z][pos.x][pos.y]) { bool hasInvisibleNeighbor = false; foreach_neighbour(cbp, pos, [&](CCallback * cbp, int3 neighbour) { - if(!(*(ts->fogOfWarMap))[neighbour.z][neighbour.x][neighbour.y]) + if(!ts->fogOfWarMap[neighbour.z][neighbour.x][neighbour.y]) { hasInvisibleNeighbor = true; } @@ -171,7 +171,7 @@ namespace Goals { foreach_neighbour(cbp, tile, [&](CCallback * cbp, int3 neighbour) { - if((*(ts->fogOfWarMap))[neighbour.z][neighbour.x][neighbour.y]) + if(ts->fogOfWarMap[neighbour.z][neighbour.x][neighbour.y]) { out.push_back(neighbour); } @@ -184,7 +184,7 @@ namespace Goals int ret = 0; int3 npos = int3(0, 0, pos.z); - const auto & slice = (*(ts->fogOfWarMap))[pos.z]; + const auto & slice = ts->fogOfWarMap[pos.z]; for(npos.x = pos.x - sightRadius; npos.x <= pos.x + sightRadius; npos.x++) { diff --git a/AI/VCAI/VCAI.h b/AI/VCAI/VCAI.h index b5625c164..4ea15f797 100644 --- a/AI/VCAI/VCAI.h +++ b/AI/VCAI/VCAI.h @@ -303,6 +303,8 @@ public: template 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; @@ -358,6 +360,7 @@ public: h & heroesUnableToExplore; //myCB is restored after load by init call +#endif } }; diff --git a/lib/CArtHandler.h b/lib/CArtHandler.h index c840e8d45..2e0d13bc0 100644 --- a/lib/CArtHandler.h +++ b/lib/CArtHandler.h @@ -16,6 +16,7 @@ #include "bonuses/CBonusSystemNode.h" #include "GameConstants.h" #include "IHandlerBase.h" +#include "serializer/Serializeable.h" VCMI_LIB_NAMESPACE_BEGIN @@ -187,7 +188,7 @@ struct DLL_LINKAGE ArtSlotInfo } }; -class DLL_LINKAGE CArtifactSet +class DLL_LINKAGE CArtifactSet : public virtual Serializeable { public: using ArtPlacementMap = std::map; diff --git a/lib/CCreatureSet.h b/lib/CCreatureSet.h index 10654b46a..27a056fe3 100644 --- a/lib/CCreatureSet.h +++ b/lib/CCreatureSet.h @@ -11,6 +11,7 @@ #include "bonuses/Bonus.h" #include "bonuses/CBonusSystemNode.h" +#include "serializer/Serializeable.h" #include "GameConstants.h" #include "CArtHandler.h" #include "CArtifactInstance.h" @@ -208,7 +209,7 @@ namespace NArmyFormation static const std::vector names{ "wide", "tight" }; } -class DLL_LINKAGE CCreatureSet : public IArmyDescriptor //seven combined creatures +class DLL_LINKAGE CCreatureSet : public IArmyDescriptor, public virtual Serializeable //seven combined creatures { CCreatureSet(const CCreatureSet &) = delete; CCreatureSet &operator=(const CCreatureSet&); diff --git a/lib/CGameInfoCallback.cpp b/lib/CGameInfoCallback.cpp index 4385fad42..090059a7d 100644 --- a/lib/CGameInfoCallback.cpp +++ b/lib/CGameInfoCallback.cpp @@ -553,7 +553,7 @@ std::shared_ptr> CGameInfoCallback::ge for(tile.x = 0; tile.x < width; tile.x++) for(tile.y = 0; tile.y < height; tile.y++) { - if ((*team->fogOfWarMap)[tile.z][tile.x][tile.y]) + if (team->fogOfWarMap[tile.z][tile.x][tile.y]) (*ptr)[tile.z][tile.x][tile.y] = &gs->map->getTile(tile); else (*ptr)[tile.z][tile.x][tile.y] = nullptr; diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index b00c41afe..8436888bb 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -602,6 +602,7 @@ set(lib_MAIN_HEADERS serializer/JsonUpdater.h serializer/Cast.h serializer/ESerializationVersion.h + serializer/Serializeable.h spells/AbilityCaster.h spells/AdventureSpellMechanics.h diff --git a/lib/CPlayerState.h b/lib/CPlayerState.h index 071e3e9c5..516a52d0e 100644 --- a/lib/CPlayerState.h +++ b/lib/CPlayerState.h @@ -128,7 +128,7 @@ public: TeamID id; //position in gameState::teams std::set players; // members of this team //TODO: boost::array, bool if possible - std::unique_ptr> fogOfWarMap; //[z][x][y] true - visible, false - hidden + boost::multi_array fogOfWarMap; //[z][x][y] true - visible, false - hidden TeamState(); @@ -136,6 +136,18 @@ public: { h & id; h & players; + if (h.version < Handler::Version::REMOVE_FOG_OF_WAR_POINTER) + { + struct Helper : public Serializeable + { + void serialize(Handler &h) + {} + }; + Helper helper; + auto ptrHelper = &helper; + h & ptrHelper; + } + h & fogOfWarMap; h & static_cast(*this); } diff --git a/lib/CRandomGenerator.h b/lib/CRandomGenerator.h index 265b716a7..fe0dd2070 100644 --- a/lib/CRandomGenerator.h +++ b/lib/CRandomGenerator.h @@ -11,6 +11,7 @@ #pragma once #include +#include "serializer/Serializeable.h" VCMI_LIB_NAMESPACE_BEGIN @@ -27,7 +28,7 @@ using TRandI = std::function; /// The random generator randomly generates integers and real numbers("doubles") between /// a given range. This is a header only class and mainly a wrapper for /// convenient usage of the standard random API. An instance of this RNG is not thread safe. -class DLL_LINKAGE CRandomGenerator : public vstd::RNG, boost::noncopyable +class DLL_LINKAGE CRandomGenerator : public vstd::RNG, boost::noncopyable, public Serializeable { public: /// Seeds the generator by default with the product of the current time in milliseconds and the diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index ae7df063b..05e2f494d 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -103,8 +103,8 @@ void CPrivilegedInfoCallback::getTilesInRange(std::unordered_set & tiles, if(distance <= radious) { if(!player - || (mode == ETileVisibility::HIDDEN && (*team->fogOfWarMap)[pos.z][xd][yd] == 0) - || (mode == ETileVisibility::REVEALED && (*team->fogOfWarMap)[pos.z][xd][yd] == 1) + || (mode == ETileVisibility::HIDDEN && team->fogOfWarMap[pos.z][xd][yd] == 0) + || (mode == ETileVisibility::REVEALED && team->fogOfWarMap[pos.z][xd][yd] == 1) ) tiles.insert(int3(xd,yd,pos.z)); } diff --git a/lib/StartInfo.h b/lib/StartInfo.h index c221e4521..1e48eb0a8 100644 --- a/lib/StartInfo.h +++ b/lib/StartInfo.h @@ -15,6 +15,7 @@ #include "TurnTimerInfo.h" #include "ExtraOptionsInfo.h" #include "campaign/CampaignConstants.h" +#include "serializer/Serializeable.h" VCMI_LIB_NAMESPACE_BEGIN @@ -107,7 +108,7 @@ enum class EStartMode : int32_t }; /// Struct which describes the difficulty, the turn time,.. of a heroes match. -struct DLL_LINKAGE StartInfo +struct DLL_LINKAGE StartInfo : public Serializeable { EStartMode mode; ui8 difficulty; //0=easy; 4=impossible diff --git a/lib/battle/CObstacleInstance.h b/lib/battle/CObstacleInstance.h index c0607b031..8499f9bb5 100644 --- a/lib/battle/CObstacleInstance.h +++ b/lib/battle/CObstacleInstance.h @@ -9,9 +9,11 @@ */ #pragma once #include "BattleHex.h" + +#include "../constants/EntityIdentifiers.h" #include "../filesystem/ResourcePath.h" #include "../networkPacks/BattleChanges.h" -#include "../constants/EntityIdentifiers.h" +#include "../serializer/Serializeable.h" VCMI_LIB_NAMESPACE_BEGIN @@ -20,7 +22,7 @@ class ObstacleChanges; class JsonSerializeFormat; class SpellID; -struct DLL_LINKAGE CObstacleInstance +struct DLL_LINKAGE CObstacleInstance : public Serializeable { enum EObstacleType : ui8 { diff --git a/lib/bonuses/Bonus.h b/lib/bonuses/Bonus.h index 910bd4062..42edeb7bd 100644 --- a/lib/bonuses/Bonus.h +++ b/lib/bonuses/Bonus.h @@ -13,6 +13,7 @@ #include "BonusCustomTypes.h" #include "../constants/VariantIdentifier.h" #include "../constants/EntityIdentifiers.h" +#include "../serializer/Serializeable.h" #include "../MetaString.h" VCMI_LIB_NAMESPACE_BEGIN @@ -55,7 +56,7 @@ public: #define BONUS_TREE_DESERIALIZATION_FIX if(!h.saving && h.smartPointerSerialization) deserializationFix(); /// Struct for handling bonuses of several types. Can be transferred to any hero -struct DLL_LINKAGE Bonus : public std::enable_shared_from_this +struct DLL_LINKAGE Bonus : public std::enable_shared_from_this, public Serializeable { BonusDuration::Type duration = BonusDuration::PERMANENT; //uses BonusDuration values si16 turnsRemain = 0; //used if duration is N_TURNS, N_DAYS or ONE_WEEK diff --git a/lib/bonuses/CBonusSystemNode.h b/lib/bonuses/CBonusSystemNode.h index 9938a1978..a1eef1627 100644 --- a/lib/bonuses/CBonusSystemNode.h +++ b/lib/bonuses/CBonusSystemNode.h @@ -9,11 +9,11 @@ */ #pragma once -#include "GameConstants.h" - #include "BonusList.h" #include "IBonusBearer.h" +#include "../serializer/Serializeable.h" + VCMI_LIB_NAMESPACE_BEGIN using TNodes = std::set; @@ -21,7 +21,7 @@ using TCNodes = std::set; using TNodesVector = std::vector; using TCNodesVector = std::vector; -class DLL_LINKAGE CBonusSystemNode : public virtual IBonusBearer, public boost::noncopyable +class DLL_LINKAGE CBonusSystemNode : public virtual IBonusBearer, public virtual Serializeable, public boost::noncopyable { public: enum ENodeTypes diff --git a/lib/bonuses/Limiters.h b/lib/bonuses/Limiters.h index 6487f6cd9..db332c0f1 100644 --- a/lib/bonuses/Limiters.h +++ b/lib/bonuses/Limiters.h @@ -10,8 +10,9 @@ #include "Bonus.h" -#include "../GameConstants.h" #include "../battle/BattleHex.h" +#include "../serializer/Serializeable.h" +#include "../constants/Enumerations.h" VCMI_LIB_NAMESPACE_BEGIN @@ -27,7 +28,7 @@ struct BonusLimitationContext const BonusList & stillUndecided; }; -class DLL_LINKAGE ILimiter +class DLL_LINKAGE ILimiter : public Serializeable { public: enum class EDecision : uint8_t {ACCEPT, DISCARD, NOT_SURE}; diff --git a/lib/bonuses/Propagators.h b/lib/bonuses/Propagators.h index e9affb097..f0519d87d 100644 --- a/lib/bonuses/Propagators.h +++ b/lib/bonuses/Propagators.h @@ -12,11 +12,13 @@ #include "Bonus.h" #include "CBonusSystemNode.h" +#include "../serializer/Serializeable.h" + VCMI_LIB_NAMESPACE_BEGIN extern DLL_LINKAGE const std::map bonusPropagatorMap; -class DLL_LINKAGE IPropagator +class DLL_LINKAGE IPropagator : public Serializeable { public: virtual ~IPropagator() = default; @@ -42,4 +44,4 @@ public: } }; -VCMI_LIB_NAMESPACE_END \ No newline at end of file +VCMI_LIB_NAMESPACE_END diff --git a/lib/bonuses/Updaters.h b/lib/bonuses/Updaters.h index 8e3a7ed49..8d2c214f0 100644 --- a/lib/bonuses/Updaters.h +++ b/lib/bonuses/Updaters.h @@ -10,6 +10,7 @@ #pragma once #include "Bonus.h" +#include "../serializer/Serializeable.h" VCMI_LIB_NAMESPACE_BEGIN @@ -17,7 +18,7 @@ extern DLL_LINKAGE const std::map bonusUpdaterMap; // observers for updating bonuses based on certain events (e.g. hero gaining level) -class DLL_LINKAGE IUpdater +class DLL_LINKAGE IUpdater : public Serializeable { public: virtual ~IUpdater() = default; @@ -114,4 +115,4 @@ public: JsonNode toJsonNode() const override; }; -VCMI_LIB_NAMESPACE_END \ No newline at end of file +VCMI_LIB_NAMESPACE_END diff --git a/lib/campaign/CampaignState.h b/lib/campaign/CampaignState.h index ddc1b4451..c34be09eb 100644 --- a/lib/campaign/CampaignState.h +++ b/lib/campaign/CampaignState.h @@ -12,6 +12,7 @@ #include "../GameConstants.h" #include "../MetaString.h" #include "../filesystem/ResourcePath.h" +#include "../serializer/Serializeable.h" #include "../CGeneralTextHandler.h" #include "CampaignConstants.h" #include "CampaignScenarioPrologEpilog.h" @@ -214,7 +215,7 @@ struct DLL_LINKAGE CampaignScenario }; /// Class that represents loaded campaign information -class DLL_LINKAGE Campaign : public CampaignHeader +class DLL_LINKAGE Campaign : public CampaignHeader, public Serializeable { friend class CampaignHandler; diff --git a/lib/gameState/CGameState.cpp b/lib/gameState/CGameState.cpp index 59c8f4c92..054bde39f 100644 --- a/lib/gameState/CGameState.cpp +++ b/lib/gameState/CGameState.cpp @@ -693,8 +693,8 @@ void CGameState::initFogOfWar() for(auto & elem : teams) { auto & fow = elem.second.fogOfWarMap; - fow->resize(boost::extents[layers][map->width][map->height]); - std::fill(fow->data(), fow->data() + fow->num_elements(), 0); + fow.resize(boost::extents[layers][map->width][map->height]); + std::fill(fow.data(), fow.data() + fow.num_elements(), 0); for(CGObjectInstance *obj : map->objects) { @@ -704,7 +704,7 @@ void CGameState::initFogOfWar() getTilesInRange(tiles, obj->getSightCenter(), obj->getSightRadius(), ETileVisibility::HIDDEN, obj->tempOwner); for(const int3 & tile : tiles) { - (*elem.second.fogOfWarMap)[tile.z][tile.x][tile.y] = 1; + elem.second.fogOfWarMap[tile.z][tile.x][tile.y] = 1; } } } @@ -1326,7 +1326,7 @@ bool CGameState::isVisible(int3 pos, const std::optional & player) if(player->isSpectator()) return true; - return (*getPlayerTeam(*player)->fogOfWarMap)[pos.z][pos.x][pos.y]; + return getPlayerTeam(*player)->fogOfWarMap[pos.z][pos.x][pos.y]; } bool CGameState::isVisible(const CGObjectInstance * obj, const std::optional & player) const @@ -1957,7 +1957,6 @@ bool RumorState::update(int id, int extra) TeamState::TeamState() { setNodeType(TEAM); - fogOfWarMap = std::make_unique>(); } CRandomGenerator & CGameState::getRandomGenerator() diff --git a/lib/gameState/CGameState.h b/lib/gameState/CGameState.h index ce2a4b102..17bd55cf5 100644 --- a/lib/gameState/CGameState.h +++ b/lib/gameState/CGameState.h @@ -79,7 +79,7 @@ class BattleInfo; DLL_LINKAGE std::ostream & operator<<(std::ostream & os, const EVictoryLossCheckResult & victoryLossCheckResult); -class DLL_LINKAGE CGameState : public CNonConstInfoCallback +class DLL_LINKAGE CGameState : public CNonConstInfoCallback, public Serializeable { friend class CGameStateCampaign; diff --git a/lib/gameState/CGameStateCampaign.h b/lib/gameState/CGameStateCampaign.h index 2614d0621..4b4d6645e 100644 --- a/lib/gameState/CGameStateCampaign.h +++ b/lib/gameState/CGameStateCampaign.h @@ -11,6 +11,7 @@ #include "../GameConstants.h" #include "../campaign/CampaignConstants.h" +#include "../serializer/Serializeable.h" VCMI_LIB_NAMESPACE_BEGIN @@ -28,7 +29,7 @@ struct CampaignHeroReplacement std::vector transferrableArtifacts; }; -class CGameStateCampaign +class CGameStateCampaign : public Serializeable { CGameState * gameState; diff --git a/lib/gameState/TavernHeroesPool.h b/lib/gameState/TavernHeroesPool.h index ceab10c15..cc77d22d1 100644 --- a/lib/gameState/TavernHeroesPool.h +++ b/lib/gameState/TavernHeroesPool.h @@ -11,6 +11,8 @@ #include "../GameConstants.h" #include "TavernSlot.h" +#include "../serializer/Serializeable.h" + VCMI_LIB_NAMESPACE_BEGIN @@ -21,7 +23,7 @@ class CHeroClass; class CGameState; class CSimpleArmy; -class DLL_LINKAGE TavernHeroesPool +class DLL_LINKAGE TavernHeroesPool : public Serializeable { struct TavernSlot { diff --git a/lib/mapObjectConstructors/CBankInstanceConstructor.h b/lib/mapObjectConstructors/CBankInstanceConstructor.h index 5a609f5d2..fce4e8156 100644 --- a/lib/mapObjectConstructors/CBankInstanceConstructor.h +++ b/lib/mapObjectConstructors/CBankInstanceConstructor.h @@ -16,10 +16,11 @@ #include "../ResourceSet.h" #include "../json/JsonNode.h" #include "../mapObjects/CBank.h" +#include "../serializer/Serializeable.h" VCMI_LIB_NAMESPACE_BEGIN -struct BankConfig +struct BankConfig : public Serializeable { ui32 chance = 0; //chance for this level being chosen std::vector guards; //creature ID, amount diff --git a/lib/mapObjects/CGObjectInstance.h b/lib/mapObjects/CGObjectInstance.h index b1e4f144e..143118727 100644 --- a/lib/mapObjects/CGObjectInstance.h +++ b/lib/mapObjects/CGObjectInstance.h @@ -10,10 +10,11 @@ #pragma once #include "IObjectInterface.h" + +#include "../bonuses/BonusEnum.h" #include "../constants/EntityIdentifiers.h" #include "../filesystem/ResourcePath.h" #include "../int3.h" -#include "../bonuses/BonusEnum.h" VCMI_LIB_NAMESPACE_BEGIN diff --git a/lib/mapObjects/CQuest.h b/lib/mapObjects/CQuest.h index 69676584f..22748ecb0 100644 --- a/lib/mapObjects/CQuest.h +++ b/lib/mapObjects/CQuest.h @@ -12,6 +12,7 @@ #include "CRewardableObject.h" #include "../ResourceSet.h" #include "../MetaString.h" +#include "../serializer/Serializeable.h" VCMI_LIB_NAMESPACE_BEGIN @@ -36,7 +37,7 @@ enum class EQuestMission { HOTA_REACH_DATE = 13, }; -class DLL_LINKAGE CQuest final +class DLL_LINKAGE CQuest final : public Serializeable { public: @@ -74,13 +75,13 @@ public: CQuest(); //TODO: Remove constructor static bool checkMissionArmy(const CQuest * q, const CCreatureSet * army); - virtual bool checkQuest(const CGHeroInstance * h) const; //determines whether the quest is complete or not - virtual void getVisitText(IGameCallback * cb, MetaString &text, std::vector & components, bool FirstVisit, const CGHeroInstance * h = nullptr) const; - virtual void getCompletionText(IGameCallback * cb, MetaString &text) const; - virtual void getRolloverText (IGameCallback * cb, MetaString &text, bool onHover) const; //hover or quest log entry - virtual void completeQuest(IGameCallback *, const CGHeroInstance * h) const; - virtual void addTextReplacements(IGameCallback * cb, MetaString &out, std::vector & components) const; - virtual void addKillTargetReplacements(MetaString &out) const; + bool checkQuest(const CGHeroInstance * h) const; //determines whether the quest is complete or not + void getVisitText(IGameCallback * cb, MetaString &text, std::vector & components, bool FirstVisit, const CGHeroInstance * h = nullptr) const; + void getCompletionText(IGameCallback * cb, MetaString &text) const; + void getRolloverText (IGameCallback * cb, MetaString &text, bool onHover) const; //hover or quest log entry + void completeQuest(IGameCallback *, const CGHeroInstance * h) const; + void addTextReplacements(IGameCallback * cb, MetaString &out, std::vector & components) const; + void addKillTargetReplacements(MetaString &out) const; void defineQuestName(); bool operator== (const CQuest & quest) const @@ -114,7 +115,7 @@ public: void serializeJson(JsonSerializeFormat & handler, const std::string & fieldName); }; -class DLL_LINKAGE IQuestObject +class DLL_LINKAGE IQuestObject : public virtual Serializeable { public: CQuest * quest = new CQuest(); diff --git a/lib/mapObjects/IObjectInterface.h b/lib/mapObjects/IObjectInterface.h index 12d2baeb1..9a4e365b6 100644 --- a/lib/mapObjects/IObjectInterface.h +++ b/lib/mapObjects/IObjectInterface.h @@ -9,10 +9,11 @@ */ #pragma once +#include "../GameCallbackHolder.h" +#include "../constants/EntityIdentifiers.h" #include "../networkPacks/EInfoWindowMode.h" #include "../networkPacks/ObjProperty.h" -#include "../constants/EntityIdentifiers.h" -#include "../GameCallbackHolder.h" +#include "../serializer/Serializeable.h" VCMI_LIB_NAMESPACE_BEGIN @@ -29,7 +30,7 @@ class int3; class MetaString; class PlayerColor; -class DLL_LINKAGE IObjectInterface : public GameCallbackHolder +class DLL_LINKAGE IObjectInterface : public GameCallbackHolder, public virtual Serializeable { public: using GameCallbackHolder::GameCallbackHolder; diff --git a/lib/mapObjects/MiscObjects.h b/lib/mapObjects/MiscObjects.h index 6b74fc402..050197736 100644 --- a/lib/mapObjects/MiscObjects.h +++ b/lib/mapObjects/MiscObjects.h @@ -185,7 +185,7 @@ protected: void serializeJsonOptions(JsonSerializeFormat & handler) override; }; -struct DLL_LINKAGE TeleportChannel +struct DLL_LINKAGE TeleportChannel : public Serializeable { enum EPassability {UNKNOWN, IMPASSABLE, PASSABLE}; diff --git a/lib/mapObjects/ObjectTemplate.h b/lib/mapObjects/ObjectTemplate.h index 0ceb409a2..262df9c19 100644 --- a/lib/mapObjects/ObjectTemplate.h +++ b/lib/mapObjects/ObjectTemplate.h @@ -12,6 +12,7 @@ #include "../GameConstants.h" #include "../int3.h" #include "../filesystem/ResourcePath.h" +#include "../serializer/Serializeable.h" VCMI_LIB_NAMESPACE_BEGIN @@ -20,7 +21,7 @@ class CLegacyConfigParser; class JsonNode; class int3; -class DLL_LINKAGE ObjectTemplate +class DLL_LINKAGE ObjectTemplate : public Serializeable { enum EBlockMapBits { diff --git a/lib/mapping/CMapHeader.h b/lib/mapping/CMapHeader.h index 1dfeabef1..5a59825d6 100644 --- a/lib/mapping/CMapHeader.h +++ b/lib/mapping/CMapHeader.h @@ -13,7 +13,8 @@ #include "../constants/EntityIdentifiers.h" #include "../constants/Enumerations.h" #include "../constants/VariantIdentifier.h" -#include "../modding/CModInfo.h" +#include "../modding/ModVerificationInfo.h" +#include "../serializer/Serializeable.h" #include "../LogicalExpression.h" #include "../int3.h" #include "../MetaString.h" @@ -202,7 +203,7 @@ enum class EMapDifficulty : uint8_t }; /// The map header holds information about loss/victory condition,map format, version, players, height, width,... -class DLL_LINKAGE CMapHeader +class DLL_LINKAGE CMapHeader: public Serializeable { void setupEvents(); public: diff --git a/lib/mapping/CMapInfo.h b/lib/mapping/CMapInfo.h index 40e05baee..517670c05 100644 --- a/lib/mapping/CMapInfo.h +++ b/lib/mapping/CMapInfo.h @@ -9,6 +9,8 @@ */ #pragma once +#include "../serializer/Serializeable.h" + VCMI_LIB_NAMESPACE_BEGIN struct StartInfo; @@ -21,7 +23,7 @@ class ResourcePath; * A class which stores the count of human players and all players, the filename, * scenario options, the map header information,... */ -class DLL_LINKAGE CMapInfo +class DLL_LINKAGE CMapInfo : public Serializeable { public: std::unique_ptr mapHeader; //may be nullptr if campaign diff --git a/lib/networkPacks/NetPacksBase.h b/lib/networkPacks/NetPacksBase.h index 093cc2cb1..10544bc0d 100644 --- a/lib/networkPacks/NetPacksBase.h +++ b/lib/networkPacks/NetPacksBase.h @@ -10,6 +10,7 @@ #pragma once #include "../constants/EntityIdentifiers.h" +#include "../serializer/Serializeable.h" VCMI_LIB_NAMESPACE_BEGIN @@ -18,7 +19,7 @@ class CConnection; class ICPackVisitor; -struct DLL_LINKAGE CPack +struct DLL_LINKAGE CPack : public Serializeable { /// Pointer to connection that pack received from /// Only set & used on server diff --git a/lib/networkPacks/NetPacksLib.cpp b/lib/networkPacks/NetPacksLib.cpp index ead5778d2..cfbe01124 100644 --- a/lib/networkPacks/NetPacksLib.cpp +++ b/lib/networkPacks/NetPacksLib.cpp @@ -963,7 +963,7 @@ void FoWChange::applyGs(CGameState *gs) TeamState * team = gs->getPlayerTeam(player); auto & fogOfWarMap = team->fogOfWarMap; for(const int3 & t : tiles) - (*fogOfWarMap)[t.z][t.x][t.y] = mode != ETileVisibility::HIDDEN; + fogOfWarMap[t.z][t.x][t.y] = mode != ETileVisibility::HIDDEN; if (mode == ETileVisibility::HIDDEN) //do not hide too much { @@ -986,7 +986,7 @@ void FoWChange::applyGs(CGameState *gs) } } for(const int3 & t : tilesRevealed) //probably not the most optimal solution ever - (*fogOfWarMap)[t.z][t.x][t.y] = 1; + fogOfWarMap[t.z][t.x][t.y] = 1; } } @@ -1325,7 +1325,7 @@ void TryMoveHero::applyGs(CGameState *gs) auto & fogOfWarMap = gs->getPlayerTeam(h->getOwner())->fogOfWarMap; for(const int3 & t : fowRevealed) - (*fogOfWarMap)[t.z][t.x][t.y] = 1; + fogOfWarMap[t.z][t.x][t.y] = 1; } void NewStructures::applyGs(CGameState *gs) diff --git a/lib/pathfinder/PathfinderUtil.h b/lib/pathfinder/PathfinderUtil.h index 749cc513e..1a137d360 100644 --- a/lib/pathfinder/PathfinderUtil.h +++ b/lib/pathfinder/PathfinderUtil.h @@ -19,13 +19,13 @@ VCMI_LIB_NAMESPACE_BEGIN namespace PathfinderUtil { - using FoW = std::unique_ptr>; + using FoW = boost::multi_array; using ELayer = EPathfindingLayer; template EPathAccessibility evaluateAccessibility(const int3 & pos, const TerrainTile & tinfo, const FoW & fow, const PlayerColor player, const CGameState * gs) { - if(!(*fow)[pos.z][pos.x][pos.y]) + if(!fow[pos.z][pos.x][pos.y]) return EPathAccessibility::BLOCKED; switch(layer) diff --git a/lib/rewardable/Limiter.h b/lib/rewardable/Limiter.h index 969bcd576..e95e6459a 100644 --- a/lib/rewardable/Limiter.h +++ b/lib/rewardable/Limiter.h @@ -12,6 +12,7 @@ #include "../GameConstants.h" #include "../ResourceSet.h" +#include "../serializer/Serializeable.h" VCMI_LIB_NAMESPACE_BEGIN @@ -26,7 +27,7 @@ using LimitersList = std::vector>; /// Limiters of rewards. Rewards will be granted to hero only if he satisfies requirements /// Note: for this is only a test - it won't remove anything from hero (e.g. artifacts or creatures) -struct DLL_LINKAGE Limiter final +struct DLL_LINKAGE Limiter final : public Serializeable { /// day of week, unused if 0, 1-7 will test for current day of week si32 dayOfWeek; diff --git a/lib/rmg/CMapGenOptions.h b/lib/rmg/CMapGenOptions.h index 2055d58e5..b4c613b56 100644 --- a/lib/rmg/CMapGenOptions.h +++ b/lib/rmg/CMapGenOptions.h @@ -11,6 +11,7 @@ #pragma once #include "../GameConstants.h" +#include "../serializer/Serializeable.h" #include "CRmgTemplate.h" VCMI_LIB_NAMESPACE_BEGIN @@ -26,7 +27,7 @@ enum class EPlayerType /// The map gen options class holds values about general map generation settings /// e.g. the size of the map, the count of players,... -class DLL_LINKAGE CMapGenOptions +class DLL_LINKAGE CMapGenOptions : public Serializeable { public: /// The player settings class maps the player color, starting town and human player flag. diff --git a/lib/serializer/BinaryDeserializer.h b/lib/serializer/BinaryDeserializer.h index c12a2b11a..0c7da5634 100644 --- a/lib/serializer/BinaryDeserializer.h +++ b/lib/serializer/BinaryDeserializer.h @@ -119,7 +119,7 @@ class DLL_LINKAGE BinaryDeserializer : public CLoaderBase class IPointerLoader { public: - virtual void * loadPtr(CLoaderBase &ar, IGameCallback * cb, ui32 pid) const =0; //data is pointer to the ACTUAL POINTER + virtual Serializeable * loadPtr(CLoaderBase &ar, IGameCallback * cb, ui32 pid) const =0; //data is pointer to the ACTUAL POINTER virtual ~IPointerLoader() = default; template static IPointerLoader *getApplier(const Type * t = nullptr) @@ -132,7 +132,7 @@ class DLL_LINKAGE BinaryDeserializer : public CLoaderBase class CPointerLoader : public IPointerLoader { public: - void * loadPtr(CLoaderBase &ar, IGameCallback * cb, ui32 pid) const override //data is pointer to the ACTUAL POINTER + Serializeable * loadPtr(CLoaderBase &ar, IGameCallback * cb, ui32 pid) const override //data is pointer to the ACTUAL POINTER { auto & s = static_cast(ar); @@ -142,7 +142,7 @@ class DLL_LINKAGE BinaryDeserializer : public CLoaderBase ptr->serialize(s); - return static_cast(ptr); + return static_cast(ptr); } }; @@ -157,8 +157,8 @@ public: Version version; std::vector loadedStrings; - std::map loadedPointers; - std::map> loadedSharedPointers; + std::map loadedPointers; + std::map> loadedSharedPointers; IGameCallback * cb = nullptr; bool smartPointerSerialization; bool saving; @@ -355,7 +355,7 @@ public: { // We already got this pointer // Cast it in case we are loading it to a non-first base pointer - data = static_cast(i->second); + data = dynamic_cast(i->second); return; } } @@ -380,15 +380,15 @@ public: data = nullptr; return; } - data = static_cast(app->loadPtr(*this, cb, pid)); + data = dynamic_cast(app->loadPtr(*this, cb, pid)); } } template - void ptrAllocated(const T *ptr, ui32 pid) + void ptrAllocated(T *ptr, ui32 pid) { if(smartPointerSerialization && pid != 0xffffffff) - loadedPointers[pid] = (void*)ptr; //add loaded pointer to our lookup map; cast is to avoid errors with const T* pt + loadedPointers[pid] = const_cast(dynamic_cast(ptr)); //add loaded pointer to our lookup map; cast is to avoid errors with const T* pt } template void registerType(const Base * b = nullptr, const Derived * d = nullptr) @@ -403,7 +403,7 @@ public: NonConstT *internalPtr; load(internalPtr); - void * internalPtrDerived = static_cast(internalPtr); + Serializeable * internalPtrDerived = static_cast(internalPtr); if(internalPtr) { @@ -418,7 +418,7 @@ public: { auto hlp = std::shared_ptr(internalPtr); data = hlp; - loadedSharedPointers[internalPtrDerived] = std::static_pointer_cast(hlp); + loadedSharedPointers[internalPtrDerived] = std::static_pointer_cast(hlp); } } else diff --git a/lib/serializer/BinarySerializer.h b/lib/serializer/BinarySerializer.h index 4aa8d3117..c7da7cb5d 100644 --- a/lib/serializer/BinarySerializer.h +++ b/lib/serializer/BinarySerializer.h @@ -12,6 +12,7 @@ #include "CSerializer.h" #include "CTypeList.h" #include "ESerializationVersion.h" +#include "Serializeable.h" #include "../mapObjects/CArmedInstance.h" VCMI_LIB_NAMESPACE_BEGIN @@ -114,7 +115,7 @@ public: using Version = ESerializationVersion; std::map savedStrings; - std::map savedPointers; + std::map savedPointers; const Version version = Version::CURRENT; bool smartPointerSerialization; @@ -268,7 +269,7 @@ public: { // We might have an object that has multiple inheritance and store it via the non-first base pointer. // Therefore, all pointers need to be normalized to the actual object address. - const void * actualPointer = static_cast(data); + const Serializeable * actualPointer = static_cast(data); auto i = savedPointers.find(actualPointer); if(i != savedPointers.end()) { diff --git a/lib/serializer/ESerializationVersion.h b/lib/serializer/ESerializationVersion.h index 2cdfefc32..09de0e531 100644 --- a/lib/serializer/ESerializationVersion.h +++ b/lib/serializer/ESerializationVersion.h @@ -46,6 +46,7 @@ enum class ESerializationVersion : int32_t COMPACT_STRING_SERIALIZATION, COMPACT_INTEGER_SERIALIZATION, + REMOVE_FOG_OF_WAR_POINTER, - CURRENT = COMPACT_INTEGER_SERIALIZATION + CURRENT = REMOVE_FOG_OF_WAR_POINTER }; diff --git a/lib/serializer/Serializeable.h b/lib/serializer/Serializeable.h new file mode 100644 index 000000000..a0ab5927a --- /dev/null +++ b/lib/serializer/Serializeable.h @@ -0,0 +1,21 @@ +/* + * Serializeable.h, part of VCMI engine + * + * Authors: listed in file AUTHORS in main folder + * + * License: GNU General Public License v2.0 or later + * Full text of license available in license.txt file, in main folder + * + */ +#pragma once + +VCMI_LIB_NAMESPACE_BEGIN + +// Tag class that acts as base for all classes that can be serialized by pointer +class Serializeable +{ +public: + virtual ~Serializeable() = default; +}; + +VCMI_LIB_NAMESPACE_END diff --git a/lib/spells/AdventureSpellMechanics.cpp b/lib/spells/AdventureSpellMechanics.cpp index 2cd65a1b6..db3e97ab1 100644 --- a/lib/spells/AdventureSpellMechanics.cpp +++ b/lib/spells/AdventureSpellMechanics.cpp @@ -735,7 +735,7 @@ ESpellCastResult ViewMechanics::applyAdventureEffects(SpellCastEnvironment * env { ObjectPosInfo posInfo(obj); - if((*fowMap)[posInfo.pos.z][posInfo.pos.x][posInfo.pos.y] == 0) + if(fowMap[posInfo.pos.z][posInfo.pos.x][posInfo.pos.y] == 0) pack.objectPositions.push_back(posInfo); } } diff --git a/server/CGameHandler.cpp b/server/CGameHandler.cpp index 538da0405..6eec0b4a3 100644 --- a/server/CGameHandler.cpp +++ b/server/CGameHandler.cpp @@ -884,11 +884,11 @@ void CGameHandler::onNewTurn() // find all hidden tiles const auto & fow = getPlayerTeam(player)->fogOfWarMap; - auto shape = fow->shape(); + auto shape = fow.shape(); for(size_t z = 0; z < shape[0]; z++) for(size_t x = 0; x < shape[1]; x++) for(size_t y = 0; y < shape[2]; y++) - if (!(*fow)[z][x][y]) + if (!fow[z][x][y]) fw.tiles.insert(int3(x, y, z)); sendAndApply (&fw); diff --git a/server/processors/PlayerMessageProcessor.cpp b/server/processors/PlayerMessageProcessor.cpp index b292d86a9..188afa295 100644 --- a/server/processors/PlayerMessageProcessor.cpp +++ b/server/processors/PlayerMessageProcessor.cpp @@ -367,7 +367,7 @@ void PlayerMessageProcessor::cheatMapReveal(PlayerColor player, bool reveal) for(int z = 0; z < mapSize.z; z++) for(int x = 0; x < mapSize.x; x++) for(int y = 0; y < mapSize.y; y++) - if(!(*fowMap)[z][x][y] || fc.mode == ETileVisibility::HIDDEN) + if(!fowMap[z][x][y] || fc.mode == ETileVisibility::HIDDEN) hlp_tab[lastUnc++] = int3(x, y, z); fc.tiles.insert(hlp_tab, hlp_tab + lastUnc);