void Serializer::StateSave::objectPtrArray (GenericArrayList *a) { //Store array size UintSize size = a->size(); store( &size, sizeof( UintSize )); //Store array elements for (UintSize s=0; s<size; ++s) objectPtr( (Object**) a->at(s) ); }
void Serializer::StateLoad::objectPtrArray (GenericArrayList *a) { //Load array size UintSize size = 0; load( &size, sizeof( UintSize )); //Insert array elements a->clear(); a->resize( size ); //Load array elements for (UintSize s=0; s<size; ++s) { objectPtr( (Object**) a->at(s) ); } }
uint32 ObjectMgr::constructPlayer( GameClient* requester, uint64 charUID ) { if (requester == NULL) throw ClientNotAvailable(); PlayerObject *newPlayerObj = NULL; try { newPlayerObj = new PlayerObject(*requester,charUID); } catch (PlayerObject::CharacterNotFound) { throw ObjectNotAvailable(); } uint32 theNewObjectId = getNewObjectId(); newPlayerObj->initGoId(theNewObjectId); m_objects[theNewObjectId]=objectPtr(newPlayerObj); return theNewObjectId; }
void Serializer::StateLoad::run (Object **ppRoot) { //Start with root object objectPtr( ppRoot ); //Process objects while (offset < maxoffset) { //Load class ID UUID cid; load( &cid, sizeof( UUID )); //Load object version Uint version = 0; load( &version, sizeof( Uint )); //Load serial ID UintSize sid = 0; load( &sid, sizeof( UintSize )); //Load object size UintSize size = 0; load( &size, sizeof( UintSize )); //Instantiate object Object *p = Serializer::Produce( cid ); //Check for invalid class ID if (p == NULL) { skip( size ); continue; } //Map object to serial ID if (sid >= objMap.size()) objMap.resizeAndCopy( sid + 100 ); objMap[ sid ] = p; //Record all the objects serializer->objects.pushBack( p ); //Deserialize object members p->serialize( serializer, version ); } //Process references while (!refStack.empty()) { //Pop reference off the stack LoadRefNode r = refStack.last(); refStack.popBack(); //Check for invalid serial ID if (r.id >= objMap.size()) { *r.pp = NULL; continue; } //Map serial ID to object *r.pp = objMap[ r.id ]; } }
void Serializer::StateSave::run (Object **ppRoot) { //Start with root object objectPtr( ppRoot ); //Process objects while (!objStack.empty()) { //Pop object node off the stack SaveObjNode o = objStack.last(); objStack.popBack(); //Insert object size when done if (o.done) { UintSize size = offset - o.offset; store( &size, o.szOffset, sizeof(UintSize) ); continue; } //Check for null pointer if (o.p == NULL) continue; //Map object to serial ID o.p->serialID = objMap.size(); objMap.pushBack( o.p ); //Store class ID UUID cid = o.p->getClass()->uuid(); store( &cid, sizeof( UUID )); //Store object version Uint version = o.p->version(); store( &version, sizeof( Uint )); //Store serial ID UintSize sid = o.p->serialID; store( &sid, sizeof( UintSize )); //Leave space for object size UintSize szOffset = offset; skip( sizeof( UintSize )); //Enqueue object done node SaveObjNode oDone = o; oDone.done = true; oDone.szOffset = szOffset; oDone.offset = offset; objStack.pushBack( oDone ); //Record all the objects serializer->objects.pushBack( o.p ); //Serialize object members o.p->serialize( serializer, version ); } //Process references while (!refStack.empty()) { //Pop reference node off the stack SaveRefNode r = refStack.last(); refStack.popBack(); //Check for null pointer if (r.p == NULL) { //Insert invalid serial ID UintSize invalidID = INVALID_SERIAL_ID; store( &invalidID, r.offset, sizeof(UintSize) ); continue; } //Insert object serial ID UintSize serialID = r.p->serialID; store( &serialID, r.offset, sizeof(UintSize) ); } }