mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-26 22:57:00 +02:00
Support for smart pointer serialization. Fixed creature banks serialization. Minor fixes.
This commit is contained in:
parent
01831e912a
commit
eb6f7fffc9
@ -1025,7 +1025,7 @@ void CGeniusAI::yourTurn()
|
|||||||
{
|
{
|
||||||
static boost::mutex mutex;
|
static boost::mutex mutex;
|
||||||
boost::mutex::scoped_lock lock(mutex);
|
boost::mutex::scoped_lock lock(mutex);
|
||||||
m_cb->waitTillRealize = true;
|
m_cb->waitTillRealize = false;
|
||||||
static int seed = rand();
|
static int seed = rand();
|
||||||
srand(seed);
|
srand(seed);
|
||||||
// if (m_cb->getDate() == 1) {
|
// if (m_cb->getDate() == 1) {
|
||||||
|
@ -2037,7 +2037,7 @@ void CAdvMapInt::mouseMoved( const SDL_MouseMotionEvent & sEvent )
|
|||||||
|
|
||||||
bool CAdvMapInt::isActive()
|
bool CAdvMapInt::isActive()
|
||||||
{
|
{
|
||||||
return active & ~CIntObject.KEYBOARD;
|
return active & ~CIntObject::KEYBOARD;
|
||||||
}
|
}
|
||||||
|
|
||||||
CAdventureOptions::CAdventureOptions()
|
CAdventureOptions::CAdventureOptions()
|
||||||
|
@ -167,7 +167,9 @@ void CObjectHandler::loadObjects()
|
|||||||
|
|
||||||
for(int i=0; i<4; ++i) //reading levels
|
for(int i=0; i<4; ++i) //reading levels
|
||||||
{
|
{
|
||||||
BankConfig bc;
|
banksInfo[g].push_back(new BankConfig);
|
||||||
|
|
||||||
|
BankConfig &bc = *banksInfo[g].back();
|
||||||
std::string buf;
|
std::string buf;
|
||||||
char dump;
|
char dump;
|
||||||
//bc.level is of type char and thus we cannot read directly to it; same for some othre variables
|
//bc.level is of type char and thus we cannot read directly to it; same for some othre variables
|
||||||
@ -210,8 +212,6 @@ void CObjectHandler::loadObjects()
|
|||||||
istr >> bc.rewardDifficulty;
|
istr >> bc.rewardDifficulty;
|
||||||
istr >> buf;
|
istr >> buf;
|
||||||
bc.easiest = atoi(buf.c_str());
|
bc.easiest = atoi(buf.c_str());
|
||||||
|
|
||||||
banksInfo[g].push_back(bc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4076,9 +4076,9 @@ void CBank::reset(ui16 var1) //prevents desync
|
|||||||
ui8 chance = 0;
|
ui8 chance = 0;
|
||||||
for (ui8 i = 0; i < VLC->objh->banksInfo[index].size(); i++)
|
for (ui8 i = 0; i < VLC->objh->banksInfo[index].size(); i++)
|
||||||
{
|
{
|
||||||
if (var1 < (chance += VLC->objh->banksInfo[index][i].chance))
|
if (var1 < (chance += VLC->objh->banksInfo[index][i]->chance))
|
||||||
{
|
{
|
||||||
bc = &VLC->objh->banksInfo[index][i];
|
bc = VLC->objh->banksInfo[index][i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -4125,7 +4125,7 @@ void CBank::setPropertyDer (ui8 what, ui32 val)
|
|||||||
multiplier = ((float)val)/100;
|
multiplier = ((float)val)/100;
|
||||||
break;
|
break;
|
||||||
case 13: //bank preset
|
case 13: //bank preset
|
||||||
bc = &VLC->objh->banksInfo[index][val];
|
bc = VLC->objh->banksInfo[index][val];
|
||||||
break;
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
reset (val%100);
|
reset (val%100);
|
||||||
|
@ -938,7 +938,7 @@ class DLL_EXPORT CBank : public CArmedInstance
|
|||||||
template <typename Handler> void serialize(Handler &h, const int version)
|
template <typename Handler> void serialize(Handler &h, const int version)
|
||||||
{
|
{
|
||||||
h & static_cast<CGObjectInstance&>(*this);
|
h & static_cast<CGObjectInstance&>(*this);
|
||||||
h & index & multiplier & artifacts & daycounter;
|
h & index & multiplier & artifacts & daycounter & bc;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
class DLL_EXPORT CGPyramid : public CBank
|
class DLL_EXPORT CGPyramid : public CBank
|
||||||
@ -1057,7 +1057,7 @@ class DLL_EXPORT CObjectHandler
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
std::vector<si32> cregens; //type 17. dwelling subid -> creature ID
|
std::vector<si32> cregens; //type 17. dwelling subid -> creature ID
|
||||||
std::map <ui32, std::vector <BankConfig> > banksInfo; //[index][preset]
|
std::map <ui32, std::vector <BankConfig*> > banksInfo; //[index][preset]
|
||||||
std::map <ui32, std::string> creBanksNames; //[crebank index] -> name of this creature bank
|
std::map <ui32, std::string> creBanksNames; //[crebank index] -> name of this creature bank
|
||||||
|
|
||||||
void loadObjects();
|
void loadObjects();
|
||||||
|
@ -47,6 +47,8 @@ CTypeList typeList;
|
|||||||
|
|
||||||
void CConnection::init()
|
void CConnection::init()
|
||||||
{
|
{
|
||||||
|
CISer::smartPointerSerialization = false;
|
||||||
|
COSer::smartPointerSerialization = false;
|
||||||
registerTypes(static_cast<CISer<CConnection>&>(*this));
|
registerTypes(static_cast<CISer<CConnection>&>(*this));
|
||||||
registerTypes(static_cast<COSer<CConnection>&>(*this));
|
registerTypes(static_cast<COSer<CConnection>&>(*this));
|
||||||
#ifdef LIL_ENDIAN
|
#ifdef LIL_ENDIAN
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
#include <boost/mpl/identity.hpp>
|
#include <boost/mpl/identity.hpp>
|
||||||
|
|
||||||
#include <boost/type_traits/is_array.hpp>
|
#include <boost/type_traits/is_array.hpp>
|
||||||
const ui32 version = 713;
|
const ui32 version = 714;
|
||||||
class CConnection;
|
class CConnection;
|
||||||
class CGObjectInstance;
|
class CGObjectInstance;
|
||||||
class CGameState;
|
class CGameState;
|
||||||
@ -255,9 +255,13 @@ public:
|
|||||||
bool saving;
|
bool saving;
|
||||||
std::map<ui16,CBasicPointerSaver*> savers; // typeID => CPointerSaver<serializer,type>
|
std::map<ui16,CBasicPointerSaver*> savers; // typeID => CPointerSaver<serializer,type>
|
||||||
|
|
||||||
|
std::map<const void*, ui32> savedPointers;
|
||||||
|
bool smartPointerSerialization;
|
||||||
|
|
||||||
COSer()
|
COSer()
|
||||||
{
|
{
|
||||||
saving=true;
|
saving=true;
|
||||||
|
smartPointerSerialization = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T> void registerType(const T * t=NULL)
|
template<typename T> void registerType(const T * t=NULL)
|
||||||
@ -304,6 +308,22 @@ public:
|
|||||||
if(!hlp)
|
if(!hlp)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if(smartPointerSerialization)
|
||||||
|
{
|
||||||
|
std::map<const void*,ui32>::iterator i = savedPointers.find(data);
|
||||||
|
if(i != savedPointers.end())
|
||||||
|
{
|
||||||
|
//this pointer has been already serialized - write only it's id
|
||||||
|
*this << i->second;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//give id to this pointer
|
||||||
|
ui32 pid = (ui32)savedPointers.size();
|
||||||
|
savedPointers[data] = pid;
|
||||||
|
*this << pid;
|
||||||
|
}
|
||||||
|
|
||||||
//write type identifier
|
//write type identifier
|
||||||
ui16 tid = typeList.getTypeID(data);
|
ui16 tid = typeList.getTypeID(data);
|
||||||
*this << tid;
|
*this << tid;
|
||||||
@ -438,10 +458,14 @@ public:
|
|||||||
std::map<ui16,CBasicPointerLoader*> loaders; // typeID => CPointerSaver<serializer,type>
|
std::map<ui16,CBasicPointerLoader*> loaders; // typeID => CPointerSaver<serializer,type>
|
||||||
ui32 myVersion;
|
ui32 myVersion;
|
||||||
|
|
||||||
|
std::map<ui32, void*> loadedPointers;
|
||||||
|
bool smartPointerSerialization;
|
||||||
|
|
||||||
CISer()
|
CISer()
|
||||||
{
|
{
|
||||||
saving = false;
|
saving = false;
|
||||||
myVersion = version;
|
myVersion = version;
|
||||||
|
smartPointerSerialization = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
~CISer()
|
~CISer()
|
||||||
@ -533,10 +557,28 @@ public:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ui32 pid = -1; //pointer id (or maybe rather pointee id)
|
||||||
|
std::map<ui32, void*>::iterator i = loadedPointers.end();
|
||||||
|
if(smartPointerSerialization)
|
||||||
|
{
|
||||||
|
*this >> pid; //get the id
|
||||||
|
i = loadedPointers.find(pid); //lookup
|
||||||
|
|
||||||
|
if(i != loadedPointers.end())
|
||||||
|
{
|
||||||
|
//we already got this pointer
|
||||||
|
data = static_cast<T>(i->second);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//get type id
|
//get type id
|
||||||
ui16 tid;
|
ui16 tid;
|
||||||
*this >> tid;
|
*this >> tid;
|
||||||
This()->loadPointerHlp(tid, data);
|
This()->loadPointerHlp(tid, data);
|
||||||
|
|
||||||
|
if(smartPointerSerialization && i == loadedPointers.end())
|
||||||
|
loadedPointers[pid] = data; //add loaded pointer to our lookup map
|
||||||
}
|
}
|
||||||
|
|
||||||
//that part of ptr deserialization was extracted to allow customization of its behavior in derived classes
|
//that part of ptr deserialization was extracted to allow customization of its behavior in derived classes
|
||||||
|
Loading…
Reference in New Issue
Block a user