Changeset 2662 for code/trunk/src/network/packet/Gamestate.h
- Timestamp:
- Feb 14, 2009, 10:17:35 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/network/packet/Gamestate.h
r2171 r2662 31 31 #define NETWORK_PACKETGAMESTATE_H 32 32 33 #include " ../NetworkPrereqs.h"33 #include "network/NetworkPrereqs.h" 34 34 35 35 #include "Packet.h" 36 #include "network/Synchronisable.h" 36 #include "network/TrafficControl.h" 37 #include "core/CoreIncludes.h" 37 38 #include <map> 39 #include <list> 38 40 #ifndef NDEBUG 39 41 #include "util/CRC32.h" … … 44 46 namespace packet { 45 47 46 struct _NetworkExport GamestateHeader{ 47 ENUM::Type packetType; 48 int32_t id; // id of the gamestate 49 uint32_t compsize; 50 uint32_t datasize; 51 int32_t base_id; // id of the base-gamestate diffed from 52 bool diffed:1; // wheter diffed or not 53 bool complete:1; // wheter it is a complete gamestate or only partial 54 bool compressed:1; 55 #ifndef NDEBUG 56 uint32_t crc32; 57 #endif 48 class _NetworkExport GamestateHeader{ 49 public: 50 GamestateHeader(uint8_t *data){ assert(data); data_ = data; *(uint32_t*)data_ = ENUM::Gamestate; } 51 GamestateHeader(uint8_t *data, GamestateHeader* h) 52 { assert(data); data_=data; memcpy(data_, h->data_, getSize()); } 53 static inline uint32_t getSize() 54 { return 21; } 55 56 inline int32_t getID() const 57 { assert(data_); return *(int32_t*)(data_+4); } 58 inline void setID(int32_t id) 59 { assert(data_); *(int32_t*)(data_+4) = id; } 60 61 inline int32_t getBaseID() const 62 { assert(data_); return *(int32_t*)(data_+8); } 63 inline void setBaseID(int32_t id) 64 { assert(data_); *(int32_t*)(data_+8) = id; } 65 66 inline uint32_t getDataSize() const 67 { assert(data_); return *(uint32_t*)(data_+12); } 68 inline void setDataSize(uint32_t size) 69 { assert(data_); *(uint32_t*)(data_+12) = size; } 70 71 inline uint32_t getCompSize() const 72 { assert(data_); return *(uint32_t*)(data_+16); } 73 inline void setCompSize(uint32_t size) 74 { assert(data_); *(uint32_t*)(data_+16) = size; } 75 76 inline bool isDiffed() const 77 { assert(data_); return *(int8_t*)(data_+20) & 0x1; } 78 inline void setDiffed(bool b) 79 { assert(data_); *(int8_t*)(data_+20) = (b<<0) | (*(int8_t*)(data_+20) & 0x6 ); } 80 81 inline bool isComplete() const 82 { assert(data_); return *(int8_t*)(data_+20) & 0x2; } 83 inline void setComplete(bool b) 84 { assert(data_); *(int8_t*)(data_+20) = (b<<1) | (*(int8_t*)(data_+20) & 0x5 ); } 85 86 inline bool isCompressed() const 87 { assert(data_); return *(int8_t*)(data_+20) & 0x4; } 88 inline void setCompressed(bool b) 89 { assert(data_); *(int8_t*)(data_+20) = (b<<2) | (*(int8_t*)(data_+20) & 0x3 ); } 90 91 inline void operator=(GamestateHeader& h) 92 { assert(data_); assert(h.data_); memcpy( data_, h.data_, getSize()); } 93 private: 94 uint8_t *data_; 95 //#define GAMESTATE_START(data) (data + sizeof(GamestateHeader)) 96 //#define GAMESTATE_HEADER(data) ((GamestateHeader *)data) 97 //#define HEADER GAMESTATE_HEADER(data_) 98 58 99 }; 59 100 … … 66 107 Gamestate(uint8_t *data, unsigned int clientID); 67 108 Gamestate(uint8_t *data); 109 Gamestate(const Gamestate& g); 68 110 69 111 ~Gamestate(); … … 71 113 bool collectData(int id, uint8_t mode=0x0); 72 114 bool spreadData( uint8_t mode=0x0); 73 in t getID();74 bool isDiffed();75 bool isCompressed();76 in t getBaseID();115 inline int32_t getID() const { return header_->getID(); } 116 inline bool isDiffed() const { return header_->isDiffed(); } 117 inline bool isCompressed() const { return header_->isCompressed(); } 118 inline int32_t getBaseID() const { return header_->getBaseID(); } 77 119 Gamestate *diff(Gamestate *base); 78 Gamestate* intelligentDiff(Gamestate *base, unsigned int clientID);79 120 Gamestate *undiff(Gamestate *base); 80 Gamestate* intelligentUnDiff(Gamestate *base); 81 Gamestate* doSelection(unsigned int clientID); 121 Gamestate* doSelection(unsigned int clientID, unsigned int targetSize); 82 122 bool compressData(); 83 123 bool decompressData(); … … 85 125 // Packet functions 86 126 private: 87 virtual u nsigned int getSize() const;88 virtual bool process();127 virtual uint32_t getSize() const; 128 virtual inline bool process(); 89 129 90 130 bool operator ==(packet::Gamestate gs); 91 131 private: 92 u nsigned int calcGamestateSize(unsigned int id, uint8_t mode=0x0);93 void removeObject(ObjectListIterator<Synchronisable> &it);94 std::map<unsigned int, Synchronisable*> dataMap_;132 uint32_t calcGamestateSize(int32_t id, uint8_t mode=0x0); 133 std::list<obj> dataMap_; 134 GamestateHeader* header_; 95 135 }; 96 136
Note: See TracChangeset
for help on using the changeset viewer.