1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-01-02 00:10:22 +02:00

Remove serialization of VLC, remove unused code

This commit is contained in:
Ivan Savenko 2023-11-04 15:21:23 +02:00
parent 8aea2be0db
commit ad3c870fb6
7 changed files with 0 additions and 218 deletions

View File

@ -180,7 +180,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
${MAIN_LIB_DIR}/serializer/BinaryDeserializer.cpp
${MAIN_LIB_DIR}/serializer/BinarySerializer.cpp
${MAIN_LIB_DIR}/serializer/CLoadIntegrityValidator.cpp
${MAIN_LIB_DIR}/serializer/CMemorySerializer.cpp
${MAIN_LIB_DIR}/serializer/Connection.cpp
${MAIN_LIB_DIR}/serializer/CSerializer.cpp
@ -546,7 +545,6 @@ macro(add_main_lib TARGET_NAME LIBRARY_TYPE)
${MAIN_LIB_DIR}/serializer/BinaryDeserializer.h
${MAIN_LIB_DIR}/serializer/BinarySerializer.h
${MAIN_LIB_DIR}/serializer/CLoadIntegrityValidator.h
${MAIN_LIB_DIR}/serializer/CMemorySerializer.h
${MAIN_LIB_DIR}/serializer/Connection.h
${MAIN_LIB_DIR}/serializer/CSerializer.h

View File

@ -24,7 +24,6 @@
#include "serializer/CSerializer.h" // for SAVEGAME_MAGIC
#include "serializer/BinaryDeserializer.h"
#include "serializer/BinarySerializer.h"
#include "serializer/CLoadIntegrityValidator.h"
#include "rmg/CMapGenOptions.h"
#include "mapObjectConstructors/AObjectTypeHandler.h"
#include "mapObjectConstructors/CObjectClassesHandler.h"
@ -191,9 +190,6 @@ void CPrivilegedInfoCallback::loadCommonState(Loader & in)
logGlobal->info("\tReading options");
in.serializer & si;
logGlobal->info("\tReading handlers");
in.serializer & *VLC;
logGlobal->info("\tReading gamestate");
in.serializer & gs;
}
@ -207,14 +203,11 @@ void CPrivilegedInfoCallback::saveCommonState(Saver & out) const
out.serializer & static_cast<CMapHeader&>(*gs->map);
logGlobal->info("\tSaving options");
out.serializer & gs->scenarioOps;
logGlobal->info("\tSaving handlers");
out.serializer & *VLC;
logGlobal->info("\tSaving gamestate");
out.serializer & gs;
}
// hardly memory usage for `-gdwarf-4` flag
template DLL_LINKAGE void CPrivilegedInfoCallback::loadCommonState<CLoadIntegrityValidator>(CLoadIntegrityValidator &);
template DLL_LINKAGE void CPrivilegedInfoCallback::loadCommonState<CLoadFile>(CLoadFile &);
template DLL_LINKAGE void CPrivilegedInfoCallback::saveCommonState<CSaveFile>(CSaveFile &) const;

View File

@ -120,51 +120,6 @@ public:
#if SCRIPTING_ENABLED
void scriptsLoaded();
#endif
template <typename Handler> void serialize(Handler &h, const int version)
{
h & identifiersHandler; // must be first - identifiers registry is used for handlers loading
#if SCRIPTING_ENABLED
h & scriptHandler;//must be first (or second after identifiers), it can modify factories other handlers depends on
if(!h.saving)
{
scriptsLoaded();
}
#endif
h & settingsHandler;
h & heroh;
h & arth;
h & creh;
h & townh;
h & objh;
h & objtypeh;
h & spellh;
h & skillh;
h & battlefieldsHandler;
h & obstacleHandler;
h & roadTypeHandler;
h & riverTypeHandler;
h & terrainTypeHandler;
if(!h.saving)
{
//modh will be changed and modh->content will be empty after deserialization
auto content = getContent();
h & modh;
setContent(content);
}
else
h & modh;
h & IS_AI_ENABLED;
h & bth;
if(!h.saving)
{
callWhenDeserializing();
}
}
};
extern DLL_LINKAGE LibClasses * VLC;

View File

@ -52,12 +52,6 @@ class DLL_LINKAGE CIdentifierStorage
{
return id == other.id && scope == other.scope;
}
template <typename Handler> void serialize(Handler &h, const int version)
{
h & id;
h & scope;
}
};
std::multimap<std::string, ObjectData> registeredObjects;
@ -102,12 +96,6 @@ public:
/// called at the very end of loading to check for any missing ID's
void finalize();
template <typename Handler> void serialize(Handler &h, const int version)
{
h & registeredObjects;
h & state;
}
};
VCMI_LIB_NAMESPACE_END

View File

