mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-28 08:48:48 +02:00
Naive solution for endianess issues. Seems to allow loading a big-endian save on little-endian build.
Fixed compile issues with CEmptyAI. Removed unnecessary methods from its.
This commit is contained in:
parent
828d9e70d2
commit
4cd77a0192
@ -12,16 +12,22 @@ void CEmptyAI::yourTurn()
|
||||
{
|
||||
cb->endTurn();
|
||||
}
|
||||
void CEmptyAI::heroKilled(const CGHeroInstance *)
|
||||
{
|
||||
}
|
||||
void CEmptyAI::heroCreated(const CGHeroInstance *)
|
||||
{
|
||||
}
|
||||
void CEmptyAI::heroMoved(const TryMoveHero& TMH)
|
||||
{
|
||||
}
|
||||
void CEmptyAI::heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback)
|
||||
{
|
||||
callback(rand()%skills.size());
|
||||
}
|
||||
|
||||
void CEmptyAI::commanderGotLevel(const CCommanderInstance * commander, std::vector<ui32> skills, boost::function<void(ui32)> &callback)
|
||||
{
|
||||
callback(0);
|
||||
}
|
||||
|
||||
void CEmptyAI::showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, const int soundID, bool selection, bool cancel)
|
||||
{
|
||||
cb->selectionMade(0, askID);
|
||||
}
|
||||
|
||||
void CEmptyAI::showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function<void()> &onEnd)
|
||||
{
|
||||
onEnd();
|
||||
}
|
@ -12,17 +12,10 @@ class CEmptyAI : public CGlobalAI
|
||||
public:
|
||||
void init(CCallback * CB) override;
|
||||
void yourTurn() override;
|
||||
void heroKilled(const CGHeroInstance *) override;
|
||||
void heroCreated(const CGHeroInstance *) override;
|
||||
void heroMoved(const TryMoveHero&) override;
|
||||
void heroPrimarySkillChanged(const CGHeroInstance * hero, int which, si64 val) override {};
|
||||
void showSelDialog(std::string text, std::vector<CSelectableComponent*> & components, int askID) override {};
|
||||
void tileRevealed(const boost::unordered_set<int3, ShashInt3> &pos) override {};
|
||||
void tileHidden(const boost::unordered_set<int3, ShashInt3> &pos) override {};
|
||||
void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, int soundID, bool selection, bool cancel) override {};
|
||||
void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function<void()> &onEnd) override {};
|
||||
void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback) override;
|
||||
void commanderGotLevel (const CCommanderInstance * commander, std::vector<ui32> skills, boost::function<void(ui32)> &callback) override {}; //TODO
|
||||
void heroGotLevel(const CGHeroInstance *hero, int pskill, std::vector<ui16> &skills, boost::function<void(ui32)> &callback) override;
|
||||
void commanderGotLevel (const CCommanderInstance * commander, std::vector<ui32> skills, boost::function<void(ui32)> &callback) override;
|
||||
void showBlockingDialog(const std::string &text, const std::vector<Component> &components, ui32 askID, const int soundID, bool selection, bool cancel) override;
|
||||
void showGarrisonDialog(const CArmedInstance *up, const CGHeroInstance *down, bool removableUnits, boost::function<void()> &onEnd) override;
|
||||
};
|
||||
|
||||
#define NAME "EmptyAI 0.1"
|
||||
|
@ -302,7 +302,8 @@ CLoadFile::~CLoadFile()
|
||||
|
||||
int CLoadFile::read( const void * data, unsigned size )
|
||||
{
|
||||
sfile->read((char *)data,size);
|
||||
char *bytePtr = (char *)data;
|
||||
sfile->read(bytePtr, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
@ -335,8 +336,18 @@ void CLoadFile::openNextFile(const std::string &fname, int minimalVersion)
|
||||
}
|
||||
if(myVersion > version)
|
||||
{
|
||||
tlog1 << "Error: Too new file format! (file " << fname << " )\n";
|
||||
sfile.release();
|
||||
auto versionptr = (char*)&myVersion;
|
||||
std::reverse(versionptr, versionptr + 4);
|
||||
if(myVersion == version)
|
||||
{
|
||||
reverseEndianess = true;
|
||||
tlog3 << fname << " seems to have different endianess!\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
tlog1 << "Error: Too new file format! (file " << fname << " )\n";
|
||||
sfile.release();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -687,6 +687,7 @@ public:
|
||||
bool saving;
|
||||
std::map<ui16,CBasicPointerLoader*> loaders; // typeID => CPointerSaver<serializer,type>
|
||||
ui32 myVersion;
|
||||
bool reverseEndianess; //if source has different endianess than us, we reverse bytes
|
||||
|
||||
std::map<ui32, void*> loadedPointers;
|
||||
bool smartPointerSerialization;
|
||||
@ -696,6 +697,7 @@ public:
|
||||
saving = false;
|
||||
myVersion = version;
|
||||
smartPointerSerialization = true;
|
||||
reverseEndianess = false;
|
||||
}
|
||||
|
||||
~CISer()
|
||||
@ -758,7 +760,12 @@ public:
|
||||
template <typename T>
|
||||
void loadPrimitive(T &data)
|
||||
{
|
||||
this->This()->read(&data,sizeof(data));
|
||||
char * dataPtr = (char*)&data;
|
||||
unsigned length = sizeof(data);
|
||||
|
||||
this->This()->read(dataPtr,length);
|
||||
if(reverseEndianess)
|
||||
std::reverse(dataPtr, dataPtr + length);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
Loading…
Reference in New Issue
Block a user