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

Basic code review, remove unused code from serializers

This commit is contained in:
Ivan Savenko
2025-04-01 17:21:17 +03:00
parent d1d2cf4189
commit 586620a290
15 changed files with 19 additions and 91 deletions

View File

@@ -227,7 +227,7 @@ void CClient::initPlayerEnvironments()
logNetwork->info("Preparing environment for player %s", color.toString()); logNetwork->info("Preparing environment for player %s", color.toString());
playerEnvironments[color] = std::make_shared<CPlayerEnvironment>(color, this, std::make_shared<CCallback>(gamestate, color, this)); playerEnvironments[color] = std::make_shared<CPlayerEnvironment>(color, this, std::make_shared<CCallback>(gamestate, color, this));
if(!hasHumanPlayer && gameState()->players[color].isHuman()) if(!hasHumanPlayer && gameState()->players.at(color).isHuman())
hasHumanPlayer = true; hasHumanPlayer = true;
} }

View File

@@ -245,7 +245,7 @@ public:
virtual int getHeroSerial(const CGHeroInstance * hero, bool includeGarrisoned=true) const; virtual int getHeroSerial(const CGHeroInstance * hero, bool includeGarrisoned=true) const;
virtual const CGTownInstance* getTownBySerial(int serialId) const; // serial id is [0, number of towns) virtual const CGTownInstance* getTownBySerial(int serialId) const; // serial id is [0, number of towns)
virtual const CGHeroInstance* getHeroBySerial(int serialId, bool includeGarrisoned=true) const; // serial id is [0, number of heroes) virtual const CGHeroInstance* getHeroBySerial(int serialId, bool includeGarrisoned=true) const; // serial id is [0, number of heroes)
virtual std::vector <const CGHeroInstance *> getHeroesInfo() const; //true -> only owned; false -> all visible virtual std::vector <const CGHeroInstance *> getHeroesInfo() const;
virtual std::vector <const CGObjectInstance * > getMyObjects() const; //returns all objects flagged by belonging player virtual std::vector <const CGObjectInstance * > getMyObjects() const; //returns all objects flagged by belonging player
virtual std::vector <QuestInfo> getMyQuests() const; virtual std::vector <QuestInfo> getMyQuests() const;

View File

