1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-29 23:07:48 +02:00

Added explicit indexing of type indexes for serialization

This commit is contained in:
Ivan Savenko
2024-08-23 23:02:17 +00:00
parent 01396b62b7
commit 77faa14119
13 changed files with 315 additions and 466 deletions

View File

@@ -564,12 +564,6 @@ set(lib_MAIN_HEADERS
pathfinder/PathfindingRules.h
pathfinder/TurnInfo.h
registerTypes/RegisterTypes.h
registerTypes/RegisterTypesClientPacks.h
registerTypes/RegisterTypesLobbyPacks.h
registerTypes/RegisterTypesMapObjects.h
registerTypes/RegisterTypesServerPacks.h
rewardable/Configuration.h
rewardable/Info.h
rewardable/Interface.h
@@ -626,6 +620,7 @@ set(lib_MAIN_HEADERS
serializer/JsonUpdater.h
serializer/Cast.h
serializer/ESerializationVersion.h
serializer/RegisterTypes.h
serializer/Serializeable.h
serializer/SerializerReflection.h

View File

@@ -1,28 +0,0 @@
/*
* RegisterTypes.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
#include "RegisterTypesClientPacks.h"
#include "RegisterTypesLobbyPacks.h"
#include "RegisterTypesMapObjects.h"
#include "RegisterTypesServerPacks.h"
VCMI_LIB_NAMESPACE_BEGIN
template<typename Serializer>
void registerTypes(Serializer &s)
{
registerTypesMapObjects(s);
registerTypesClientPacks(s);
registerTypesServerPacks(s);
registerTypesLobbyPacks(s);
}
VCMI_LIB_NAMESPACE_END

View File

@@ -1,126 +0,0 @@
/*
* RegisterTypesClientPacks.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
#include "../networkPacks/PacksForClient.h"
#include "../networkPacks/PacksForClientBattle.h"
#include "../networkPacks/SetStackEffect.h"
#include "../networkPacks/SetRewardableConfiguration.h"
VCMI_LIB_NAMESPACE_BEGIN
template<typename Serializer>
void registerTypesClientPacks(Serializer &s)
{
s.template registerType<CPack, CPackForClient>();
s.template registerType<CPackForClient, PackageApplied>();
s.template registerType<CPackForClient, SystemMessage>();
s.template registerType<CPackForClient, PlayerBlocked>();
s.template registerType<CPackForClient, PlayerCheated>();
s.template registerType<CPackForClient, PlayerStartsTurn>();
s.template registerType<CPackForClient, DaysWithoutTown>();
s.template registerType<CPackForClient, TurnTimeUpdate>();
s.template registerType<CPackForClient, SetResources>();
s.template registerType<CPackForClient, SetPrimSkill>();
s.template registerType<CPackForClient, SetSecSkill>();
s.template registerType<CPackForClient, HeroVisitCastle>();
s.template registerType<CPackForClient, ChangeSpells>();
s.template registerType<CPackForClient, SetMana>();
s.template registerType<CPackForClient, SetMovePoints>();
s.template registerType<CPackForClient, FoWChange>();
s.template registerType<CPackForClient, SetAvailableHero>();
s.template registerType<CPackForClient, GiveBonus>();
s.template registerType<CPackForClient, ChangeObjPos>();
s.template registerType<CPackForClient, PlayerEndsTurn>();
s.template registerType<CPackForClient, PlayerEndsGame>();
s.template registerType<CPackForClient, PlayerReinitInterface>();
s.template registerType<CPackForClient, RemoveBonus>();
s.template registerType<CPackForClient, UpdateArtHandlerLists>();
s.template registerType<CPackForClient, ChangeFormation>();
s.template registerType<CPackForClient, RemoveObject>();
s.template registerType<CPackForClient, TryMoveHero>();
s.template registerType<CPackForClient, NewStructures>();
s.template registerType<CPackForClient, RazeStructures>();
s.template registerType<CPackForClient, SetAvailableCreatures>();
s.template registerType<CPackForClient, SetHeroesInTown>();
s.template registerType<CPackForClient, HeroRecruited>();
s.template registerType<CPackForClient, GiveHero>();
s.template registerType<CPackForClient, NewTurn>();
s.template registerType<CPackForClient, InfoWindow>();
s.template registerType<CPackForClient, SetObjectProperty>();
s.template registerType<CPackForClient, AdvmapSpellCast>();
s.template registerType<CPackForClient, OpenWindow>();
s.template registerType<CPackForClient, NewObject>();
s.template registerType<CPackForClient, NewArtifact>();
s.template registerType<CPackForClient, AddQuest>();
s.template registerType<CPackForClient, SetAvailableArtifacts>();
s.template registerType<CPackForClient, CenterView>();
s.template registerType<CPackForClient, HeroVisit>();
s.template registerType<CPackForClient, SetCommanderProperty>();
s.template registerType<CPackForClient, ChangeObjectVisitors>();
s.template registerType<CPackForClient, ChangeArtifactsCostume>();
s.template registerType<CPackForClient, ShowWorldViewEx>();
s.template registerType<CPackForClient, EntitiesChanged>();
s.template registerType<CPackForClient, BattleStart>();
s.template registerType<CPackForClient, BattleNextRound>();
s.template registerType<CPackForClient, BattleSetActiveStack>();
s.template registerType<CPackForClient, BattleResult>();
s.template registerType<CPackForClient, BattleResultAccepted>();
s.template registerType<CPackForClient, BattleCancelled>();
s.template registerType<CPackForClient, BattleLogMessage>();
s.template registerType<CPackForClient, BattleStackMoved>();
s.template registerType<CPackForClient, BattleAttack>();
s.template registerType<CPackForClient, StartAction>();
s.template registerType<CPackForClient, EndAction>();
s.template registerType<CPackForClient, BattleSpellCast>();
s.template registerType<CPackForClient, SetStackEffect>();
s.template registerType<CPackForClient, BattleTriggerEffect>();
s.template registerType<CPackForClient, BattleUpdateGateState>();
s.template registerType<CPackForClient, BattleSetStackProperty>();
s.template registerType<CPackForClient, StacksInjured>();
s.template registerType<CPackForClient, BattleResultsApplied>();
s.template registerType<CPackForClient, BattleUnitsChanged>();
s.template registerType<CPackForClient, BattleObstaclesChanged>();
s.template registerType<CPackForClient, CatapultAttack>();
s.template registerType<CPackForClient, Query>();
s.template registerType<Query, HeroLevelUp>();
s.template registerType<Query, CommanderLevelUp>();
s.template registerType<Query, BlockingDialog>();
s.template registerType<Query, GarrisonDialog>();
s.template registerType<Query, ExchangeDialog>();
s.template registerType<Query, TeleportDialog>();
s.template registerType<Query, MapObjectSelectDialog>();
s.template registerType<CPackForClient, CGarrisonOperationPack>();
s.template registerType<CGarrisonOperationPack, ChangeStackCount>();
s.template registerType<CGarrisonOperationPack, SetStackType>();
s.template registerType<CGarrisonOperationPack, EraseStack>();
s.template registerType<CGarrisonOperationPack, SwapStacks>();
s.template registerType<CGarrisonOperationPack, InsertNewStack>();
s.template registerType<CGarrisonOperationPack, RebalanceStacks>();
s.template registerType<CPackForClient, CArtifactOperationPack>();
s.template registerType<CArtifactOperationPack, PutArtifact>();
s.template registerType<CArtifactOperationPack, EraseArtifact>();
s.template registerType<CArtifactOperationPack, AssembledArtifact>();
s.template registerType<CArtifactOperationPack, DisassembledArtifact>();
s.template registerType<CArtifactOperationPack, BulkMoveArtifacts>();
s.template registerType<CPackForClient, PlayerMessageClient>();
s.template registerType<CGarrisonOperationPack, BulkRebalanceStacks>();
s.template registerType<CGarrisonOperationPack, BulkSmartRebalanceStacks>();
s.template registerType<SetRewardableConfiguration, CPackForClient>();
s.template registerType<SetBankConfiguration, CPackForClient>();
}
VCMI_LIB_NAMESPACE_END

View File

@@ -1,66 +0,0 @@
/*
* RegisterTypesLobbyPacks.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
#include "../networkPacks/PacksForLobby.h"
#include "../gameState/CGameState.h"
#include "../campaign/CampaignState.h"
#include "../mapping/CMapInfo.h"
#include "../rmg/CMapGenOptions.h"
#include "../gameState/TavernHeroesPool.h"
#include "../gameState/CGameStateCampaign.h"
#include "../mapping/CMap.h"
#include "../TerrainHandler.h"
#include "../RiverHandler.h"
#include "../RoadHandler.h"
VCMI_LIB_NAMESPACE_BEGIN
template<typename Serializer>
void registerTypesLobbyPacks(Serializer &s)
{
s.template registerType<CPack, CPackForLobby>();
s.template registerType<CPackForLobby, CLobbyPackToPropagate>();
s.template registerType<CPackForLobby, CLobbyPackToServer>();
// Any client can sent
s.template registerType<CLobbyPackToPropagate, LobbyClientConnected>();
s.template registerType<CLobbyPackToPropagate, LobbyClientDisconnected>();
s.template registerType<CLobbyPackToPropagate, LobbyChatMessage>();
s.template registerType<CLobbyPackToServer, LobbyPvPAction>();
// Only host client send
s.template registerType<CLobbyPackToPropagate, LobbyGuiAction>();
s.template registerType<CLobbyPackToPropagate, LobbyLoadProgress>();
s.template registerType<CLobbyPackToPropagate, LobbyRestartGame>();
s.template registerType<CLobbyPackToPropagate, LobbyPrepareStartGame>();
s.template registerType<CLobbyPackToPropagate, LobbyStartGame>();
s.template registerType<CLobbyPackToPropagate, LobbyChangeHost>();
// Only server send
s.template registerType<CLobbyPackToPropagate, LobbyUpdateState>();
s.template registerType<CLobbyPackToPropagate, LobbyShowMessage>();
// For client with permissions
s.template registerType<CLobbyPackToServer, LobbyChangePlayerOption>();
// Only for host client
s.template registerType<CLobbyPackToServer, LobbySetMap>();
s.template registerType<CLobbyPackToServer, LobbySetCampaign>();
s.template registerType<CLobbyPackToServer, LobbySetCampaignMap>();
s.template registerType<CLobbyPackToServer, LobbySetCampaignBonus>();
s.template registerType<CLobbyPackToServer, LobbySetPlayer>();
s.template registerType<CLobbyPackToServer, LobbySetPlayerName>();
s.template registerType<CLobbyPackToServer, LobbySetPlayerHandicap>();
s.template registerType<CLobbyPackToServer, LobbySetTurnTime>();
s.template registerType<CLobbyPackToServer, LobbySetSimturns>();
s.template registerType<CLobbyPackToServer, LobbySetDifficulty>();
s.template registerType<CLobbyPackToServer, LobbyForceSetPlayer>();
s.template registerType<CLobbyPackToServer, LobbySetExtraOptions>();
}
VCMI_LIB_NAMESPACE_END

View File

@@ -1,138 +0,0 @@
/*
* RegisterTypesMapObjects.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
#include "../mapObjectConstructors/CBankInstanceConstructor.h"
#include "../mapObjects/MapObjects.h"
#include "../mapObjects/CGCreature.h"
#include "../mapObjects/TownBuildingInstance.h"
#include "../mapObjects/ObjectTemplate.h"
#include "../battle/BattleInfo.h"
#include "../battle/CObstacleInstance.h"
#include "../bonuses/Limiters.h"
#include "../bonuses/Updaters.h"
#include "../bonuses/Propagators.h"
#include "../CPlayerState.h"
#include "../CStack.h"
#include "../CHeroHandler.h"
VCMI_LIB_NAMESPACE_BEGIN
template<typename Serializer>
void registerTypesMapObjects(Serializer &s)
{
//////////////////////////////////////////////////////////////////////////
// Adventure map objects
//////////////////////////////////////////////////////////////////////////
s.template registerType<IObjectInterface, CGObjectInstance>();
// Non-armed objects
s.template registerType<CGObjectInstance, CGTeleport>();
s.template registerType<CGTeleport, CGMonolith>();
s.template registerType<CGMonolith, CGSubterraneanGate>();
s.template registerType<CGMonolith, CGWhirlpool>();
s.template registerType<CGObjectInstance, CGSignBottle>();
s.template registerType<CGObjectInstance, CGKeys>();
s.template registerType<CGKeys, CGKeymasterTent>();
s.template registerType<CGKeys, CGBorderGuard>(); s.template registerType<IQuestObject, CGBorderGuard>();
s.template registerType<CGBorderGuard, CGBorderGate>();
s.template registerType<CGObjectInstance, CGBoat>();
s.template registerType<CGObjectInstance, CGMagi>();
s.template registerType<CGObjectInstance, CGSirens>();
s.template registerType<CGObjectInstance, CGShipyard>();
s.template registerType<CGObjectInstance, CGDenOfthieves>();
s.template registerType<CGObjectInstance, CGLighthouse>();
s.template registerType<CGObjectInstance, CGTerrainPatch>();
s.template registerType<CGObjectInstance, HillFort>();
s.template registerType<CGObjectInstance, CGMarket>();
s.template registerType<CGMarket, CGBlackMarket>();
s.template registerType<CGMarket, CGUniversity>();
s.template registerType<CGObjectInstance, CGHeroPlaceholder>();
s.template registerType<CGObjectInstance, CArmedInstance>(); s.template registerType<CBonusSystemNode, CArmedInstance>(); s.template registerType<CCreatureSet, CArmedInstance>();
// Armed objects
s.template registerType<CArmedInstance, CGHeroInstance>(); s.template registerType<CArtifactSet, CGHeroInstance>();
s.template registerType<CArmedInstance, CGDwelling>();
s.template registerType<CGDwelling, CGTownInstance>();
s.template registerType<CArmedInstance, CGPandoraBox>();
s.template registerType<CGPandoraBox, CGEvent>();
s.template registerType<CArmedInstance, CGCreature>();
s.template registerType<CArmedInstance, CGGarrison>();
s.template registerType<CArmedInstance, CGArtifact>();
s.template registerType<CArmedInstance, CGResource>();
s.template registerType<CArmedInstance, CGMine>();
s.template registerType<CArmedInstance, CBank>();
s.template registerType<CArmedInstance, CGSeerHut>(); s.template registerType<IQuestObject, CGSeerHut>();
s.template registerType<CGSeerHut, CGQuestGuard>();
s.template registerType<IUpdater, GrowsWithLevelUpdater>();
s.template registerType<IUpdater, TimesHeroLevelUpdater>();
s.template registerType<IUpdater, TimesStackLevelUpdater>();
s.template registerType<IUpdater, OwnerUpdater>();
s.template registerType<IUpdater, ArmyMovementUpdater>();
s.template registerType<ILimiter, AnyOfLimiter>();
s.template registerType<ILimiter, NoneOfLimiter>();
s.template registerType<ILimiter, OppositeSideLimiter>();
//new types (other than netpacks) must register here
//order of type registration is critical for loading old savegames
//Other object-related
s.template registerType<IObjectInterface, TownBuildingInstance>();
s.template registerType<TownBuildingInstance, TownRewardableBuildingInstance>();
s.template registerType<TownBuildingInstance, CTownCompatBuilding1>();
s.template registerType<TownBuildingInstance, CTownCompatBuilding2>();
s.template registerType<CGObjectInstance, CRewardableObject>();
s.template registerType<CGObjectInstance, CTeamVisited>();
s.template registerType<CTeamVisited, CGObelisk>();
//end of objects
//////////////////////////////////////////////////////////////////////////
// Bonus system
//////////////////////////////////////////////////////////////////////////
//s.template registerType<IPropagator>();
s.template registerType<IPropagator, CPropagatorNodeType>();
// Limiters
//s.template registerType<ILimiter>();
s.template registerType<ILimiter, AllOfLimiter>();
s.template registerType<ILimiter, CCreatureTypeLimiter>();
s.template registerType<ILimiter, HasAnotherBonusLimiter>();
s.template registerType<ILimiter, CreatureTerrainLimiter>();
s.template registerType<ILimiter, FactionLimiter>();
s.template registerType<ILimiter, CreatureLevelLimiter>();
s.template registerType<ILimiter, CreatureAlignmentLimiter>();
s.template registerType<ILimiter, RankRangeLimiter>();
s.template registerType<ILimiter, UnitOnHexLimiter>();
// s.template registerType<CBonusSystemNode>();
s.template registerType<CBonusSystemNode, CArtifact>();
s.template registerType<CBonusSystemNode, CCreature>();
s.template registerType<CBonusSystemNode, CStackInstance>();
s.template registerType<CStackInstance, CCommanderInstance>();
s.template registerType<CBonusSystemNode, PlayerState>();
s.template registerType<CBonusSystemNode, TeamState>();
//s.template registerType<CGameState>(); //TODO
//s.template registerType<CArmedInstance>();
s.template registerType<CBonusSystemNode, CStack>();
s.template registerType<CBonusSystemNode, BattleInfo>();
//s.template registerType<QuestInfo>();
s.template registerType<CBonusSystemNode, CArtifactInstance>();
//s.template registerType<CObstacleInstance>();
s.template registerType<CObstacleInstance, SpellCreatedObstacle>();
s.template registerType<IMarket, CGMarket>();
}
VCMI_LIB_NAMESPACE_END

View File

@@ -1,59 +0,0 @@
/*
* RegisterTypesServerPacks.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
#include "../networkPacks/PacksForServer.h"
VCMI_LIB_NAMESPACE_BEGIN
class BinarySerializer;
class BinaryDeserializer;
class CTypeList;
template<typename Serializer>
void registerTypesServerPacks(Serializer &s)
{
s.template registerType<CPack, CPackForServer>();
s.template registerType<CPackForServer, EndTurn>();
s.template registerType<CPackForServer, DismissHero>();
s.template registerType<CPackForServer, MoveHero>();
s.template registerType<CPackForServer, ArrangeStacks>();
s.template registerType<CPackForServer, DisbandCreature>();
s.template registerType<CPackForServer, BuildStructure>();
s.template registerType<CPackForServer, TriggerTownSpecialBuildingAction>();
s.template registerType<CPackForServer, RecruitCreatures>();
s.template registerType<CPackForServer, UpgradeCreature>();
s.template registerType<CPackForServer, GarrisonHeroSwap>();
s.template registerType<CPackForServer, ExchangeArtifacts>();
s.template registerType<CPackForServer, AssembleArtifacts>();
s.template registerType<CPackForServer, BuyArtifact>();
s.template registerType<CPackForServer, TradeOnMarketplace>();
s.template registerType<CPackForServer, SetFormation>();
s.template registerType<CPackForServer, HireHero>();
s.template registerType<CPackForServer, BuildBoat>();
s.template registerType<CPackForServer, QueryReply>();
s.template registerType<CPackForServer, MakeAction>();
s.template registerType<CPackForServer, DigWithHero>();
s.template registerType<CPackForServer, CastAdvSpell>();
s.template registerType<CPackForServer, CastleTeleportHero>();
s.template registerType<CPackForServer, SaveGame>();
s.template registerType<CPackForServer, PlayerMessage>();
s.template registerType<CPackForServer, BulkSplitStack>();
s.template registerType<CPackForServer, BulkMergeStacks>();
s.template registerType<CPackForServer, BulkSmartSplitStack>();
s.template registerType<CPackForServer, BulkMoveArmy>();
s.template registerType<CPackForServer, BulkExchangeArtifacts>();
s.template registerType<CPackForServer, ManageBackpackArtifacts>();
s.template registerType<CPackForServer, ManageEquippedArtifacts>();
s.template registerType<CPackForServer, EraseArtifactByClient>();
s.template registerType<CPackForServer, GamePause>();
}
VCMI_LIB_NAMESPACE_END

View File

@@ -9,7 +9,6 @@
*/
#include "StdInc.h"
#include "BinaryDeserializer.h"
#include "../registerTypes/RegisterTypes.h"
VCMI_LIB_NAMESPACE_BEGIN

View File

@@ -9,7 +9,6 @@
*/
#include "StdInc.h"
#include "BinarySerializer.h"
#include "../registerTypes/RegisterTypes.h"
VCMI_LIB_NAMESPACE_BEGIN

View File

@@ -10,7 +10,7 @@
#include "StdInc.h"
#include "CTypeList.h"
#include "../registerTypes/RegisterTypes.h"
#include "RegisterTypes.h"
VCMI_LIB_NAMESPACE_BEGIN

View File

@@ -36,22 +36,15 @@ public:
return registry;
}
template<typename T, typename U>
void registerType()
{
registerType<T>();
registerType<U>();
}
template<typename T>
void registerType()
void registerType(uint16_t index)
{
const std::type_info & typeInfo = typeid(T);
if (typeInfos.count(typeInfo.name()) != 0)
return;
typeInfos[typeInfo.name()] = typeInfos.size() + 1;
typeInfos[typeInfo.name()] = index;
}
template<typename T>

View File

@@ -0,0 +1,302 @@
/*
* RegisterTypes.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
#include "../CHeroHandler.h"
#include "../CPlayerState.h"
#include "../CStack.h"
#include "../RiverHandler.h"
#include "../RoadHandler.h"
#include "../TerrainHandler.h"
#include "../battle/BattleInfo.h"
#include "../battle/CObstacleInstance.h"
#include "../bonuses/Limiters.h"
#include "../bonuses/Propagators.h"
#include "../bonuses/Updaters.h"
#include "../campaign/CampaignState.h"
#include "../gameState/CGameState.h"
#include "../gameState/CGameStateCampaign.h"
#include "../gameState/TavernHeroesPool.h"
#include "../mapObjects/CGCreature.h"
#include "../mapObjects/CGDwelling.h"
#include "../mapObjects/CGMarket.h"
#include "../mapObjects/CGPandoraBox.h"
#include "../mapObjects/CGTownInstance.h"
#include "../mapObjects/CQuest.h"
#include "../mapObjects/MiscObjects.h"
#include "../mapObjects/ObjectTemplate.h"
#include "../mapObjects/TownBuildingInstance.h"
#include "../mapping/CMap.h"
#include "../mapping/CMapInfo.h"
#include "../networkPacks/PacksForClient.h"
#include "../networkPacks/PacksForClientBattle.h"
#include "../networkPacks/PacksForLobby.h"
#include "../networkPacks/PacksForServer.h"
#include "../networkPacks/SetRewardableConfiguration.h"
#include "../networkPacks/SetStackEffect.h"
#include "../rmg/CMapGenOptions.h"
VCMI_LIB_NAMESPACE_BEGIN
/// This method defines all types that are part of Serializeable hieararchy and can be serialized as their base type
/// Each class is registered with a unique index that is used to determine correct type on deserialization
/// For example, if CGHeroInstance is serialized as pointer to CGObjectInstance serializer will write type index for CGHeroInstance, followed by CGHeroInstance::serialize() call
/// Similarly, on deserialize, game will look up type index of object that was serialized as this CGObjectInstance and will load it as CGHeroInstance instead
/// Meaning, these type indexes must NEVER change.
/// If type is removed please only remove corresponding type, without adjusting indexes of following types
/// NOTE: when removing type please consider potential save compatibility handling
/// Similarly, when adding new type make sure to add it to the very end of this list with new type index
template<typename Serializer>
void registerTypes(Serializer &s)
{
static_assert(std::is_abstract_v<IObjectInterface>, "If this type is no longer abstract consider registering it for serialization with ID 1");
static_assert(std::is_abstract_v<CGTeleport>, "If this type is no longer abstract consider registering it for serialization with ID 3");
static_assert(std::is_abstract_v<IQuestObject>, "If this type is no longer abstract consider registering it for serialization with ID 11");
static_assert(std::is_abstract_v<CArtifactSet>, "If this type is no longer abstract consider registering it for serialization with ID 29");
static_assert(std::is_abstract_v<CPackForClient>, "If this type is no longer abstract consider registering it for serialization with ID 83");
static_assert(std::is_abstract_v<Query>, "If this type is no longer abstract consider registering it for serialization with ID 153");
static_assert(std::is_abstract_v<CGarrisonOperationPack>, "If this type is no longer abstract consider registering it for serialization with ID 161");
static_assert(std::is_abstract_v<CArtifactOperationPack>, "If this type is no longer abstract consider registering it for serialization with ID 168");
s.template registerType<CGObjectInstance>(2);
s.template registerType<CGMonolith>(4);
s.template registerType<CGSubterraneanGate>(5);
s.template registerType<CGWhirlpool>(6);
s.template registerType<CGSignBottle>(7);
s.template registerType<CGKeys>(8);
s.template registerType<CGKeymasterTent>(9);
s.template registerType<CGBorderGuard>(10);
s.template registerType<CGBorderGate>(12);
s.template registerType<CGBoat>(13);
s.template registerType<CGMagi>(14);
s.template registerType<CGSirens>(15);
s.template registerType<CGShipyard>(16);
s.template registerType<CGDenOfthieves>(17);
s.template registerType<CGLighthouse>(18);
s.template registerType<CGTerrainPatch>(19);
s.template registerType<HillFort>(20);
s.template registerType<CGMarket>(21);
s.template registerType<CGBlackMarket>(22);
s.template registerType<CGUniversity>(23);
s.template registerType<CGHeroPlaceholder>(24);
s.template registerType<CArmedInstance>(25);
s.template registerType<CBonusSystemNode>(26);
s.template registerType<CCreatureSet>(27);
s.template registerType<CGHeroInstance>(28);
s.template registerType<CGDwelling>(30);
s.template registerType<CGTownInstance>(31);
s.template registerType<CGPandoraBox>(32);
s.template registerType<CGEvent>(33);
s.template registerType<CGCreature>(34);
s.template registerType<CGGarrison>(35);
s.template registerType<CGArtifact>(36);
s.template registerType<CGResource>(37);
s.template registerType<CGMine>(38);
s.template registerType<CBank>(39);
s.template registerType<CGSeerHut>(40);
s.template registerType<CGQuestGuard>(41);
s.template registerType<IUpdater>(42);
s.template registerType<GrowsWithLevelUpdater>(43);
s.template registerType<TimesHeroLevelUpdater>(44);
s.template registerType<TimesStackLevelUpdater>(45);
s.template registerType<OwnerUpdater>(46);
s.template registerType<ArmyMovementUpdater>(47);
s.template registerType<ILimiter>(48);
s.template registerType<AnyOfLimiter>(49);
s.template registerType<NoneOfLimiter>(50);
s.template registerType<OppositeSideLimiter>(51);
s.template registerType<TownBuildingInstance>(52);
s.template registerType<TownRewardableBuildingInstance>(53);
s.template registerType<CTownCompatBuilding1>(54);
s.template registerType<CTownCompatBuilding2>(55);
s.template registerType<CRewardableObject>(56);
s.template registerType<CTeamVisited>(57);
s.template registerType<CGObelisk>(58);
s.template registerType<IPropagator>(59);
s.template registerType<CPropagatorNodeType>(60);
s.template registerType<AllOfLimiter>(61);
s.template registerType<CCreatureTypeLimiter>(62);
s.template registerType<HasAnotherBonusLimiter>(63);
s.template registerType<CreatureTerrainLimiter>(64);
s.template registerType<FactionLimiter>(65);
s.template registerType<CreatureLevelLimiter>(66);
s.template registerType<CreatureAlignmentLimiter>(67);
s.template registerType<RankRangeLimiter>(68);
s.template registerType<UnitOnHexLimiter>(69);
s.template registerType<CArtifact>(70);
s.template registerType<CCreature>(71);
s.template registerType<CStackInstance>(72);
s.template registerType<CCommanderInstance>(73);
s.template registerType<PlayerState>(74);
s.template registerType<TeamState>(75);
s.template registerType<CStack>(76);
s.template registerType<BattleInfo>(77);
s.template registerType<CArtifactInstance>(78);
s.template registerType<CObstacleInstance>(79);
s.template registerType<SpellCreatedObstacle>(80);
//s.template registerType<CGArtifactsAltar>(81);
s.template registerType<CPack>(82);
s.template registerType<PackageApplied>(84);
s.template registerType<SystemMessage>(85);
s.template registerType<PlayerBlocked>(86);
s.template registerType<PlayerCheated>(87);
s.template registerType<PlayerStartsTurn>(88);
s.template registerType<DaysWithoutTown>(89);
s.template registerType<TurnTimeUpdate>(90);
s.template registerType<SetResources>(91);
s.template registerType<SetPrimSkill>(92);
s.template registerType<SetSecSkill>(93);
s.template registerType<HeroVisitCastle>(94);
s.template registerType<ChangeSpells>(95);
s.template registerType<SetMana>(96);
s.template registerType<SetMovePoints>(97);
s.template registerType<FoWChange>(98);
s.template registerType<SetAvailableHero>(99);
s.template registerType<GiveBonus>(100);
s.template registerType<ChangeObjPos>(101);
s.template registerType<PlayerEndsTurn>(102);
s.template registerType<PlayerEndsGame>(103);
s.template registerType<PlayerReinitInterface>(104);
s.template registerType<RemoveBonus>(105);
s.template registerType<UpdateArtHandlerLists>(106);
s.template registerType<ChangeFormation>(107);
s.template registerType<RemoveObject>(108);
s.template registerType<TryMoveHero>(109);
s.template registerType<NewStructures>(110);
s.template registerType<RazeStructures>(111);
s.template registerType<SetAvailableCreatures>(112);
s.template registerType<SetHeroesInTown>(113);
s.template registerType<HeroRecruited>(114);
s.template registerType<GiveHero>(115);
s.template registerType<NewTurn>(116);
s.template registerType<InfoWindow>(117);
s.template registerType<SetObjectProperty>(118);
s.template registerType<AdvmapSpellCast>(119);
s.template registerType<OpenWindow>(120);
s.template registerType<NewObject>(121);
s.template registerType<NewArtifact>(122);
s.template registerType<AddQuest>(123);
s.template registerType<SetAvailableArtifacts>(124);
s.template registerType<CenterView>(125);
s.template registerType<HeroVisit>(126);
s.template registerType<SetCommanderProperty>(127);
s.template registerType<ChangeObjectVisitors>(128);
s.template registerType<ChangeArtifactsCostume>(129);
s.template registerType<ShowWorldViewEx>(130);
s.template registerType<EntitiesChanged>(131);
s.template registerType<BattleStart>(132);
s.template registerType<BattleNextRound>(133);
s.template registerType<BattleSetActiveStack>(134);
s.template registerType<BattleResult>(135);
s.template registerType<BattleResultAccepted>(136);
s.template registerType<BattleCancelled>(137);
s.template registerType<BattleLogMessage>(138);
s.template registerType<BattleStackMoved>(139);
s.template registerType<BattleAttack>(140);
s.template registerType<StartAction>(141);
s.template registerType<EndAction>(142);
s.template registerType<BattleSpellCast>(143);
s.template registerType<SetStackEffect>(144);
s.template registerType<BattleTriggerEffect>(145);
s.template registerType<BattleUpdateGateState>(146);
s.template registerType<BattleSetStackProperty>(147);
s.template registerType<StacksInjured>(148);
s.template registerType<BattleResultsApplied>(149);
s.template registerType<BattleUnitsChanged>(150);
s.template registerType<BattleObstaclesChanged>(151);
s.template registerType<CatapultAttack>(152);
s.template registerType<HeroLevelUp>(154);
s.template registerType<CommanderLevelUp>(155);
s.template registerType<BlockingDialog>(156);
s.template registerType<GarrisonDialog>(157);
s.template registerType<ExchangeDialog>(158);
s.template registerType<TeleportDialog>(159);
s.template registerType<MapObjectSelectDialog>(160);
s.template registerType<ChangeStackCount>(162);
s.template registerType<SetStackType>(163);
s.template registerType<EraseStack>(164);
s.template registerType<SwapStacks>(165);
s.template registerType<InsertNewStack>(166);
s.template registerType<RebalanceStacks>(167);
s.template registerType<PutArtifact>(169);
s.template registerType<EraseArtifact>(170);
s.template registerType<AssembledArtifact>(171);
s.template registerType<DisassembledArtifact>(172);
s.template registerType<BulkMoveArtifacts>(173);
s.template registerType<PlayerMessageClient>(174);
s.template registerType<BulkRebalanceStacks>(175);
s.template registerType<BulkSmartRebalanceStacks>(176);
s.template registerType<SetRewardableConfiguration>(177);
s.template registerType<SetBankConfiguration>(178);
s.template registerType<CPackForServer>(179);
s.template registerType<EndTurn>(180);
s.template registerType<DismissHero>(181);
s.template registerType<MoveHero>(182);
s.template registerType<ArrangeStacks>(183);
s.template registerType<DisbandCreature>(184);
s.template registerType<BuildStructure>(185);
s.template registerType<TriggerTownSpecialBuildingAction>(186);
s.template registerType<RecruitCreatures>(187);
s.template registerType<UpgradeCreature>(188);
s.template registerType<GarrisonHeroSwap>(189);
s.template registerType<ExchangeArtifacts>(190);
s.template registerType<AssembleArtifacts>(191);
s.template registerType<BuyArtifact>(192);
s.template registerType<TradeOnMarketplace>(193);
s.template registerType<SetFormation>(194);
s.template registerType<HireHero>(195);
s.template registerType<BuildBoat>(196);
s.template registerType<QueryReply>(197);
s.template registerType<MakeAction>(198);
s.template registerType<DigWithHero>(199);
s.template registerType<CastAdvSpell>(200);
s.template registerType<CastleTeleportHero>(201);
s.template registerType<SaveGame>(202);
s.template registerType<PlayerMessage>(203);
s.template registerType<BulkSplitStack>(204);
s.template registerType<BulkMergeStacks>(205);
s.template registerType<BulkSmartSplitStack>(206);
s.template registerType<BulkMoveArmy>(207);
s.template registerType<BulkExchangeArtifacts>(208);
s.template registerType<ManageBackpackArtifacts>(209);
s.template registerType<ManageEquippedArtifacts>(210);
s.template registerType<EraseArtifactByClient>(211);
s.template registerType<GamePause>(212);
s.template registerType<CPackForLobby>(213);
s.template registerType<CLobbyPackToPropagate>(214);
s.template registerType<CLobbyPackToServer>(215);
s.template registerType<LobbyClientConnected>(216);
s.template registerType<LobbyClientDisconnected>(217);
s.template registerType<LobbyChatMessage>(218);
s.template registerType<LobbyPvPAction>(219);
s.template registerType<LobbyGuiAction>(220);
s.template registerType<LobbyLoadProgress>(221);
s.template registerType<LobbyRestartGame>(222);
s.template registerType<LobbyPrepareStartGame>(223);
s.template registerType<LobbyStartGame>(224);
s.template registerType<LobbyChangeHost>(225);
s.template registerType<LobbyUpdateState>(226);
s.template registerType<LobbyShowMessage>(227);
s.template registerType<LobbyChangePlayerOption>(228);
s.template registerType<LobbySetMap>(229);
s.template registerType<LobbySetCampaign>(230);
s.template registerType<LobbySetCampaignMap>(231);
s.template registerType<LobbySetCampaignBonus>(232);
s.template registerType<LobbySetPlayer>(233);
s.template registerType<LobbySetPlayerName>(234);
s.template registerType<LobbySetPlayerHandicap>(235);
s.template registerType<LobbySetTurnTime>(236);
s.template registerType<LobbySetSimturns>(237);
s.template registerType<LobbySetDifficulty>(238);
s.template registerType<LobbyForceSetPlayer>(239);
s.template registerType<LobbySetExtraOptions>(240);
}
VCMI_LIB_NAMESPACE_END

View File

@@ -14,7 +14,7 @@
#include "BinarySerializer.h"
#include "CTypeList.h"
#include "../registerTypes/RegisterTypes.h"
#include "RegisterTypes.h"
VCMI_LIB_NAMESPACE_BEGIN
@@ -42,21 +42,11 @@ public:
}
};
template<typename RegisteredType>
void CSerializationApplier::addApplier(ui16 ID)
template<typename Type>
void CSerializationApplier::registerType(uint16_t ID)
{
if(!apps.count(ID))
{
logGlobal->info("Registering type %d (%s)", ID, typeid(RegisteredType).name());
apps[ID].reset(new SerializerReflection<RegisteredType>);
}
}
template<typename Base, typename Derived>
void CSerializationApplier::registerType(const Base * b, const Derived * d)
{
addApplier<Base>(CTypeList::getInstance().getTypeID<Base>(nullptr));
addApplier<Derived>(CTypeList::getInstance().getTypeID<Derived>(nullptr));
assert(!apps.count(ID));
apps[ID].reset(new SerializerReflection<Type>);
}
CSerializationApplier::CSerializationApplier()

View File

@@ -30,16 +30,7 @@ struct ClassObjectCreator
};
template<typename T>
struct ClassObjectCreator<T, typename std::enable_if_t<std::is_abstract_v<T>>>
{
static T *invoke(IGameCallback *cb)
{
throw std::runtime_error("Something went really wrong during deserialization. Attempted creating an object of an abstract class " + std::string(typeid(T).name()));
}
};
template<typename T>
struct ClassObjectCreator<T, typename std::enable_if_t<std::is_base_of_v<GameCallbackHolder, T> && !std::is_abstract_v<T>>>
struct ClassObjectCreator<T, typename std::enable_if_t<std::is_base_of_v<GameCallbackHolder, T>>>
{
static T *invoke(IGameCallback *cb)
{
@@ -61,20 +52,17 @@ class DLL_LINKAGE CSerializationApplier
{
std::map<int32_t, std::unique_ptr<ISerializerReflection>> apps;
template<typename RegisteredType>
void addApplier(ui16 ID);
CSerializationApplier();
public:
ISerializerReflection * getApplier(ui16 ID)
ISerializerReflection * getApplier(uint16_t ID)
{
if(!apps.count(ID))
throw std::runtime_error("No applier found.");
return apps[ID].get();
}
template<typename Base, typename Derived>
void registerType(const Base * b = nullptr, const Derived * d = nullptr);
template<typename Type>
void registerType(uint16_t index);
static CSerializationApplier & getInstance();
};