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

Split registerTypes into multiple files, now in lib/registerTypes

directory in order to reduce huge memory usage by gcc
This commit is contained in:
Ivan Savenko 2014-02-24 19:57:33 +00:00
parent 6d73052ca1
commit 8d36bcabce
14 changed files with 242 additions and 70 deletions

View File

@ -35,7 +35,7 @@
#include "CBitmapHandler.h"
#include "Client.h"
#include "../lib/NetPacks.h"
#include "../lib/RegisterTypes.h"
#include "../lib/registerTypes//RegisterTypes.h"
#include "../lib/CThreadHelper.h"
#include "../lib/CConfigHandler.h"
#include "../lib/GameConstants.h"
@ -734,7 +734,7 @@ CSelectionScreen::CSelectionScreen(CMenuScreen::EState Type, CMenuScreen::EMulti
}
applier = new CApplier<CBaseForPGApply>;
registerTypes4(*applier);
registerTypesPregamePacks(*applier);
serverHandlingThread = new boost::thread(&CSelectionScreen::handleConnection, this);
}
delete sh;

View File

@ -32,7 +32,7 @@
#include "battle/CBattleInterface.h"
#include "../lib/CThreadHelper.h"
#include "../lib/CScriptingModule.h"
#include "../lib/RegisterTypes.h"
#include "../lib/registerTypes/RegisterTypes.h"
#include "gui/CGuiHandler.h"
#include "CMT.h"
@ -103,7 +103,8 @@ void CClient::init()
connectionHandler = nullptr;
pathInfo = nullptr;
applier = new CApplier<CBaseForCLApply>;
registerTypes2(*applier);
registerTypesClientPacks1(*applier);
registerTypesClientPacks2(*applier);
IObjectInterface::cb = this;
serv = nullptr;
gs = nullptr;

View File

@ -18,7 +18,7 @@
#include "mapping/CMapService.h"
#include "StartInfo.h"
#include "NetPacks.h"
#include "RegisterTypes.h"
#include "registerTypes/RegisterTypes.h"
#include "mapping/CMapInfo.h"
#include "BattleState.h"
#include "JsonNode.h"
@ -109,7 +109,7 @@ static CApplier<CBaseForGSApply> *applierGs = nullptr;
//
// CObjectCallersHandler()
// {
// registerTypes1(*this);
// registerTypesMapObjects(*this);
// }
//
// ~CObjectCallersHandler()
@ -729,7 +729,8 @@ CGameState::CGameState()
gs = this;
mx = new boost::shared_mutex();
applierGs = new CApplier<CBaseForGSApply>;
registerTypes2(*applierGs);
registerTypesClientPacks1(*applierGs);
registerTypesClientPacks2(*applierGs);
//objCaller = new CObjectCallersHandler;
globalEffects.setDescription("Global effects");
}

View File

