Changeset 7801 for code/trunk/src/libraries/network/synchronisable
- Timestamp:
- Dec 22, 2010, 7:24:24 PM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/synchronisable/Synchronisable.cc
r7401 r7801 123 123 { 124 124 SynchronisableHeader header(mem); 125 assert( !header.isDiffed() ); 125 if( header.isDiffed() ) 126 { 127 mem += header.getDataSize() + header.getSize(); 128 return 0; 129 } 130 // assert( !header.isDiffed() ); 126 131 127 132 COUT(4) << "fabricating object with id: " << header.getObjectID() << std::endl; … … 217 222 * length of varx: size saved int syncvarlist 218 223 * @param mem pointer to allocated memory with enough size 219 * @param sizes FIXME - add doc!224 * @param sizes vector containing sizes of all objects in gamestate (to be appended) 220 225 * @param id gamestateid of the gamestate to be saved (important for priorities) 221 226 * @param mode defines the direction in which the data will be send/received 222 227 * 0x1: server->client 223 * 0x2: client->server (not recommended)228 * 0x2: client->server 224 229 * 0x3: bidirectional 225 230 * @return true: if !doSync or if everything was successfully saved … … 265 270 //tempsize += (*i)->getSize( mode ); 266 271 } 272 assert(tempsize!=0); // if this happens an empty object (with no variables) would be transmitted 267 273 // COUT(4) << endl; 268 274 … … 316 322 mem += SynchronisableHeader::getSize(); 317 323 std::vector<SynchronisableVariableBase *>::iterator i; 318 for(i=syncList_.begin(); i!=syncList_.end(); i++)324 for(i=syncList_.begin(); i!=syncList_.end(); ++i) 319 325 { 320 326 assert( mem <= data+syncHeader2.getDataSize()+SynchronisableHeader::getSize() ); // always make sure we don't exceed the datasize in our stream -
code/trunk/src/libraries/network/synchronisable/Synchronisable.h
r7163 r7801 65 65 }; 66 66 } 67 68 typedef uint8_t VariableID;69 70 /**71 * @brief: stores information about a Synchronisable72 *73 * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)74 * in an emulated bitset.75 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream76 * Bit 32 is a bool and defines whether the variables are stored in diff mode77 * Byte 5 to 8: objectID_78 * Byte 9 to 12: classID_79 * Byte 13 to 16: creatorID_80 */81 class _NetworkExport SynchronisableHeader{82 friend class SynchronisableHeaderLight;83 private:84 uint8_t* data_;85 public:86 SynchronisableHeader(uint8_t* data)87 { data_ = data; }88 inline static uint32_t getSize()89 { return 14; }90 inline uint16_t getDataSize() const91 { return (*(uint16_t*)data_) & 0x7FFF; } //only use the first 15 bits92 inline void setDataSize(uint16_t size)93 { *(uint16_t*)(data_) = (size & 0x7FFF) | (*(uint16_t*)(data_) & 0x8000 ); }94 inline bool isDiffed() const95 { return ( (*(uint16_t*)data_) & 0x8000 ) == 0x8000; }96 inline void setDiffed( bool b)97 { *(uint16_t*)(data_) = (b << 15) | (*(uint16_t*)(data_) & 0x7FFF ); }98 inline uint32_t getObjectID() const99 { return *(uint32_t*)(data_+2); }100 inline void setObjectID(uint32_t objectID_)101 { *(uint32_t*)(data_+2) = objectID_; }102 inline uint32_t getClassID() const103 { return *(uint32_t*)(data_+6); }104 inline void setClassID(uint32_t classID_)105 { *(uint32_t*)(data_+6) = classID_; }106 inline uint32_t getCreatorID() const107 { return *(uint32_t*)(data_+10); }108 inline void setCreatorID(uint32_t creatorID_)109 { *(uint32_t*)(data_+10) = creatorID_; }110 inline void operator=(SynchronisableHeader& h)111 { memcpy(data_, h.data_, getSize()); }112 };113 67 114 68 /** … … 121 75 * Byte 5 to 8: objectID_ 122 76 */ 123 class _NetworkExport SynchronisableHeaderLight{ 124 private: 77 class _NetworkExport SynchronisableHeaderLight 78 { 79 protected: 125 80 uint8_t* data_; 126 81 public: … … 141 96 inline void setObjectID(uint32_t objectID_) 142 97 { *(uint32_t*)(data_+2) = objectID_; } 98 inline void operator=(SynchronisableHeaderLight& h) 99 { memcpy(data_, h.data_, SynchronisableHeaderLight::getSize()); } 100 }; 101 102 typedef uint8_t VariableID; 103 104 /** 105 * @brief: stores information about a Synchronisable 106 * 107 * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize) 108 * in an emulated bitset. 109 * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream 110 * Bit 32 is a bool and defines whether the variables are stored in diff mode 111 * Byte 5 to 8: objectID_ 112 * Byte 9 to 12: classID_ 113 * Byte 13 to 16: creatorID_ 114 */ 115 class _NetworkExport SynchronisableHeader: public SynchronisableHeaderLight 116 { 117 public: 118 SynchronisableHeader(uint8_t* data): SynchronisableHeaderLight(data) 119 {} 120 inline static uint32_t getSize() 121 { return SynchronisableHeaderLight::getSize()+8; } 122 inline uint32_t getClassID() const 123 { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()); } 124 inline void setClassID(uint32_t classID_) 125 { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()) = classID_; } 126 inline uint32_t getCreatorID() const 127 { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4); } 128 inline void setCreatorID(uint32_t creatorID_) 129 { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4) = creatorID_; } 143 130 inline void operator=(SynchronisableHeader& h) 144 131 { memcpy(data_, h.data_, getSize()); } 145 132 }; 133 134 // inline void operator=(SynchronisableHeaderLight& h1, SynchronisableHeader& h2) 135 // { 136 // memcpy(h1.data_, h2.data_, h1.getSize()); 137 // } 146 138 147 139 /**
Note: See TracChangeset
for help on using the changeset viewer.