Changeset 1715 for code/branches/network/src
- Timestamp:
- Sep 6, 2008, 3:16:11 PM (16 years ago)
- Location:
- code/branches/network/src/network/packet
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/packet/Gamestate.cc
r1713 r1715 49 49 } 50 50 51 Gamestate::Gamestate(unsigned char *data, bool compressed,int clientID):51 Gamestate::Gamestate(unsigned char *data, int clientID): 52 52 Packet(data, clientID) 53 53 { 54 compressed_ = compressed;55 54 } 56 55 … … 106 105 //start write gamestate header 107 106 HEADER->packetType = ENUM::Gamestate; 108 assert( *(ENUM::Type *) &data_[ 0 ]== ENUM::Gamestate);107 assert( *(ENUM::Type *)(data_) == ENUM::Gamestate); 109 108 HEADER->normsize = currentsize; 110 109 HEADER->id = id; 111 110 HEADER->diffed = false; 112 111 HEADER->complete = true; 113 compressed_=false;112 HEADER->compressed = false; 114 113 //stop write gamestate header 115 114 … … 121 120 bool Gamestate::spreadData(int mode) 122 121 { 123 assert(data_ && ! compressed_&& !HEADER->diffed);122 assert(data_ && !HEADER->compressed && !HEADER->diffed); 124 123 unsigned int size, objectID, classID; 125 124 unsigned char *mem=data_+sizeof(GamestateHeader); … … 167 166 { 168 167 assert(data_); 169 if( compressed_)168 if(HEADER->compressed) 170 169 return HEADER->compsize+sizeof(GamestateHeader); 171 170 else … … 203 202 //copy and modify header 204 203 HEADER->compsize = buffer; 204 HEADER->compressed = true; 205 205 *GAMESTATE_HEADER(ndata) = *HEADER; 206 206 //delete old data … … 208 208 //save new data 209 209 data_ = ndata; 210 compressed_ = true;211 210 return true; 212 211 } 213 212 bool Gamestate::decompressData() 214 213 { 215 assert( compressed_);214 assert(HEADER->compressed); 216 215 //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl; 217 216 int normsize = HEADER->normsize; … … 236 235 } 237 236 238 compressed_= false;237 HEADER->compressed = false; 239 238 //copy over the header 240 239 *GAMESTATE_HEADER(ndata) = *HEADER; … … 273 272 } 274 273 275 Gamestate *g = new Gamestate(ndata, false, 0); 274 *GAMESTATE_HEADER(ndata) = *HEADER; 275 GAMESTATE_HEADER(ndata)->diffed = true; 276 Gamestate *g = new Gamestate(ndata, 0); 276 277 return g; 277 278 } … … 280 281 { 281 282 assert(this && base); 282 assert(! this->compressed_ && !base->compressed_);283 assert(!HEADER->compressed && !GAMESTATE_HEADER(base->data_)->compressed); 283 284 //unsigned char *basep = base->getGs()/*, *gs = getGs()*/; 284 285 unsigned char *basep = GAMESTATE_START(base->data_); … … 304 305 } 305 306 } 306 307 Gamestate *g = new Gamestate(ndata, false, 0); 307 *GAMESTATE_HEADER(ndata) = *HEADER; 308 GAMESTATE_HEADER(ndata)->diffed = false; 309 Gamestate *g = new Gamestate(ndata, 0); 308 310 return g; 309 311 } -
code/branches/network/src/network/packet/Gamestate.h
r1712 r1715 47 47 bool diffed; // wheter diffed or not 48 48 bool complete; // wheter it is a complete gamestate or only partial 49 bool compressed; 49 50 }; 50 51 … … 55 56 public: 56 57 Gamestate(); 57 Gamestate(unsigned char *data, bool compressed,int clientID);58 Gamestate(unsigned char *data, int clientID); 58 59 59 60 ~Gamestate(); … … 81 82 //Bytestream *bs_; 82 83 //GamestateHeader *header_; 83 bool compressed_;84 84 }; 85 85 -
code/branches/network/src/network/packet/Packet.cc
r1713 r1715 111 111 packetMap_[enetPacket_] = this; 112 112 } 113 /*switch( *(ENUM::Type *)(data_ + _PACKETID) ) 114 { 115 case ENUM::Acknowledgement: 116 case ENUM::Chat: 117 case ENUM::ClassID: 118 case ENUM::Gamestate: 119 case ENUM::Welcome: 120 COUT(3) << "welcome" << std::endl; 121 p = new Welcome( data, clientID ); 122 default: 123 assert(0); //TODO: repair this 124 break; 125 }*/ 113 126 network::Host::addPacket( enetPacket_, clientID_); 114 127 enetPacket_ = 0; // otherwise we have a double free because enet already handles the deallocation of the packet … … 121 134 Packet *p; 122 135 COUT(3) << "packet type: " << *(ENUM::Type *)&data[_PACKETID] << std::endl; 123 switch( *(ENUM::Type *) &data[_PACKETID])136 switch( *(ENUM::Type *)(data + _PACKETID) ) 124 137 { 125 138 case ENUM::Acknowledgement: … … 138 151 COUT(3) << "gamestate" << std::endl; 139 152 // TODO: remove brackets 140 p = new Gamestate( data, true,clientID );153 p = new Gamestate( data, clientID ); 141 154 break; 142 155 case ENUM::Welcome: 143 156 COUT(3) << "welcome" << std::endl; 144 157 p = new Welcome( data, clientID ); 158 break; 145 159 default: 146 160 assert(0); //TODO: repair this
Note: See TracChangeset
for help on using the changeset viewer.