Changeset 1741
- Timestamp:
- Sep 8, 2008, 11:09:28 AM (16 years ago)
- Location:
- code/branches/network/src/network
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/GamestateClient.cc
r1739 r1741 157 157 158 158 packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){ 159 if(gs->isCompressed()) 160 assert(gs->decompressData()); 159 if(gs->isCompressed()){ 160 bool b = gs->decompressData(); 161 assert(b); 162 } 161 163 if(gs->isDiffed()){ 162 164 packet::Gamestate *base = gamestateMap_[gs->getBaseID()]; -
code/branches/network/src/network/GamestateManager.cc
r1739 r1741 129 129 //why are we searching the same client's gamestate id as we searched in 130 130 //Server::sendGameState? 131 packet::Gamestate *gs; 131 132 int gID = ClientInformation::findClient(clientID)->getGamestateID(); 132 133 COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id_ << " diffed from: " << gID << std::endl; … … 134 135 //chose wheather the next gamestate is the first or not 135 136 if(gID != GAMESTATEID_INITIAL){ 136 // TODO something with the gamestatemap is wrong137 137 packet::Gamestate *client=NULL; 138 138 std::map<int, packet::Gamestate*>::iterator it = gamestateMap.find(gID); 139 139 if(it!=gamestateMap.end()) 140 140 client = it->second; 141 packet::Gamestate *gs;142 141 if(client) 143 142 gs = reference->diff(client); 144 143 else 145 144 gs = new packet::Gamestate(*reference); 146 gs->compressData();147 return gs;148 145 } else { 149 146 COUT(4) << "we got a GAMESTATEID_INITIAL for clientID: " << clientID << std::endl; 150 // ackGameState(clientID, reference->id); 151 return new packet::Gamestate(*reference); 152 // return an undiffed gamestate and set appropriate flags 153 } 147 gs = new packet::Gamestate(*reference); 148 } 149 #ifndef NDEBUG 150 packet::Gamestate *ns = new packet::Gamestate(*gs); 151 ns->compressData(); 152 ns->decompressData(); 153 assert(*gs==*ns); 154 delete ns; 155 #endif 156 assert(gs->compressData()); 157 return gs; 154 158 } 155 159 -
code/branches/network/src/network/Synchronisable.cc
r1735 r1741 98 98 if(!id){ 99 99 COUT(3) << "We could not identify a new object; classid: " << classID << " uint: " << (unsigned int)classID << " objectID: " << objectID << " size: " << size << std::endl; 100 assert(0); 100 101 return false; // most probably the gamestate is corrupted 101 102 } … … 224 225 // end copy header 225 226 226 227 227 COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl; 228 228 // copy to location -
code/branches/network/src/network/packet/Gamestate.cc
r1739 r1741 41 41 42 42 43 #define GAMESTATE_START(data) data + sizeof(GamestateHeader)43 #define GAMESTATE_START(data) (data + sizeof(GamestateHeader)) 44 44 #define GAMESTATE_HEADER(data) ((GamestateHeader *)data) 45 45 #define HEADER GAMESTATE_HEADER(data_) … … 176 176 } 177 177 178 bool Gamestate::operator==(packet::Gamestate gs){ 179 unsigned char *d1 = data_+sizeof(GamestateHeader); 180 unsigned char *d2 = gs.data_+sizeof(GamestateHeader); 181 assert(!isCompressed()); 182 assert(!gs.isCompressed()); 183 while(d1<data_+HEADER->normsize) 184 { 185 if(*d1!=*d2) 186 return false; 187 d1++; 188 d2++; 189 } 190 return true; 191 } 192 178 193 bool Gamestate::process() 179 194 { … … 184 199 { 185 200 assert(HEADER); 186 uLongf buffer = (uLongf)(( HEADER->normsize + 12)*1.01)+1;201 uLongf buffer = (uLongf)(((HEADER->normsize + 12)*1.01)+1); 187 202 if(buffer==0) 188 203 return false; … … 190 205 unsigned char *ndata = new unsigned char[buffer+sizeof(GamestateHeader)]; 191 206 unsigned char *dest = GAMESTATE_START(ndata); 207 //unsigned char *dest = new unsigned char[buffer]; 208 unsigned char *source = GAMESTATE_START(data_); 192 209 int retval; 193 retval = compress( dest, &buffer, GAMESTATE_START(data_), (uLong)(HEADER->normsize) );210 retval = compress( dest, &buffer, source, (uLong)(HEADER->normsize) ); 194 211 switch ( retval ) { 195 212 case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break; 196 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 197 return false; 198 case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; 199 return false; 200 case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl; 201 return false; 202 } 213 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; return false; 214 case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; return false; 215 case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl; return false; 216 } 217 #ifndef NDEBUG 218 //decompress and compare the start and the decompressed data 219 unsigned char *rdata = new unsigned char[HEADER->normsize+sizeof(GamestateHeader)]; 220 unsigned char *d2 = GAMESTATE_START(rdata); 221 uLongf length2 = HEADER->normsize; 222 uncompress(d2, &length2, dest, buffer); 223 for(unsigned int i=0; i<HEADER->normsize; i++){ 224 assert(*(source+i)==*(d2+i)); 225 } 226 delete[] rdata; 227 #endif 203 228 204 229 //copy and modify header 205 HEADER->compsize = buffer;206 HEADER->compressed = true;207 230 *GAMESTATE_HEADER(ndata) = *HEADER; 208 231 //delete old data … … 210 233 //save new data 211 234 data_ = ndata; 235 HEADER->compsize = buffer; 236 HEADER->compressed = true; 212 237 assert(HEADER->compressed); 213 238 COUT(3) << "gamestate compress normsize: " << HEADER->normsize << " compsize: " << HEADER->compsize << std::endl; … … 217 242 { 218 243 assert(HEADER->compressed); 219 //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl; 220 int normsize = HEADER->normsize; 221 int compsize = HEADER->compsize; 222 int bufsize; 223 if(normsize < compsize) 224 bufsize = compsize; 225 else 226 bufsize = normsize; 227 if(bufsize==0) 228 return NULL; 244 COUT(3) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", normsize: " << HEADER->normsize << ", compsize: " << HEADER->compsize << std::endl; 245 unsigned int normsize = HEADER->normsize; 246 unsigned int compsize = HEADER->compsize; 247 unsigned int bufsize; 248 assert(compsize<=normsize); 249 bufsize = normsize; 250 assert(bufsize!=0); 229 251 unsigned char *ndata = new unsigned char[bufsize + sizeof(GamestateHeader)]; 230 252 unsigned char *dest = ndata + sizeof(GamestateHeader); 253 unsigned char *source = data_ + sizeof(GamestateHeader); 231 254 int retval; 232 uLongf length= normsize;233 retval = uncompress( dest, &length, data_+sizeof(GamestateHeader), (uLong)compsize );255 uLongf length=bufsize; 256 retval = uncompress( dest, &length, source, (uLong)compsize ); 234 257 switch ( retval ) { 235 258 case Z_OK: COUT(5) << "successfully decompressed" << std::endl; break; … … 239 262 } 240 263 241 HEADER->compressed = false;242 264 //copy over the header 243 265 *GAMESTATE_HEADER(ndata) = *HEADER; 244 266 //delete old (compressed data) 245 267 delete[] data_; 246 //set new pointers and create bytestream268 //set new pointers 247 269 data_ = ndata; 248 //bs_ = new Bytestream(getGs(), GAMESTATE_HEADER->normsize); 249 270 HEADER->compressed = false; 271 assert(HEADER->normsize==normsize); 272 assert(HEADER->compsize==compsize); 250 273 return true; 251 274 } … … 279 302 GAMESTATE_HEADER(ndata)->diffed = true; 280 303 GAMESTATE_HEADER(ndata)->base_id = base->getID(); 281 Gamestate *g = new Gamestate(ndata, 0);304 Gamestate *g = new Gamestate(ndata, getClientID()); 282 305 g->flags_=flags_; 283 306 g->packetDirection_ = packetDirection_; 284 g->clientID_ = clientID_;285 307 return g; 286 308 } … … 315 337 *GAMESTATE_HEADER(ndata) = *HEADER; 316 338 GAMESTATE_HEADER(ndata)->diffed = false; 317 Gamestate *g = new Gamestate(ndata, 0);339 Gamestate *g = new Gamestate(ndata, getClientID()); 318 340 g->flags_=flags_; 319 341 g->packetDirection_ = packetDirection_; 320 g->clientID_ = clientID_;321 342 assert(!g->isDiffed()); 322 343 assert(!g->isCompressed()); -
code/branches/network/src/network/packet/Gamestate.h
r1739 r1741 75 75 virtual bool process(); 76 76 77 77 bool operator ==(packet::Gamestate gs); 78 78 private: 79 79 unsigned int calcGamestateSize(int mode=0x0); -
code/branches/network/src/network/packet/Packet.cc
r1739 r1741 113 113 packetMap_[enetPacket_] = this; 114 114 } 115 #ifndef NDEBUG 115 #ifndef NDEBUG 116 116 switch( *(ENUM::Type *)(data_ + _PACKETID) ) 117 117 { … … 123 123 break; 124 124 default: 125 assert(0); // TODO: repair this125 assert(0); //there was some error, if this is the case 126 126 break; 127 127 }
Note: See TracChangeset
for help on using the changeset viewer.