@@ -218,8 +218,6 @@ set(lib_MAIN_SRCS
rmg/modificators/TerrainPainter.cpp rmg/modificators/TerrainPainter.cpp
rmg/MapProxy.cpp rmg/MapProxy.cpp
serializer/BinaryDeserializer.cpp
serializer/BinarySerializer.cpp
serializer/CLoadFile.cpp serializer/CLoadFile.cpp
serializer/CMemorySerializer.cpp serializer/CMemorySerializer.cpp
serializer/Connection.cpp serializer/Connection.cpp

View File

@@ -21,10 +21,6 @@
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
PlayerState::PlayerState()
:PlayerState(nullptr)
{}
PlayerState::PlayerState(IGameCallback *cb) PlayerState::PlayerState(IGameCallback *cb)
: CBonusSystemNode(PLAYER) : CBonusSystemNode(PLAYER)
, GameCallbackHolder(cb) , GameCallbackHolder(cb)

View File

@@ -75,7 +75,6 @@ public:
TurnTimerInfo turnTimer; TurnTimerInfo turnTimer;
PlayerState(IGameCallback *cb); PlayerState(IGameCallback *cb);
PlayerState();
~PlayerState(); ~PlayerState();
std::string nodeName() const override; std::string nodeName() const override;

View File

@@ -1573,11 +1573,6 @@ void CGameState::buildBonusSystemTree()
void CGameState::deserializationFix() void CGameState::deserializationFix()
{ {
assert(cb != nullptr);
for(auto & player : players)
player.second.cb = cb;
buildGlobalTeamPlayerTree(); buildGlobalTeamPlayerTree();
attachArmedObjects(); attachArmedObjects();

View File

@@ -2418,13 +2418,13 @@ void PlayerEndsTurn::applyGs(CGameState *gs)
void DaysWithoutTown::applyGs(CGameState *gs) void DaysWithoutTown::applyGs(CGameState *gs)
{ {
auto & playerState = gs->players[player]; auto & playerState = gs->players.at(player);
playerState.daysWithoutCastle = daysWithoutCastle; playerState.daysWithoutCastle = daysWithoutCastle;
} }
void TurnTimeUpdate::applyGs(CGameState *gs) void TurnTimeUpdate::applyGs(CGameState *gs)
{ {
auto & playerState = gs->players[player]; auto & playerState = gs->players.at(player);
playerState.turnTimer = turnTimer; playerState.turnTimer = turnTimer;
} }

View File

@@ -1,21 +0,0 @@
/*
* BinaryDeserializer.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 "BinaryDeserializer.h"
VCMI_LIB_NAMESPACE_BEGIN
BinaryDeserializer::BinaryDeserializer(IBinaryReader * r): CLoaderBase(r)
{
version = Version::NONE;
reverseEndianness = false;
}
VCMI_LIB_NAMESPACE_END

View File

@@ -55,8 +55,8 @@ class BinaryDeserializer : public CLoaderBase
public: public:
using Version = ESerializationVersion; using Version = ESerializationVersion;
bool reverseEndianness; //if source has different endianness than us, we reverse bytes bool reverseEndianness = false; //if source has different endianness than us, we reverse bytes
Version version; Version version = Version::NONE;
std::vector<std::string> loadedStrings; std::vector<std::string> loadedStrings;
std::map<uint32_t, Serializeable*> loadedPointers; std::map<uint32_t, Serializeable*> loadedPointers;
@@ -71,7 +71,9 @@ public:
return version >= what; return version >= what;
}; };
DLL_LINKAGE BinaryDeserializer(IBinaryReader * r); BinaryDeserializer(IBinaryReader * r)
: CLoaderBase(r)
{}
template<class T> template<class T>
BinaryDeserializer & operator&(T & t) BinaryDeserializer & operator&(T & t)

View File

@@ -1,19 +0,0 @@
/*
* BinarySerializer.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 "BinarySerializer.h"
VCMI_LIB_NAMESPACE_BEGIN
BinarySerializer::BinarySerializer(IBinaryWriter * w): CSaverBase(w)
{
}
VCMI_LIB_NAMESPACE_END

View File

@@ -69,7 +69,10 @@ public:
return version >= what; return version >= what;
}; };
DLL_LINKAGE BinarySerializer(IBinaryWriter * w); BinarySerializer(IBinaryWriter * w)
: CSaverBase(w)
{
}
template<class T> template<class T>
BinarySerializer & operator&(const T & t) BinarySerializer & operator&(const T & t)

View File

@@ -49,15 +49,6 @@ void CSaveFile::openNextFile(const boost::filesystem::path &fname)
} }
} }
void CSaveFile::reportState(vstd::CLoggerBase * out)
{
out->debug("CSaveFile");
if(sfile.get() && *sfile)
{
out->debug("\tOpened %s \tPosition: %d", fName, sfile->tellp());
}
}
void CSaveFile::clear() void CSaveFile::clear()
{ {
fName.clear(); fName.clear();

View File

@@ -27,7 +27,6 @@ public:
void openNextFile(const boost::filesystem::path &fname); //throws! void openNextFile(const boost::filesystem::path &fname); //throws!
void clear(); void clear();
void reportState(vstd::CLoggerBase * out) override;
void putMagicBytes(const std::string &text); void putMagicBytes(const std::string &text);

View File

@@ -9,28 +9,10 @@
*/ */
#pragma once #pragma once
#include "../GameConstants.h"
VCMI_LIB_NAMESPACE_BEGIN VCMI_LIB_NAMESPACE_BEGIN
const std::string SAVEGAME_MAGIC = "VCMISVG"; const std::string SAVEGAME_MAGIC = "VCMISVG";
class CHero;
class CGHeroInstance;
class CGObjectInstance;
class CGameState;
class GameLibrary;
extern DLL_LINKAGE GameLibrary * LIBRARY;
/// Base class for serializers capable of reading or writing data
class DLL_LINKAGE CSerializer : boost::noncopyable
{
public:
virtual ~CSerializer() = default;
virtual void reportState(vstd::CLoggerBase * out){};
};
/// Helper to detect classes with user-provided serialize(S&, int version) method /// Helper to detect classes with user-provided serialize(S&, int version) method
template<class S, class T> template<class S, class T>
struct is_serializeable struct is_serializeable
@@ -45,16 +27,19 @@ struct is_serializeable
}; };
/// Base class for deserializers /// Base class for deserializers
class DLL_LINKAGE IBinaryReader : public virtual CSerializer class IBinaryReader
{ {
public: public:
virtual ~IBinaryReader() = default;
virtual int read(std::byte * data, unsigned size) = 0; virtual int read(std::byte * data, unsigned size) = 0;
virtual void reportState(vstd::CLoggerBase * out){};
}; };
/// Base class for serializers /// Base class for serializers
class DLL_LINKAGE IBinaryWriter : public virtual CSerializer class IBinaryWriter
{ {
public: public:
virtual ~IBinaryWriter() = default;
virtual int write(const std::byte * data, unsigned size) = 0; virtual int write(const std::byte * data, unsigned size) = 0;
}; };

View File

@@ -802,7 +802,7 @@ bool CGameHandler::moveHero(ObjectInstanceID hid, int3 dst, EMovementMode moveme
// not turn of that hero or player can't simply teleport hero (at least not with this function) // not turn of that hero or player can't simply teleport hero (at least not with this function)
if(!h || (asker != PlayerColor::NEUTRAL && movementMode != EMovementMode::STANDARD)) if(!h || (asker != PlayerColor::NEUTRAL && movementMode != EMovementMode::STANDARD))
{ {
if(h && getStartInfo()->turnTimerInfo.isEnabled() && gameState()->players[h->getOwner()].turnTimer.turnTimer == 0) if(h && getStartInfo()->turnTimerInfo.isEnabled() && gameState()->players.at(h->getOwner()).turnTimer.turnTimer == 0)
return true; //timer expired, no error return true; //timer expired, no error
logGlobal->error("Illegal call to move hero!"); logGlobal->error("Illegal call to move hero!");