Changeset 1740 for code/trunk/src/network/packet
- Timestamp:
- Sep 8, 2008, 2:48:48 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/network/packet/Gamestate.cc
r1735 r1740 39 39 40 40 namespace packet { 41 41 42 42 43 43 #define GAMESTATE_START(data) data + sizeof(GamestateHeader) 44 44 #define GAMESTATE_HEADER(data) ((GamestateHeader *)data) 45 45 #define HEADER GAMESTATE_HEADER(data_) 46 46 47 47 Gamestate::Gamestate() 48 48 { … … 64 64 assert(data_==0 /*&& bs_==0*/); 65 65 int size = calcGamestateSize(mode); 66 66 67 67 COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl; 68 68 //retval->data = (unsigned char*)malloc(size); … … 82 82 for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){ 83 83 tempsize=it->getSize2(mode); 84 84 85 85 if(currentsize+tempsize > size){ 86 86 // start allocate additional memory … … 101 101 currentsize+=tempsize; 102 102 } 103 104 103 104 105 105 //start write gamestate header 106 106 HEADER->packetType = ENUM::Gamestate; 107 assert( *(ENUM::Type *)(data_) == ENUM::Gamestate); 107 assert( *(ENUM::Type *)(data_) == ENUM::Gamestate); 108 108 HEADER->normsize = currentsize; 109 109 HEADER->id = id; … … 112 112 HEADER->compressed = false; 113 113 //stop write gamestate header 114 114 115 115 COUT(5) << "G.ST.Man: Gamestate size: " << currentsize << std::endl; 116 116 COUT(5) << "G.ST.Man: 'estimated' (and corrected) Gamestate size: " << size << std::endl; … … 125 125 // get the start of the Synchronisable list 126 126 orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start(); 127 127 128 128 while(mem < data_+sizeof(GamestateHeader)+HEADER->normsize){ 129 129 // extract synchronisable header … … 144 144 it=orxonox::ObjectList<Synchronisable>::end(); 145 145 } 146 } else 146 } else 147 147 { 148 148 // we have our object … … 185 185 if(buffer==0) 186 186 return false; 187 187 188 188 unsigned char *ndata = new unsigned char[buffer+sizeof(GamestateHeader)]; 189 189 unsigned char *dest = GAMESTATE_START(ndata); … … 192 192 switch ( retval ) { 193 193 case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break; 194 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 194 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 195 195 return false; 196 196 case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; … … 224 224 bufsize = normsize; 225 225 if(bufsize==0) 226 return NULL;226 return false; 227 227 unsigned char *ndata = new unsigned char[bufsize + sizeof(GamestateHeader)]; 228 228 unsigned char *dest = ndata + sizeof(GamestateHeader); … … 236 236 case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return false; 237 237 } 238 238 239 239 HEADER->compressed = false; 240 240 //copy over the header … … 245 245 data_ = ndata; 246 246 //bs_ = new Bytestream(getGs(), GAMESTATE_HEADER->normsize); 247 247 248 248 return true; 249 249 } … … 340 340 return HEADER->diffed; 341 341 } 342 342 343 343 int Gamestate::getBaseID(){ 344 344 return HEADER->base_id;
Note: See TracChangeset
for help on using the changeset viewer.