1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-06-23 00:28:08 +02:00

Serializer will now smartly send over network CArtifact* and CHero*. Unified handling of items stored in vector.

Started making support for Black Market / Artifact merchant.
This commit is contained in:
Michał W. Urbańczyk
2010-06-26 16:02:10 +00:00
parent 627a1a5905
commit ec6342d9a7
20 changed files with 367 additions and 278 deletions

View File

@ -16,6 +16,9 @@
#include "../hch/CObjectHandler.h"
#include "../hch/CCreatureHandler.h"
#include "VCMI_Lib.h"
#include "../hch/CArtHandler.h"
#include "../hch/CHeroHandler.h"
#include "../hch/CTownHandler.h"
/*
@ -66,7 +69,6 @@ void CConnection::init()
tlog0 << "Established connection with "<<pom<<std::endl;
wmx = new boost::mutex;
rmx = new boost::mutex;
gs = NULL;
}
CConnection::CConnection(std::string host, std::string port, std::string Name)
@ -201,42 +203,6 @@ void CConnection::close()
}
}
CGObjectInstance *CConnection::loadObject()
{
assert(gs);
si32 id;
*this >> id;
assert(id >= 0 && id < gs->map->objects.size());
return gs->map->objects[id];
}
void CConnection::saveObject( const CGObjectInstance *data )
{
assert(gs);
assert(data);
*this << data->id;
}
CCreature * CConnection::loadCreature()
{
si32 id;
*this >> id;
assert(id >= 0 && id < VLC->creh->creatures.size());
return VLC->creh->creatures[id];
}
void CConnection::saveCreature(const CCreature *data)
{
assert(data);
*this << data->idNumber;
}
void CConnection::setGS( CGameState *state )
{
gs = state;
}
bool CConnection::isOpen() const
{
return socket && connected;
@ -362,3 +328,23 @@ ui16 CTypeList::getTypeID( const std::type_info *type )
else
return 0;
}
CSerializer::~CSerializer()
{
}
CSerializer::CSerializer()
{
smartVectorMembersSerialization = false;
}
void CSerializer::addStdVecItems(CGameState *gs, LibClasses *lib)
{
registerVectoredType(&gs->map->objects, &CGObjectInstance::id);
registerVectoredType(&lib->creh->creatures, &CCreature::idNumber);
registerVectoredType(&lib->arth->artifacts, &CArtifact::id);
registerVectoredType(&lib->heroh->heroes, &CHero::ID);
smartVectorMembersSerialization = true;
}