Changeset 7801 for code/trunk/src/libraries/network/packet/Gamestate.h
- Timestamp:
- Dec 22, 2010, 7:24:24 PM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/packet/Gamestate.h
r7163 r7801 42 42 #include "Packet.h" 43 43 44 namespace orxonox { 44 namespace orxonox 45 { 45 46 46 namespace packet { 47 namespace packet 48 { 49 50 static const uint8_t GAMESTATE_MODE_SERVER = 0x1; 51 static const uint8_t GAMESTATE_MODE_CLIENT = 0x2; 47 52 48 class _NetworkExport GamestateHeader{ 53 class _NetworkExport GamestateHeader 54 { 49 55 public: 50 GamestateHeader(uint8_t *data){ assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; } 51 GamestateHeader(uint8_t *data, GamestateHeader* h) 52 { assert(data); data_=data; memcpy(data_, h->data_, getSize()); } 56 GamestateHeader(){ data_=0; } 57 GamestateHeader(uint8_t* data) 58 { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; } 59 /*GamestateHeader(uint8_t* data, GamestateHeader* h) 60 { assert(data); data_=data; memcpy(data_, h->data_, getSize()); }*/ 61 void setData(uint8_t* data) 62 { assert(data); data_ = data; *(uint32_t*)data_ = Type::Gamestate; } 53 63 static inline uint32_t getSize() 54 { return 21; }64 { return 21; } 55 65 56 inline int32_t getID() const57 { assert(data_); return *(int32_t*)(data_+4); }58 inline void setID( int32_t id)59 { assert(data_); *(int32_t*)(data_+4) = id; }66 inline uint32_t getID() const 67 { assert(data_); return *(uint32_t*)(data_+4); } 68 inline void setID(uint32_t id) 69 { assert(data_); *(uint32_t*)(data_+4) = id; } 60 70 61 inline int32_t getBaseID() const62 { assert(data_); return *(int32_t*)(data_+8); }63 inline void setBaseID( int32_t id)64 { assert(data_); *(int32_t*)(data_+8) = id; }71 inline uint32_t getBaseID() const 72 { assert(data_); return *(uint32_t*)(data_+8); } 73 inline void setBaseID(uint32_t id) 74 { assert(data_); *(uint32_t*)(data_+8) = id; } 65 75 66 76 inline uint32_t getDataSize() const 67 { assert(data_); return *(uint32_t*)(data_+12); }77 { assert(data_); return *(uint32_t*)(data_+12); } 68 78 inline void setDataSize(uint32_t size) 69 { assert(data_); *(uint32_t*)(data_+12) = size; }79 { assert(data_); *(uint32_t*)(data_+12) = size; } 70 80 71 81 inline uint32_t getCompSize() const … … 75 85 76 86 inline bool isDiffed() const 77 { assert(data_); return *(int8_t*)(data_+20) & 0x1; }87 { assert(data_); return *(int8_t*)(data_+20) & 0x1; } 78 88 inline void setDiffed(bool b) 79 { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); }89 { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); } 80 90 81 91 inline bool isComplete() const 82 { assert(data_); return *(int8_t*)(data_+20) & 0x2; }92 { assert(data_); return *(int8_t*)(data_+20) & 0x2; } 83 93 inline void setComplete(bool b) 84 { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); }94 { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); } 85 95 86 96 inline bool isCompressed() const 87 { assert(data_); return *(int8_t*)(data_+20) & 0x4; }97 { assert(data_); return *(int8_t*)(data_+20) & 0x4; } 88 98 inline void setCompressed(bool b) 89 { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); }99 { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); } 90 100 91 101 inline void operator=(GamestateHeader& h) 92 { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); }102 { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); } 93 103 private: 94 uint8_t *data_;104 uint8_t* data_; 95 105 96 106 }; … … 99 109 @author Oliver Scheuss 100 110 */ 101 class _NetworkExport Gamestate: public Packet{ 111 class _NetworkExport Gamestate: public Packet 112 { 102 113 public: 103 114 Gamestate(); … … 110 121 bool collectData(int id, uint8_t mode=0x0); 111 122 bool spreadData( uint8_t mode=0x0); 112 inline int32_t getID() const { return header_->getID(); }113 inline bool isDiffed() const { return header_ ->isDiffed(); }114 inline bool isCompressed() const { return header_ ->isCompressed(); }115 inline int32_t getBaseID() const { return header_ ->getBaseID(); }116 inline uint32_t getDataSize() const { return header_ ->getDataSize(); }123 inline uint32_t getID() const { return header_.getID(); } 124 inline bool isDiffed() const { return header_.isDiffed(); } 125 inline bool isCompressed() const { return header_.isCompressed(); } 126 inline int32_t getBaseID() const { return header_.getBaseID(); } 127 inline uint32_t getDataSize() const { return header_.getDataSize(); } 117 128 Gamestate* diffVariables(Gamestate *base); 118 Gamestate* diffData(Gamestate *base);119 Gamestate *undiff(Gamestate *base);120 Gamestate* doSelection(unsigned int clientID, unsigned int targetSize);129 // Gamestate* diffData(Gamestate *base); 130 // Gamestate *undiff(Gamestate *base); 131 // Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); 121 132 bool compressData(); 122 133 bool decompressData(); … … 125 136 // Packet functions 126 137 private: 127 void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength);128 inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 );138 // void rawDiff( uint8_t* newdata, uint8_t* data, uint8_t* basedata, uint32_t datalength, uint32_t baselength); 139 // inline uint32_t findObject( const SynchronisableHeader& header, uint8_t* mem, uint32_t dataLength, uint32_t startPosition = 0 ); 129 140 virtual uint32_t getSize() const; 130 virtual inline bool process(); 131 uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0); 141 virtual bool process(orxonox::Host* host); 142 uint32_t calcGamestateSize(uint32_t id, uint8_t mode=0x0); 143 // inline void diffObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); 144 // inline void copyObject( uint8_t*& newData, uint8_t*& origData, uint8_t*& baseData, SynchronisableHeader& objectHeader, std::vector<uint32_t>::iterator& sizes ); 132 145 133 146 std::list<obj> dataVector_; 134 GamestateHeader *header_;147 GamestateHeader header_; 135 148 std::vector<uint32_t> sizes_; 136 149 uint32_t nrOfVariables_;
Note: See TracChangeset
for help on using the changeset viewer.