From ad3c870fb6672e8729b80de2c7b2e80200b9b3c3 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sat, 4 Nov 2023 15:21:23 +0200 Subject: [PATCH] Remove serialization of VLC, remove unused code --- cmake_modules/VCMI_lib.cmake | 2 - lib/IGameCallback.cpp | 7 --- lib/VCMI_Lib.h | 45 -------------- lib/modding/IdentifierStorage.h | 12 ---- lib/registerTypes/RegisterTypes.h | 51 ---------------- lib/serializer/CLoadIntegrityValidator.cpp | 68 ---------------------- lib/serializer/CLoadIntegrityValidator.h | 33 ----------- 7 files changed, 218 deletions(-) delete mode 100644 lib/serializer/CLoadIntegrityValidator.cpp delete mode 100644 lib/serializer/CLoadIntegrityValidator.h diff --git a/cmake_modules/VCMI_lib.cmake b/cmake_modules/VCMI_lib.cmake index be60f369b..0b969d102 100644 --- a/cmake_modules/VCMI_lib.cmake +++ b/cmake_modules/VCMI_lib.cmake @@ -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 diff --git a/lib/IGameCallback.cpp b/lib/IGameCallback.cpp index 25f70c0e2..55dcecdeb 100644 --- a/lib/IGameCallback.cpp +++ b/lib/IGameCallback.cpp @@ -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(*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 &); template DLL_LINKAGE void CPrivilegedInfoCallback::loadCommonState(CLoadFile &); template DLL_LINKAGE void CPrivilegedInfoCallback::saveCommonState(CSaveFile &) const; diff --git a/lib/VCMI_Lib.h b/lib/VCMI_Lib.h index c6cd971f9..dc9912e3b 100644 --- a/lib/VCMI_Lib.h +++ b/lib/VCMI_Lib.h @@ -120,51 +120,6 @@ public: #if SCRIPTING_ENABLED void scriptsLoaded(); #endif - - template 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; diff --git a/lib/modding/IdentifierStorage.h b/lib/modding/IdentifierStorage.h index 004d724c7..31857c447 100644 --- a/lib/modding/IdentifierStorage.h +++ b/lib/modding/IdentifierStorage.h @@ -52,12 +52,6 @@ class DLL_LINKAGE CIdentifierStorage { return id == other.id && scope == other.scope; } - - template void serialize(Handler &h, const int version) - { - h & id; - h & scope; - } }; std::multimap registeredObjects; @@ -102,12 +96,6 @@ public: /// called at the very end of loading to check for any missing ID's void finalize(); - - template void serialize(Handler &h, const int version) - { - h & registeredObjects; - h & state; - } }; VCMI_LIB_NAMESPACE_END diff --git a/lib/registerTypes/RegisterTypes.h b/lib/registerTypes/RegisterTypes.h index 907361a40..847c4b1eb 100644 --- a/lib/registerTypes/RegisterTypes.h +++ b/lib/registerTypes/RegisterTypes.h @@ -95,57 +95,6 @@ void registerTypesMapObjects1(Serializer &s) template void registerTypesMapObjectTypes(Serializer &s) { - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - s.template registerType(); - -#define REGISTER_GENERIC_HANDLER(TYPENAME) s.template registerType >() - - 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(); s.template registerType(); s.template registerType(); diff --git a/lib/serializer/CLoadIntegrityValidator.cpp b/lib/serializer/CLoadIntegrityValidator.cpp deleted file mode 100644 index 81b3be830..000000000 --- a/lib/serializer/CLoadIntegrityValidator.cpp +++ /dev/null @@ -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(primaryFileName, minimalVersion); - controlFile = std::make_unique(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 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 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 diff --git a/lib/serializer/CLoadIntegrityValidator.h b/lib/serializer/CLoadIntegrityValidator.h deleted file mode 100644 index 5adb4f3d3..000000000 --- a/lib/serializer/CLoadIntegrityValidator.h +++ /dev/null @@ -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 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 decay(); //returns primary file. CLoadIntegrityValidator stops being usable anymore -}; - -VCMI_LIB_NAMESPACE_END