Changeset 1775 for code/branches/network/src/network/Synchronisable.cc
- Timestamp:
- Sep 12, 2008, 5:36:57 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/Synchronisable.cc
r1758 r1775 52 52 { 53 53 54 std::map<unsigned int, Synchronisable *> Synchronisable::objectMap_; 55 std::queue<unsigned int> Synchronisable::deletedObjects_; 54 56 55 57 int Synchronisable::state_=0x1; // detemines wheter we are server (default) or client … … 61 63 Synchronisable::Synchronisable(){ 62 64 RegisterRootObject(Synchronisable); 63 static int idCounter=0;65 static unsigned int idCounter=0; 64 66 datasize=0; 65 67 objectFrequency_=1; … … 67 69 objectID=idCounter++; 68 70 syncList = new std::list<synchronisableVariable *>; 69 //registerAllVariables();70 71 } 71 72 72 73 Synchronisable::~Synchronisable(){ 73 74 // delete callback function objects 74 if(!orxonox::Identifier::isCreatingHierarchy()) 75 if(!orxonox::Identifier::isCreatingHierarchy()){ 75 76 for(std::list<synchronisableVariable *>::iterator it = syncList->begin(); it!=syncList->end(); it++) 76 77 delete (*it)->callback; 78 assert(objectMap_[objectID]->objectID==objectID); 79 objectMap_.erase(objectID); 80 } 77 81 } 78 82 79 83 bool Synchronisable::create(){ 84 objectMap_[objectID]=this; 85 assert(objectMap_[objectID]==this); 80 86 this->classID = this->getIdentifier()->getNetworkID(); 81 87 COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl; … … 91 97 } 92 98 93 boolSynchronisable::fabricate(unsigned char*& mem, int mode)99 Synchronisable *Synchronisable::fabricate(unsigned char*& mem, int mode) 94 100 { 95 101 unsigned int size, objectID, classID; … … 98 104 classID = *(unsigned int*)(mem+2*sizeof(unsigned int)); 99 105 100 if(size==3*sizeof(unsigned int)){ //not our turn, dont do anything101 mem+=3*sizeof(unsigned int);102 return true;103 }104 105 106 orxonox::Identifier* id = GetIdentifier(classID); 106 if(!id){ 107 COUT(3) << "We could not identify a new object; classid: " << classID << " uint: " << (unsigned int)classID << " objectID: " << objectID << " size: " << size << std::endl; 108 assert(0); 109 return false; // most probably the gamestate is corrupted 110 } 107 assert(id); 111 108 orxonox::BaseObject *bo = id->fabricate(); 112 109 Synchronisable *no = dynamic_cast<Synchronisable *>(bo); … … 116 113 COUT(3) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl; 117 114 // update data and create object/entity... 118 if( !no->updateData(mem, mode) ){ 119 COUT(1) << "We couldn't update the object: " << objectID << std::endl; 120 return false; 121 } 122 if( !no->create() ) 123 { 124 COUT(1) << "We couldn't manifest (create() ) the object: " << objectID << std::endl; 125 return false; 126 } 115 assert(no->updateData(mem, mode)); 116 assert( no->create() ); 117 return no; 118 } 119 120 121 bool Synchronisable::deleteObject(unsigned int objectID){ 122 assert(getSynchronisable(objectID)); 123 assert(getSynchronisable(objectID)->objectID==objectID); 124 delete objectMap_[objectID]; 127 125 return true; 128 126 } 129 127 128 Synchronisable* Synchronisable::getSynchronisable(unsigned int objectID){ 129 std::map<unsigned int, Synchronisable *>::iterator i = objectMap_.find(objectID); 130 if(i==objectMap_.end()) 131 return NULL; 132 assert(i->second->objectID==objectID); 133 return (*i).second; 134 } 135 136 130 137 /** 131 138 * This function is used to register a variable to be synchronized … … 161 168 */ 162 169 bool Synchronisable::getData(unsigned char*& mem, unsigned int id, int mode){ 170 //if this tick is we dont synchronise, then abort now 171 if(!isMyTick(id)) 172 return true; 163 173 //std::cout << "inside getData" << std::endl; 164 174 unsigned int tempsize = 0; … … 170 180 std::list<synchronisableVariable *>::iterator i; 171 181 unsigned int size; 172 size=getSize 2(id, mode);182 size=getSize(id, mode); 173 183 174 184 // start copy header … … 182 192 // end copy header 183 193 184 //if this tick is we dont synchronise, then abort now185 if(!isMyTick(id))186 return true;187 194 188 195 COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl; … … 222 229 */ 223 230 bool Synchronisable::updateData(unsigned char*& mem, int mode){ 224 unsigned char *data = mem;225 231 if(mode==0x0) 226 232 mode=state_; … … 230 236 return false; 231 237 } 232 238 unsigned char *data=mem; 233 239 // start extract header 240 if(!isMyData(mem)) 241 return true; 234 242 unsigned int objectID, classID, size; 235 243 size = *(int *)mem; … … 242 250 assert(this->objectID==objectID); 243 251 assert(this->classID==classID); 244 if(size==3*sizeof(unsigned int)) //if true, only the header is available245 return true;246 //assert(0);247 252 248 253 COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " size: " << size << " synchronising data" << std::endl; … … 288 293 if(!isMyTick(id)) 289 294 return 0; 290 int tsize= 0;295 int tsize=sizeof(synchronisableHeader); 291 296 if(mode==0x0) 292 297 mode=state_; … … 311 316 312 317 /** 313 * This function returns the total amount of bytes needed by getData to save the whole content of the variables314 * @return amount of bytes315 */316 int Synchronisable::getSize2(unsigned int id, int mode){317 return sizeof(synchronisableHeader) + getSize( id, mode );318 }319 320 /**321 318 * 322 319 * @param id
Note: See TracChangeset
for help on using the changeset viewer.