@ -95,57 +95,6 @@ void registerTypesMapObjects1(Serializer &s)
template<typename Serializer>
void registerTypesMapObjectTypes(Serializer &s)
{
s.template registerType<AObjectTypeHandler, CRewardableConstructor>();
s.template registerType<AObjectTypeHandler, CHeroInstanceConstructor>();
s.template registerType<AObjectTypeHandler, CTownInstanceConstructor>();
s.template registerType<AObjectTypeHandler, DwellingInstanceConstructor>();
s.template registerType<AObjectTypeHandler, CBankInstanceConstructor>();
s.template registerType<AObjectTypeHandler, BoatInstanceConstructor>();
s.template registerType<AObjectTypeHandler, MarketInstanceConstructor>();
s.template registerType<AObjectTypeHandler, CObstacleConstructor>();
s.template registerType<AObjectTypeHandler, ShipyardInstanceConstructor>();
s.template registerType<AObjectTypeHandler, HillFortInstanceConstructor>();
s.template registerType<AObjectTypeHandler, CreatureInstanceConstructor>();
s.template registerType<AObjectTypeHandler, ResourceInstanceConstructor>();
#define REGISTER_GENERIC_HANDLER(TYPENAME) s.template registerType<AObjectTypeHandler, CDefaultObjectTypeHandler<TYPENAME> >()
REGISTER_GENERIC_HANDLER(CGObjectInstance);
REGISTER_GENERIC_HANDLER(CGArtifact);
REGISTER_GENERIC_HANDLER(CGBlackMarket);
REGISTER_GENERIC_HANDLER(CGBoat);
REGISTER_GENERIC_HANDLER(CGBorderGate);
REGISTER_GENERIC_HANDLER(CGBorderGuard);
REGISTER_GENERIC_HANDLER(CGCreature);
REGISTER_GENERIC_HANDLER(CGDenOfthieves);
REGISTER_GENERIC_HANDLER(CGDwelling);
REGISTER_GENERIC_HANDLER(CGEvent);
REGISTER_GENERIC_HANDLER(CGGarrison);
REGISTER_GENERIC_HANDLER(CGHeroPlaceholder);
REGISTER_GENERIC_HANDLER(CGHeroInstance);
REGISTER_GENERIC_HANDLER(CGKeymasterTent);
REGISTER_GENERIC_HANDLER(CGLighthouse);
REGISTER_GENERIC_HANDLER(CGTerrainPatch);
REGISTER_GENERIC_HANDLER(CGMagi);
REGISTER_GENERIC_HANDLER(CGMarket);
REGISTER_GENERIC_HANDLER(CGMine);
REGISTER_GENERIC_HANDLER(CGObelisk);
REGISTER_GENERIC_HANDLER(CGPandoraBox);
REGISTER_GENERIC_HANDLER(CGQuestGuard);
REGISTER_GENERIC_HANDLER(CGResource);
REGISTER_GENERIC_HANDLER(CGSeerHut);
REGISTER_GENERIC_HANDLER(CGShipyard);
REGISTER_GENERIC_HANDLER(CGSignBottle);
REGISTER_GENERIC_HANDLER(CGSirens);
REGISTER_GENERIC_HANDLER(CGMonolith);
REGISTER_GENERIC_HANDLER(CGSubterraneanGate);
REGISTER_GENERIC_HANDLER(CGWhirlpool);
REGISTER_GENERIC_HANDLER(CGTownInstance);
REGISTER_GENERIC_HANDLER(CGUniversity);
REGISTER_GENERIC_HANDLER(HillFort);
#undef REGISTER_GENERIC_HANDLER
s.template registerType<IUpdater, GrowsWithLevelUpdater>();
s.template registerType<IUpdater, TimesHeroLevelUpdater>();
s.template registerType<IUpdater, TimesStackLevelUpdater>();

View File

@ -1,68 +0,0 @@
/*
* CLoadIntegrityValidator.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
*
*/
#include "StdInc.h"
#include "CLoadIntegrityValidator.h"
#include "../registerTypes/RegisterTypes.h"
VCMI_LIB_NAMESPACE_BEGIN
CLoadIntegrityValidator::CLoadIntegrityValidator(const boost::filesystem::path &primaryFileName, const boost::filesystem::path &controlFileName, int minimalVersion)
: serializer(this), foundDesync(false)
{
registerTypes(serializer);
primaryFile = std::make_unique<CLoadFile>(primaryFileName, minimalVersion);
controlFile = std::make_unique<CLoadFile>(controlFileName, minimalVersion);
assert(primaryFile->serializer.fileVersion == controlFile->serializer.fileVersion);
serializer.fileVersion = primaryFile->serializer.fileVersion;
}
int CLoadIntegrityValidator::read( void * data, unsigned size )
{
assert(primaryFile);
assert(controlFile);
if(!size)
return size;
std::vector<ui8> controlData(size);
auto ret = primaryFile->read(data, size);
if(!foundDesync)
{
controlFile->read(controlData.data(), size);
if(std::memcmp(data, controlData.data(), size) != 0)
{
logGlobal->error("Desync found! Position: %d", primaryFile->sfile->tellg());
foundDesync = true;
//throw std::runtime_error("Savegame dsynchronized!");
}
}
return ret;
}
std::unique_ptr<CLoadFile> CLoadIntegrityValidator::decay()
{
primaryFile->serializer.loadedPointers = this->serializer.loadedPointers;
primaryFile->serializer.loadedPointersTypes = this->serializer.loadedPointersTypes;
return std::move(primaryFile);
}
void CLoadIntegrityValidator::checkMagicBytes(const std::string & text) const
{
assert(primaryFile);
assert(controlFile);
primaryFile->checkMagicBytes(text);
controlFile->checkMagicBytes(text);
}
VCMI_LIB_NAMESPACE_END

View File

@ -1,33 +0,0 @@
/*
* CLoadIntegrityValidator.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 "BinaryDeserializer.h"
VCMI_LIB_NAMESPACE_BEGIN
/// Simple byte-to-byte saves comparator
class DLL_LINKAGE CLoadIntegrityValidator
: public IBinaryReader
{
public:
BinaryDeserializer serializer;
std::unique_ptr<CLoadFile> primaryFile, controlFile;
bool foundDesync;
CLoadIntegrityValidator(const boost::filesystem::path &primaryFileName, const boost::filesystem::path &controlFileName, int minimalVersion = SERIALIZATION_VERSION); //throws!
int read( void * data, unsigned size) override; //throws!
void checkMagicBytes(const std::string & text) const;
std::unique_ptr<CLoadFile> decay(); //returns primary file. CLoadIntegrityValidator stops being usable anymore
};
VCMI_LIB_NAMESPACE_END