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:
@@ -227,7 +227,7 @@ void CClient::initPlayerEnvironments()
|
||||
logNetwork->info("Preparing environment for player %s", color.toString());
|
||||
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;
|
||||
}
|
||||
|
||||
|
@@ -245,7 +245,7 @@ public:
|
||||
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 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 <QuestInfo> getMyQuests() const;
|
||||
|
||||
|
@@ -218,8 +218,6 @@ set(lib_MAIN_SRCS
|
||||
rmg/modificators/TerrainPainter.cpp
|
||||
rmg/MapProxy.cpp
|
||||
|
||||
serializer/BinaryDeserializer.cpp
|
||||
serializer/BinarySerializer.cpp
|
||||
serializer/CLoadFile.cpp
|
||||
serializer/CMemorySerializer.cpp
|
||||
serializer/Connection.cpp
|
||||
|
@@ -21,10 +21,6 @@
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
PlayerState::PlayerState()
|
||||
:PlayerState(nullptr)
|
||||
{}
|
||||
|
||||
PlayerState::PlayerState(IGameCallback *cb)
|
||||
: CBonusSystemNode(PLAYER)
|
||||
, GameCallbackHolder(cb)
|
||||
|
@@ -75,7 +75,6 @@ public:
|
||||
TurnTimerInfo turnTimer;
|
||||
|
||||
PlayerState(IGameCallback *cb);
|
||||
PlayerState();
|
||||
~PlayerState();
|
||||
|
||||
std::string nodeName() const override;
|
||||
|
@@ -1573,11 +1573,6 @@ void CGameState::buildBonusSystemTree()
|
||||
|
||||
void CGameState::deserializationFix()
|
||||
{
|
||||
assert(cb != nullptr);
|
||||
|
||||
for(auto & player : players)
|
||||
player.second.cb = cb;
|
||||
|
||||
buildGlobalTeamPlayerTree();
|
||||
attachArmedObjects();
|
||||
|
||||
|
@@ -2418,13 +2418,13 @@ void PlayerEndsTurn::applyGs(CGameState *gs)
|
||||
|
||||
void DaysWithoutTown::applyGs(CGameState *gs)
|
||||
{
|
||||
auto & playerState = gs->players[player];
|
||||
auto & playerState = gs->players.at(player);
|
||||
playerState.daysWithoutCastle = daysWithoutCastle;
|
||||
}
|
||||
|
||||
void TurnTimeUpdate::applyGs(CGameState *gs)
|
||||
{
|
||||
auto & playerState = gs->players[player];
|
||||
auto & playerState = gs->players.at(player);
|
||||
playerState.turnTimer = turnTimer;
|
||||
}
|
||||
|
||||
|
@@ -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
|
@@ -55,8 +55,8 @@ class BinaryDeserializer : public CLoaderBase
|
||||
public:
|
||||
using Version = ESerializationVersion;
|
||||
|
||||
bool reverseEndianness; //if source has different endianness than us, we reverse bytes
|
||||
Version version;
|
||||
bool reverseEndianness = false; //if source has different endianness than us, we reverse bytes
|
||||
Version version = Version::NONE;
|
||||
|
||||
std::vector<std::string> loadedStrings;
|
||||
std::map<uint32_t, Serializeable*> loadedPointers;
|
||||
@@ -71,7 +71,9 @@ public:
|
||||
return version >= what;
|
||||
};
|
||||
|
||||
DLL_LINKAGE BinaryDeserializer(IBinaryReader * r);
|
||||
BinaryDeserializer(IBinaryReader * r)
|
||||
: CLoaderBase(r)
|
||||
{}
|
||||
|
||||
template<class T>
|
||||
BinaryDeserializer & operator&(T & t)
|
||||
|
@@ -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
|
@@ -69,7 +69,10 @@ public:
|
||||
return version >= what;
|
||||
};
|
||||
|
||||
DLL_LINKAGE BinarySerializer(IBinaryWriter * w);
|
||||
BinarySerializer(IBinaryWriter * w)
|
||||
: CSaverBase(w)
|
||||
{
|
||||
}
|
||||
|
||||
template<class T>
|
||||
BinarySerializer & operator&(const T & t)
|
||||
|
@@ -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()
|
||||
{
|
||||
fName.clear();
|
||||
|
@@ -27,7 +27,6 @@ public:
|
||||
|
||||
void openNextFile(const boost::filesystem::path &fname); //throws!
|
||||
void clear();
|
||||
void reportState(vstd::CLoggerBase * out) override;
|
||||
|
||||
void putMagicBytes(const std::string &text);
|
||||
|
||||
|
@@ -9,28 +9,10 @@
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include "../GameConstants.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
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
|
||||
template<class S, class T>
|
||||
struct is_serializeable
|
||||
@@ -45,16 +27,19 @@ struct is_serializeable
|
||||
};
|
||||
|
||||
/// Base class for deserializers
|
||||
class DLL_LINKAGE IBinaryReader : public virtual CSerializer
|
||||
class IBinaryReader
|
||||
{
|
||||
public:
|
||||
virtual ~IBinaryReader() = default;
|
||||
virtual int read(std::byte * data, unsigned size) = 0;
|
||||
virtual void reportState(vstd::CLoggerBase * out){};
|
||||
};
|
||||
|
||||
/// Base class for serializers
|
||||
class DLL_LINKAGE IBinaryWriter : public virtual CSerializer
|
||||
class IBinaryWriter
|
||||
{
|
||||
public:
|
||||
virtual ~IBinaryWriter() = default;
|
||||
virtual int write(const std::byte * data, unsigned size) = 0;
|
||||
};
|
||||
|
||||
|
@@ -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)
|
||||
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
|
||||
|
||||
logGlobal->error("Illegal call to move hero!");
|
||||
|
Reference in New Issue
Block a user