@ -6,13 +6,19 @@ include_directories(${Boost_INCLUDE_DIRS} ${SDL_INCLUDE_DIR} ${ZLIB_INCLUDE_DIR}
set(lib_SRCS
StdInc.cpp
RegisterTypes.cpp
IGameCallback.cpp
CGameState.cpp
CObjectHandler.cpp
Connection.cpp
NetPacksLib.cpp
registerTypes/RegisterTypes.cpp
registerTypes/TypesClientPacks1.cpp
registerTypes/TypesClientPacks2.cpp
registerTypes/TypesMapObjects.cpp
registerTypes/TypesPregamePacks.cpp
registerTypes/TypesServerPacks.cpp
filesystem/AdapterLoaders.cpp
filesystem/CCompressedStream.cpp
filesystem/CFilesystemLoader.cpp
@ -96,7 +102,6 @@ set(lib_HEADERS
Interprocess.h
NetPacks.h
NetPacksBase.h
RegisterTypes.h
StartInfo.h
UnlockGuard.h
VCMIDirs.h

View File

@ -1,7 +1,7 @@
#include "StdInc.h"
#include "Connection.h"
#include "RegisterTypes.h"
#include "registerTypes/RegisterTypes.h"
#include <boost/asio.hpp>

View File

@ -1,39 +0,0 @@
#include "StdInc.h"
#define DO_NOT_DISABLE_REGISTER_TYPES_INSTANTIATION
#include "RegisterTypes.h"
#include "mapping/CMapInfo.h"
#include "StartInfo.h"
#include "BattleState.h"
#include "CGameState.h"
#include "mapping/CMap.h"
#include "CModHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "CArtHandler.h"
#include "CHeroHandler.h"
#include "CSpellHandler.h"
#include "CTownHandler.h"
#include "mapping/CCampaignHandler.h"
#include "NetPacks.h"
#include "CDefObjInfoHandler.h"
/*
* RegisterTypes.cpp, 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
*
*/
template void registerTypes<CISer<CConnection>>(CISer<CConnection>& s);
template void registerTypes<COSer<CConnection>>(COSer<CConnection>& s);
template void registerTypes<CISer<CMemorySerializer>>(CISer<CMemorySerializer>& s);
template void registerTypes<COSer<CMemorySerializer>>(COSer<CMemorySerializer>& s);
template void registerTypes<CSaveFile>(CSaveFile & s);
template void registerTypes<CLoadFile>(CLoadFile & s);
template void registerTypes<CTypeList>(CTypeList & s);
template void registerTypes<CLoadIntegrityValidator>(CLoadIntegrityValidator & s);

View File

@ -0,0 +1,53 @@
#include "StdInc.h"
#define INSTANTIATE_REGISTER_TYPES_HERE
#include "RegisterTypes.h"
#include "mapping/CMapInfo.h"
#include "StartInfo.h"
#include "BattleState.h"
#include "CGameState.h"
#include "mapping/CMap.h"
#include "CModHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "CArtHandler.h"
#include "CHeroHandler.h"
#include "CSpellHandler.h"
#include "CTownHandler.h"
#include "mapping/CCampaignHandler.h"
#include "NetPacks.h"
#include "CDefObjInfoHandler.h"
// For reference: peak memory usage by gcc during compilation of register type templates
// registerTypesMapObjects: 1.9 Gb
// registerTypes2: 2.2 Gb
// registerTypesClientPacks1 1.6 Gb
// registerTypesClientPacks2 1.6 Gb
// registerTypesServerPacks: 1.3 Gb
// registerTypes4: 1.3 Gb
#define DEFINE_EXTERNAL_METHOD(METHODNAME) \
extern template DLL_LINKAGE void METHODNAME<CISer<CConnection>>(CISer<CConnection>& s); \
extern template DLL_LINKAGE void METHODNAME<COSer<CConnection>>(COSer<CConnection>& s); \
extern template DLL_LINKAGE void METHODNAME<CISer<CMemorySerializer>>(CISer<CMemorySerializer>& s); \
extern template DLL_LINKAGE void METHODNAME<COSer<CMemorySerializer>>(COSer<CMemorySerializer>& s); \
extern template DLL_LINKAGE void METHODNAME<CSaveFile>(CSaveFile & s); \
extern template DLL_LINKAGE void METHODNAME<CLoadFile>(CLoadFile & s); \
extern template DLL_LINKAGE void METHODNAME<CTypeList>(CTypeList & s); \
extern template DLL_LINKAGE void METHODNAME<CLoadIntegrityValidator>(CLoadIntegrityValidator & s);
DEFINE_EXTERNAL_METHOD(registerTypesMapObjects)
DEFINE_EXTERNAL_METHOD(registerTypesClientPacks1)
DEFINE_EXTERNAL_METHOD(registerTypesClientPacks2)
DEFINE_EXTERNAL_METHOD(registerTypesServerPacks)
DEFINE_EXTERNAL_METHOD(registerTypesPregamePacks)
template void registerTypes<CISer<CConnection>>(CISer<CConnection>& s);
template void registerTypes<COSer<CConnection>>(COSer<CConnection>& s);
template void registerTypes<CISer<CMemorySerializer>>(CISer<CMemorySerializer>& s);
template void registerTypes<COSer<CMemorySerializer>>(COSer<CMemorySerializer>& s);
template void registerTypes<CSaveFile>(CSaveFile & s);
template void registerTypes<CLoadFile>(CLoadFile & s);
template void registerTypes<CTypeList>(CTypeList & s);
template void registerTypes<CLoadIntegrityValidator>(CLoadIntegrityValidator & s);

View File

@ -21,7 +21,7 @@
*/
template<typename Serializer>
void registerTypes1(Serializer &s)
void registerTypesMapObjects(Serializer &s)
{
//////////////////////////////////////////////////////////////////////////
// Adventure map objects (and related)
@ -133,7 +133,7 @@ void registerTypes1(Serializer &s)
}
template<typename Serializer>
void registerTypes2(Serializer &s)
void registerTypesClientPacks1(Serializer &s)
{
s.template registerType<CPack, CPackForClient>();
@ -174,6 +174,21 @@ void registerTypes2(Serializer &s)
s.template registerType<CPackForClient, InfoWindow>();
s.template registerType<CPackForClient, SetObjectProperty>();
s.template registerType<CPackForClient, SetHoverName>();
s.template registerType<CPackForClient, ShowInInfobox>();
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>();
}
template<typename Serializer>
void registerTypesClientPacks2(Serializer &s)
{
s.template registerType<CPackForClient, BattleStart>();
s.template registerType<CPackForClient, BattleNextRound>();
s.template registerType<CPackForClient, BattleSetActiveStack>();
@ -195,16 +210,6 @@ void registerTypes2(Serializer &s)
s.template registerType<CPackForClient, CatapultAttack>();
s.template registerType<CPackForClient, BattleStacksRemoved>();
s.template registerType<CPackForClient, BattleStackAdded>();
s.template registerType<CPackForClient, ShowInInfobox>();
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, Query>();
s.template registerType<Query, HeroLevelUp>();
@ -234,7 +239,7 @@ void registerTypes2(Serializer &s)
}
template<typename Serializer>
void registerTypes3(Serializer &s)
void registerTypesServerPacks(Serializer &s)
{
s.template registerType<CPack, CPackForServer>();
s.template registerType<CPackForServer, CloseServer>();
@ -268,7 +273,7 @@ void registerTypes3(Serializer &s)
}
template<typename Serializer>
void registerTypes4(Serializer &s)
void registerTypesPregamePacks(Serializer &s)
{
s.template registerType<CPack, CPackForSelectionScreen>();
s.template registerType<CPackForSelectionScreen, CPregamePackToPropagate>();
@ -290,18 +295,21 @@ void registerTypes4(Serializer &s)
template<typename Serializer>
void registerTypes(Serializer &s)
{
registerTypes1(s);
registerTypes2(s);
registerTypes3(s);
registerTypes4(s);
registerTypesMapObjects(s);
registerTypesClientPacks1(s);
registerTypesClientPacks2(s);
registerTypesServerPacks(s);
registerTypesPregamePacks(s);
}
#ifndef DO_NOT_DISABLE_REGISTER_TYPES_INSTANTIATION
#ifndef INSTANTIATE_REGISTER_TYPES_HERE
extern template DLL_LINKAGE void registerTypes<CISer<CConnection>>(CISer<CConnection>& s);
extern template DLL_LINKAGE void registerTypes<COSer<CConnection>>(COSer<CConnection>& s);
extern template DLL_LINKAGE void registerTypes<CSaveFile>(CSaveFile & s);
extern template DLL_LINKAGE void registerTypes<CLoadFile>(CLoadFile & s);
extern template DLL_LINKAGE void registerTypes<CTypeList>(CTypeList & s);
extern template DLL_LINKAGE void registerTypes<CLoadIntegrityValidator>(CLoadIntegrityValidator & s);
extern template DLL_LINKAGE void registerTypes<CISer<CMemorySerializer>>(CISer<CMemorySerializer> & s);
extern template DLL_LINKAGE void registerTypes<COSer<CMemorySerializer>>(COSer<CMemorySerializer> & s);
#endif

View File

@ -0,0 +1,29 @@
#include "StdInc.h"
#include "RegisterTypes.h"
#include "mapping/CMapInfo.h"
#include "StartInfo.h"
#include "BattleState.h"
#include "CGameState.h"
#include "mapping/CMap.h"
#include "CModHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "CArtHandler.h"
#include "CHeroHandler.h"
#include "CSpellHandler.h"
#include "CTownHandler.h"
#include "mapping/CCampaignHandler.h"
#include "NetPacks.h"
#include "CDefObjInfoHandler.h"
template void registerTypesClientPacks1<CISer<CConnection>>(CISer<CConnection>& s);
template void registerTypesClientPacks1<COSer<CConnection>>(COSer<CConnection>& s);
template void registerTypesClientPacks1<CISer<CMemorySerializer>>(CISer<CMemorySerializer>& s);
template void registerTypesClientPacks1<COSer<CMemorySerializer>>(COSer<CMemorySerializer>& s);
template void registerTypesClientPacks1<CSaveFile>(CSaveFile & s);
template void registerTypesClientPacks1<CLoadFile>(CLoadFile & s);
template void registerTypesClientPacks1<CTypeList>(CTypeList & s);
template void registerTypesClientPacks1<CLoadIntegrityValidator>(CLoadIntegrityValidator & s);

View File

@ -0,0 +1,29 @@
#include "StdInc.h"
#include "RegisterTypes.h"
#include "mapping/CMapInfo.h"
#include "StartInfo.h"
#include "BattleState.h"
#include "CGameState.h"
#include "mapping/CMap.h"
#include "CModHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "CArtHandler.h"
#include "CHeroHandler.h"
#include "CSpellHandler.h"
#include "CTownHandler.h"
#include "mapping/CCampaignHandler.h"
#include "NetPacks.h"
#include "CDefObjInfoHandler.h"
template void registerTypesClientPacks2<CISer<CConnection>>(CISer<CConnection>& s);
template void registerTypesClientPacks2<COSer<CConnection>>(COSer<CConnection>& s);
template void registerTypesClientPacks2<CISer<CMemorySerializer>>(CISer<CMemorySerializer>& s);
template void registerTypesClientPacks2<COSer<CMemorySerializer>>(COSer<CMemorySerializer>& s);
template void registerTypesClientPacks2<CSaveFile>(CSaveFile & s);
template void registerTypesClientPacks2<CLoadFile>(CLoadFile & s);
template void registerTypesClientPacks2<CTypeList>(CTypeList & s);
template void registerTypesClientPacks2<CLoadIntegrityValidator>(CLoadIntegrityValidator & s);

View File

@ -0,0 +1,29 @@
#include "StdInc.h"
#include "RegisterTypes.h"
#include "mapping/CMapInfo.h"
#include "StartInfo.h"
#include "BattleState.h"
#include "CGameState.h"
#include "mapping/CMap.h"
#include "CModHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "CArtHandler.h"
#include "CHeroHandler.h"
#include "CSpellHandler.h"
#include "CTownHandler.h"
#include "mapping/CCampaignHandler.h"
#include "NetPacks.h"
#include "CDefObjInfoHandler.h"
template void registerTypesMapObjects<CISer<CConnection>>(CISer<CConnection>& s);
template void registerTypesMapObjects<COSer<CConnection>>(COSer<CConnection>& s);
template void registerTypesMapObjects<CISer<CMemorySerializer>>(CISer<CMemorySerializer>& s);
template void registerTypesMapObjects<COSer<CMemorySerializer>>(COSer<CMemorySerializer>& s);
template void registerTypesMapObjects<CSaveFile>(CSaveFile & s);
template void registerTypesMapObjects<CLoadFile>(CLoadFile & s);
template void registerTypesMapObjects<CTypeList>(CTypeList & s);
template void registerTypesMapObjects<CLoadIntegrityValidator>(CLoadIntegrityValidator & s);

View File

@ -0,0 +1,28 @@
#include "StdInc.h"
#include "RegisterTypes.h"
#include "mapping/CMapInfo.h"
#include "StartInfo.h"
#include "BattleState.h"
#include "CGameState.h"
#include "mapping/CMap.h"
#include "CModHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "CArtHandler.h"
#include "CHeroHandler.h"
#include "CSpellHandler.h"
#include "CTownHandler.h"
#include "mapping/CCampaignHandler.h"
#include "NetPacks.h"
#include "CDefObjInfoHandler.h"
template void registerTypesPregamePacks<CISer<CConnection>>(CISer<CConnection>& s);
template void registerTypesPregamePacks<COSer<CConnection>>(COSer<CConnection>& s);
template void registerTypesPregamePacks<CISer<CMemorySerializer>>(CISer<CMemorySerializer>& s);
template void registerTypesPregamePacks<COSer<CMemorySerializer>>(COSer<CMemorySerializer>& s);
template void registerTypesPregamePacks<CSaveFile>(CSaveFile & s);
template void registerTypesPregamePacks<CLoadFile>(CLoadFile & s);
template void registerTypesPregamePacks<CTypeList>(CTypeList & s);
template void registerTypesPregamePacks<CLoadIntegrityValidator>(CLoadIntegrityValidator & s);

View File

@ -0,0 +1,28 @@
#include "StdInc.h"
#include "RegisterTypes.h"
#include "mapping/CMapInfo.h"
#include "StartInfo.h"
#include "BattleState.h"
#include "CGameState.h"
#include "mapping/CMap.h"
#include "CModHandler.h"
#include "CObjectHandler.h"
#include "CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "CArtHandler.h"
#include "CHeroHandler.h"
#include "CSpellHandler.h"
#include "CTownHandler.h"
#include "mapping/CCampaignHandler.h"
#include "NetPacks.h"
#include "CDefObjInfoHandler.h"
template void registerTypesServerPacks<CISer<CConnection>>(CISer<CConnection>& s);
template void registerTypesServerPacks<COSer<CConnection>>(COSer<CConnection>& s);
template void registerTypesServerPacks<CISer<CMemorySerializer>>(CISer<CMemorySerializer>& s);
template void registerTypesServerPacks<COSer<CMemorySerializer>>(COSer<CMemorySerializer>& s);
template void registerTypesServerPacks<CSaveFile>(CSaveFile & s);
template void registerTypesServerPacks<CLoadFile>(CLoadFile & s);
template void registerTypesServerPacks<CTypeList>(CTypeList & s);
template void registerTypesServerPacks<CLoadIntegrityValidator>(CLoadIntegrityValidator & s);

View File

@ -29,7 +29,7 @@
#include "../lib/CCreatureSet.h"
#include "../lib/CThreadHelper.h"
#include "../lib/GameConstants.h"
#include "../lib/RegisterTypes.h"
#include "../lib/registerTypes/RegisterTypes.h"
/*
* CGameHandler.cpp, part of VCMI engine
@ -1065,7 +1065,7 @@ CGameHandler::CGameHandler(void)
//gs = nullptr;
IObjectInterface::cb = this;
applier = new CApplier<CBaseForGHApply>;
registerTypes3(*applier);
registerTypesServerPacks(*applier);
visitObjectAfterVictory = false;
queries.gh = this;
}