Changeset 6455 for code/branches/network2/src
- Timestamp:
- Jan 22, 2010, 3:49:23 PM (15 years ago)
- Location:
- code/branches/network2/src/libraries/network/synchronisable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network2/src/libraries/network/synchronisable/Synchronisable.cc
r6450 r6455 49 49 * Initializes all Variables and sets the right objectID_ 50 50 */ 51 Synchronisable::Synchronisable(BaseObject* creator ){ 51 Synchronisable::Synchronisable(BaseObject* creator ) 52 { 52 53 RegisterRootObject(Synchronisable); 53 54 static uint32_t idCounter=0; … … 73 74 else 74 75 this->creatorID_ = OBJECTID_UNKNOWN; 75 76 /*searchcreatorID:77 if (creator)78 {79 Synchronisable* synchronisable_creator = orxonox_cast<Synchronisable*>(creator);80 if (synchronisable_creator && synchronisable_creator->objectMode_)81 {82 this->creatorID = synchronisable_creator->getScene()->getObjectID();83 }84 else if (creator != creator->getCreator())85 {86 creator = creator->getCreator();87 goto searchcreatorID;88 }89 }*/90 76 } 91 77 … … 94 80 * Delete all callback objects and remove objectID_ from the objectMap_ 95 81 */ 96 Synchronisable::~Synchronisable(){ 82 Synchronisable::~Synchronisable() 83 { 97 84 // delete callback function objects 98 85 if(!Identifier::isCreatingHierarchy()){ … … 118 105 * @param b true if this object is located on a client or on a server 119 106 */ 120 void Synchronisable::setClient(bool b){ 107 void Synchronisable::setClient(bool b) 108 { 121 109 if(b) // client 122 110 state_=0x2; … … 191 179 * @return true/false 192 180 */ 193 bool Synchronisable::deleteObject(uint32_t objectID_){ 181 bool Synchronisable::deleteObject(uint32_t objectID_) 182 { 194 183 if(!getSynchronisable(objectID_)) 195 184 return false; … … 208 197 * @return pointer to the Synchronisable with the objectID_ 209 198 */ 210 Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_){ 199 Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_) 200 { 211 201 std::map<uint32_t, Synchronisable*>::iterator it1; 212 202 it1 = objectMap_.find(objectID_); 213 203 if (it1 != objectMap_.end()) 214 204 return it1->second; 215 216 // ObjectList<Synchronisable>::iterator it;217 // for(it = ObjectList<Synchronisable>::begin(); it; ++it){218 // if( it->getObjectID()==objectID_ ){219 // objectMap_[objectID_] = *it;220 // return *it;221 // }222 // }223 205 // if the objects not in the map it should'nt exist at all anymore 224 206 return NULL; … … 240 222 * @return true: if !doSync or if everything was successfully saved 241 223 */ 242 uint32_t Synchronisable::getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode){ 224 uint32_t Synchronisable::getData(uint8_t*& mem, std::vector<uint32_t>& sizes, int32_t id, uint8_t mode) 225 { 243 226 unsigned int test = 0; 244 227 if(mode==0x0) … … 270 253 // COUT(4) << "objectid: " << this->objectID_ << ":"; 271 254 // copy to location 272 for(i=syncList_.begin(); i!=syncList_.end(); ++i){ 255 for(i=syncList_.begin(); i!=syncList_.end(); ++i) 256 { 273 257 uint32_t varsize = (*i)->getData( mem, mode ); 274 258 // COUT(4) << " " << varsize; … … 304 288 * @return true/false 305 289 */ 306 bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback){ 290 bool Synchronisable::updateData(uint8_t*& mem, uint8_t mode, bool forceCallback) 291 { 307 292 if(mode==0x0) 308 293 mode=state_; 309 if(syncList_.empty()){ 294 if(syncList_.empty()) 295 { 310 296 assert(0); 311 297 COUT(2) << "Synchronisable::updateData syncList_ is empty" << std::endl; … … 356 342 * @return amount of bytes 357 343 */ 358 uint32_t Synchronisable::getSize(int32_t id, uint8_t mode){ 344 uint32_t Synchronisable::getSize(int32_t id, uint8_t mode) 345 { 359 346 uint32_t tsize=SynchronisableHeader::getSize(); 360 347 if (mode==0x0) … … 365 352 tsize += this->dataSize_; 366 353 std::vector<SynchronisableVariableBase*>::iterator i; 367 for(i=stringList_.begin(); i!=stringList_.end(); ++i){ 354 for(i=stringList_.begin(); i!=stringList_.end(); ++i) 355 { 368 356 tsize += (*i)->getSize( mode ); 369 357 } … … 376 364 * @return true/false 377 365 */ 378 bool Synchronisable::doSync(int32_t id, uint8_t mode){ 366 bool Synchronisable::doSync(int32_t id, uint8_t mode) 367 { 379 368 if(mode==0x0) 380 369 mode=state_; … … 390 379 * @param mode same as in registerVar 391 380 */ 392 void Synchronisable::setSyncMode(uint8_t mode){ 381 void Synchronisable::setSyncMode(uint8_t mode) 382 { 393 383 assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3); 394 384 this->objectMode_=mode; … … 406 396 } 407 397 398 template <> void Synchronisable::unregisterVariable( std::string& variable ) 399 { 400 bool unregistered_nonexistent_variable = true; 401 std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin(); 402 while(it!=syncList_.end()) 403 { 404 if( ((*it)->getReference()) == &variable ) 405 { 406 delete (*it); 407 syncList_.erase(it); 408 unregistered_nonexistent_variable = false; 409 break; 410 } 411 else 412 ++it; 413 } 414 assert(unregistered_nonexistent_variable == false); 415 416 it = stringList_.begin(); 417 while(it!=stringList_.end()) 418 { 419 if( ((*it)->getReference()) == &variable ) 420 { 421 delete (*it); 422 stringList_.erase(it); 423 return; 424 } 425 else 426 ++it; 427 } 428 unregistered_nonexistent_variable = true; 429 assert(unregistered_nonexistent_variable == false); //if we reach this point something went wrong: 430 // the variable has not been registered before 431 } 432 408 433 409 434 } -
code/branches/network2/src/libraries/network/synchronisable/Synchronisable.h
r6450 r6455 177 177 Synchronisable(BaseObject* creator); 178 178 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false); 179 template <class T> void unregisterVariable(T& var); 179 180 180 181 void setPriority(unsigned int freq){ objectFrequency_ = freq; } … … 219 220 } 220 221 } 222 223 template <class T> void Synchronisable::unregisterVariable(T& variable){ 224 std::vector<SynchronisableVariableBase*>::iterator it = syncList_.begin(); 225 while(it!=syncList_.end()){ 226 if( ((*it)->getReference()) == &variable ){ 227 delete (*it); 228 syncList_.erase(it); 229 return; 230 } 231 else 232 it++; 233 } 234 bool unregistered_nonexistent_variable = false; 235 assert(unregistered_nonexistent_variable); //if we reach this point something went wrong: 236 // the variable has not been registered before 237 } 221 238 222 239 template <> _NetworkExport void Synchronisable::registerVariable( std::string& variable, uint8_t mode, NetworkCallbackBase *cb, bool bidirectional); 240 template <> _NetworkExport void Synchronisable::unregisterVariable( std::string& variable ); 223 241 224 242
Note: See TracChangeset
for help on using the changeset viewer.