Changeset 5929 for code/trunk/src/libraries/network/synchronisable
- Timestamp:
- Oct 12, 2009, 8:20:07 PM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core5 (added) merged: 5768-5769,5772,5775-5780,5783-5785,5791-5792,5795-5807,5809-5814,5816-5832,5836-5839,5842-5853,5855-5899,5904-5922,5924-5928
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
r5781 r5929 47 47 /** 48 48 * Constructor: 49 * Initializes all Variables and sets the right objectID 49 * Initializes all Variables and sets the right objectID_ 50 50 */ 51 Synchronisable::Synchronisable(BaseObject* creator ){51 Synchronisable::Synchronisable(BaseObject* creator ){ 52 52 RegisterRootObject(Synchronisable); 53 53 static uint32_t idCounter=0; … … 55 55 if ( GameMode::isMaster() || ( Host::running() && Host::isServer() ) ) 56 56 { 57 this->objectID = idCounter++; //this is only needed when running a server 58 //add synchronisable to the objectMap 59 objectMap_[this->objectID] = this; 57 this->setObjectID( idCounter++ ); 60 58 } 61 59 else 62 60 { 63 objectID=OBJECTID_UNKNOWN; 64 this->setObjectMode(0x0); //make sure this object doesn't get synchronized 65 } 66 classID = static_cast<uint32_t>(-1); 61 objectID_=OBJECTID_UNKNOWN; 62 } 63 classID_ = static_cast<uint32_t>(-1); 67 64 68 65 // set dataSize to 0 … … 72 69 73 70 // get creator id 74 this->creatorID = OBJECTID_UNKNOWN; 75 76 searchcreatorID: 71 if( creator ) 72 this->creatorID_ = creator->getSceneID(); 73 else 74 this->creatorID_ = OBJECTID_UNKNOWN; 75 76 /*searchcreatorID: 77 77 if (creator) 78 78 { … … 80 80 if (synchronisable_creator && synchronisable_creator->objectMode_) 81 81 { 82 this->creatorID = synchronisable_creator->get ObjectID();82 this->creatorID = synchronisable_creator->getScene()->getObjectID(); 83 83 } 84 84 else if (creator != creator->getCreator()) … … 87 87 goto searchcreatorID; 88 88 } 89 } 89 }*/ 90 90 } 91 91 92 92 /** 93 93 * Destructor: 94 * Delete all callback objects and remove objectID from the objectMap_94 * Delete all callback objects and remove objectID_ from the objectMap_ 95 95 */ 96 96 Synchronisable::~Synchronisable(){ … … 99 99 // remove object from the static objectMap 100 100 if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer())) 101 deletedObjects_.push(objectID );101 deletedObjects_.push(objectID_); 102 102 } 103 103 // delete all Synchronisable Variables from syncList ( which are also in stringList ) … … 107 107 stringList.clear(); 108 108 std::map<uint32_t, Synchronisable*>::iterator it; 109 it = objectMap_.find(objectID );109 it = objectMap_.find(objectID_); 110 110 if (it != objectMap_.end()) 111 111 objectMap_.erase(it); … … 172 172 Synchronisable *no = orxonox_cast<Synchronisable*>(bo); 173 173 assert(no); 174 no->objectID=header.getObjectID(); 175 no->creatorID=header.getCreatorID(); //TODO: remove this 176 no->classID=header.getClassID(); 177 COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl; 174 assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() ); 175 no->setObjectID(header.getObjectID()); 176 //no->creatorID=header.getCreatorID(); //TODO: remove this 177 no->setClassID(header.getClassID()); 178 assert(no->creatorID_ == header.getCreatorID()); 179 //assert(no->classID_ == header.getClassID()); 180 COUT(4) << "fabricate objectID_: " << no->objectID_ << " classID_: " << no->classID_ << std::endl; 178 181 // update data and create object/entity... 179 assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() );180 Synchronisable::objectMap_[header.getObjectID()] = no;181 182 bool b = no->updateData(mem, mode, true); 182 183 assert(b); … … 191 192 192 193 /** 193 * Finds and deletes the Synchronisable with the appropriate objectID 194 * @param objectID objectIDof the Synchronisable194 * Finds and deletes the Synchronisable with the appropriate objectID_ 195 * @param objectID_ objectID_ of the Synchronisable 195 196 * @return true/false 196 197 */ 197 bool Synchronisable::deleteObject(uint32_t objectID ){198 if(!getSynchronisable(objectID ))198 bool Synchronisable::deleteObject(uint32_t objectID_){ 199 if(!getSynchronisable(objectID_)) 199 200 return false; 200 assert(getSynchronisable(objectID )->objectID==objectID);201 Synchronisable *s = getSynchronisable(objectID );201 assert(getSynchronisable(objectID_)->objectID_==objectID_); 202 Synchronisable *s = getSynchronisable(objectID_); 202 203 if(s) 203 delete s;204 s->destroy(); // or delete? 204 205 else 205 206 return false; … … 208 209 209 210 /** 210 * This function looks up the objectID in the objectMap_ and returns a pointer to the right Synchronisable211 * @param objectID objectIDof the Synchronisable212 * @return pointer to the Synchronisable with the objectID 213 */ 214 Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID ){211 * This function looks up the objectID_ in the objectMap_ and returns a pointer to the right Synchronisable 212 * @param objectID_ objectID_ of the Synchronisable 213 * @return pointer to the Synchronisable with the objectID_ 214 */ 215 Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_){ 215 216 std::map<uint32_t, Synchronisable*>::iterator it1; 216 it1 = objectMap_.find(objectID );217 it1 = objectMap_.find(objectID_); 217 218 if (it1 != objectMap_.end()) 218 219 return it1->second; … … 220 221 // ObjectList<Synchronisable>::iterator it; 221 222 // for(it = ObjectList<Synchronisable>::begin(); it; ++it){ 222 // if( it->getObjectID()==objectID ){223 // objectMap_[objectID ] = *it;223 // if( it->getObjectID()==objectID_ ){ 224 // objectMap_[objectID_] = *it; 224 225 // return *it; 225 226 // } … … 231 232 232 233 /** 233 * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID and classIDto the given memory234 * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID_ and classID_ to the given memory 234 235 * takes a pointer to already allocated memory (must have at least getSize bytes length) 235 236 * structure of the bitstream: 236 * |totalsize,objectID ,classID,var1,var2,string1_length,string1,var3,...|237 * |totalsize,objectID_,classID_,var1,var2,string1_length,string1,var3,...| 237 238 * length of varx: size saved int syncvarlist 238 239 * @param mem pointer to allocated memory with enough size … … 252 253 uint32_t tempsize = 0; 253 254 #ifndef NDEBUG 254 if (this->classID ==0)255 if (this->classID_==0) 255 256 COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl; 256 257 #endif 257 258 258 if (this->classID == static_cast<uint32_t>(-1)) 259 this->classID = this->getIdentifier()->getNetworkID(); 260 261 assert(ClassByID(this->classID)); 262 assert(this->classID==this->getIdentifier()->getNetworkID()); 259 if (this->classID_ == static_cast<uint32_t>(-1)) 260 this->classID_ = this->getIdentifier()->getNetworkID(); 261 262 assert(ClassByID(this->classID_)); 263 assert(this->classID_==this->getIdentifier()->getNetworkID()); 264 assert(this->objectID_!=OBJECTID_UNKNOWN); 263 265 std::vector<SynchronisableVariableBase*>::iterator i; 264 266 … … 269 271 270 272 271 COUT(5) << "Synchronisable getting data from objectID : " << objectID << " classID: " << classID<< std::endl;273 COUT(5) << "Synchronisable getting data from objectID_: " << objectID_ << " classID_: " << classID_ << std::endl; 272 274 // copy to location 273 275 for(i=syncList.begin(); i!=syncList.end(); ++i){ … … 277 279 278 280 tempsize += SynchronisableHeader::getSize(); 279 header.setObjectID( this->objectID );280 header.setCreatorID( this->creatorID );281 header.setClassID( this->classID );281 header.setObjectID( this->objectID_ ); 282 header.setCreatorID( this->creatorID_ ); 283 header.setClassID( this->classID_ ); 282 284 header.setDataAvailable( true ); 283 285 header.setDataSize( tempsize ); … … 311 313 // start extract header 312 314 SynchronisableHeader syncHeader(mem); 313 assert(syncHeader.getObjectID()==this->objectID );314 assert(syncHeader.getCreatorID()==this->creatorID );315 assert(syncHeader.getClassID()==this->classID );315 assert(syncHeader.getObjectID()==this->objectID_); 316 assert(syncHeader.getCreatorID()==this->creatorID_); 317 assert(syncHeader.getClassID()==this->classID_); 316 318 if(syncHeader.isDataAvailable()==false){ 317 319 mem += syncHeader.getDataSize(); … … 322 324 // stop extract header 323 325 324 //COUT(5) << "Synchronisable: objectID " << syncHeader.getObjectID() << ", classID" << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;326 //COUT(5) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl; 325 327 for(i=syncList.begin(); i!=syncList.end(); i++) 326 328 { … … 361 363 if(mode==0x0) 362 364 mode=state_; 363 return ( ( objectMode_&mode)!=0 && (!syncList.empty() ) );364 } 365 366 /** 367 * This function looks at the header located in the bytestream and checks wheter objectID and classIDmatch with the Synchronisables ones365 return ( (this->objectMode_ & mode)!=0 && (!syncList.empty() ) ); 366 } 367 368 /** 369 * This function looks at the header located in the bytestream and checks wheter objectID_ and classID_ match with the Synchronisables ones 368 370 * @param mem pointer to the bytestream 369 371 */ … … 371 373 { 372 374 SynchronisableHeader header(mem); 373 assert(header.getObjectID()==this->objectID );375 assert(header.getObjectID()==this->objectID_); 374 376 return header.isDataAvailable(); 375 377 } … … 383 385 * @param mode same as in registerVar 384 386 */ 385 void Synchronisable::set ObjectMode(uint8_t mode){387 void Synchronisable::setSyncMode(uint8_t mode){ 386 388 assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3); 387 objectMode_=mode;389 this->objectMode_=mode; 388 390 } 389 391 -
code/trunk/src/libraries/network/synchronisable/Synchronisable.h
r5781 r5929 68 68 * @brief: stores information about a Synchronisable 69 69 * 70 * This class stores the information about a Synchronisable (objectID , classID, creatorID, dataSize)70 * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize) 71 71 * in an emulated bitset. 72 72 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream 73 73 * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 0 74 * Byte 5 to 8: objectID 75 * Byte 9 to 12: classID 76 * Byte 13 to 16: creatorID 74 * Byte 5 to 8: objectID_ 75 * Byte 9 to 12: classID_ 76 * Byte 13 to 16: creatorID_ 77 77 */ 78 78 class _NetworkExport SynchronisableHeader{ … … 94 94 inline uint32_t getObjectID() const 95 95 { return *(uint32_t*)(data_+4); } 96 inline void setObjectID(uint32_t objectID )97 { *(uint32_t*)(data_+4) = objectID ; }96 inline void setObjectID(uint32_t objectID_) 97 { *(uint32_t*)(data_+4) = objectID_; } 98 98 inline uint32_t getClassID() const 99 99 { return *(uint32_t*)(data_+8); } 100 inline void setClassID(uint32_t classID )101 { *(uint32_t*)(data_+8) = classID ; }100 inline void setClassID(uint32_t classID_) 101 { *(uint32_t*)(data_+8) = classID_; } 102 102 inline uint32_t getCreatorID() const 103 103 { return *(uint32_t*)(data_+12); } 104 inline void setCreatorID(uint32_t creatorID )105 { *(uint32_t*)(data_+12) = creatorID ; }104 inline void setCreatorID(uint32_t creatorID_) 105 { *(uint32_t*)(data_+12) = creatorID_; } 106 106 inline void operator=(SynchronisableHeader& h) 107 107 { memcpy(data_, h.data_, getSize()); } … … 122 122 123 123 static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0); 124 static bool deleteObject(uint32_t objectID );125 static Synchronisable *getSynchronisable(uint32_t objectID );124 static bool deleteObject(uint32_t objectID_); 125 static Synchronisable *getSynchronisable(uint32_t objectID_); 126 126 static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); } 127 127 static uint32_t popDeletedObject(){ uint32_t i = deletedObjects_.front(); deletedObjects_.pop(); return i; } 128 128 129 inline uint32_t getObjectID() const {return objectID;} 130 inline unsigned int getCreatorID() const {return creatorID;} 131 inline uint32_t getClassID() const {return classID;} 132 inline unsigned int getPriority() const { return objectFrequency_;} 129 inline uint32_t getObjectID() const {return this->objectID_;} 130 inline unsigned int getCreatorID() const {return this->creatorID_;} 131 inline uint32_t getClassID() const {return this->classID_;} 132 inline unsigned int getPriority() const { return this->objectFrequency_;} 133 inline uint8_t getSyncMode() const { return this->objectMode_; } 134 135 void setSyncMode(uint8_t mode); 133 136 134 137 protected: … … 136 139 template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false); 137 140 //template <class T> void unregisterVariable(T& var); 138 void setObjectMode(uint8_t mode);139 141 void setPriority(unsigned int freq){ objectFrequency_ = freq; } 140 142 … … 146 148 bool isMyData(uint8_t* mem); 147 149 bool doSync(int32_t id, uint8_t mode=0x0); 148 149 uint32_t objectID; 150 uint32_t creatorID; 151 uint32_t classID; 150 151 inline void setObjectID(uint32_t id){ this->objectID_ = id; objectMap_[this->objectID_] = this; } 152 inline void setClassID(uint32_t id){ this->classID_ = id; } 153 154 uint32_t objectID_; 155 uint32_t creatorID_; 156 uint32_t classID_; 152 157 153 158 std::vector<SynchronisableVariableBase*> syncList;
Note: See TracChangeset
for help on using the changeset viewer.