Changeset 1008 for code/branches/network/src/network/GameStateManager.cc
- Timestamp:
- Apr 10, 2008, 12:55:35 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/network/src/network/GameStateManager.cc
r1007 r1008 93 93 94 94 GameStateCompressed *GameStateManager::popGameState(int clientID) { 95 //why are we searching the same client's gamestate id as we searched in 96 //Server::sendGameState? 95 97 int gID = head_->findClient(clientID)->getGamestateID(); 96 COUT(4) << "popgamestate: sending gstate id: " << id << "diffed from: " << gID << std::endl; 97 if(gID!=GAMESTATEID_INITIAL){ 98 COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id << " diffed from: " << gID << " (not diffed yet)" << std::endl; 99 100 //chose wheather the next gamestate is the first or not 101 if(gID != GAMESTATEID_INITIAL){ 98 102 GameState *client = gameStateMap[gID]; 99 103 GameState *server = reference; … … 115 119 GameState *GameStateManager::getSnapshot(int id) 116 120 { 121 //std::cout << "begin getSnapshot" << std::endl; 117 122 //the size of the gamestate 118 123 int totalsize=0; … … 127 132 GameState *retval=new GameState; //return value 128 133 retval->id=id++; 129 COUT(4) << " producing gamestate with id: " << retval->id << std::endl;134 COUT(4) << "G.ST.Man: producing gamestate with id: " << retval->id << std::endl; 130 135 // reserve a little memory and increase it later on 131 COUT(5) << " mallocing"<< std::endl;136 COUT(5) << "G.ST.Man: mallocing: " << memsize << std::endl; 132 137 retval->data = (unsigned char*)malloc(memsize); 133 COUT(5) << " malloced"<< std::endl;138 COUT(5) << "G.ST.Man: malloced: " << memsize << std::endl; 134 139 135 140 // offset of memory functions … … 137 142 // go through all Synchronisables 138 143 for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){ 144 //std::cout << "begin inner loop" << std::endl; 139 145 //std::cout << "gamestatemanager: in for loop" << std::endl; 140 146 //get size of the synchronisable 141 147 tempsize=it->getSize(); 142 //COUT(5) << "size of temp gamestate: " << tempsize << std::endl;148 //COUT(5) << "size of temp gamestate: " << tempsize << std::endl; 143 149 //COUT(2) << "size of synchronisable: " << tempsize << std::endl; 144 150 // add place for data and 3 ints (length,classid,objectid) 145 151 totalsize+=tempsize+3*sizeof(int); 146 152 //std::cout << "totalsize: " << totalsize << std::endl; 153 //COUT(5) << "G.St.Man: current totalsize=" << totalsize << std::endl; 154 //COUT(5) << "G.St.Man: current it->classID=" << it->classID << " it->objectID=" << it->objectID << std::endl; 147 155 // allocate additional space 148 if(totalsize+tempsize>memsize){ 149 if(tempsize<1000){ 156 if((totalsize+tempsize) > memsize){ 157 COUT(5) << "G.St.Man: need additional memory" << std::endl; 158 if(tempsize < 1000){ 150 159 retval->data = (unsigned char *)realloc((void *)retval->data, totalsize+1000); 151 160 memsize+=1000; … … 154 163 memsize+=tempsize+1000; 155 164 } 165 COUT(5) << "G.St.Man: additional space allocation finished" << std::endl; 156 166 } 157 167 … … 166 176 // increase data pointer 167 177 offset+=tempsize+3*sizeof(int); 168 }169 COUT(5) << "Gamestate size: " << totalsize << std::endl;178 //std::cout << "end inner loop" << std::endl; 179 } 170 180 retval->size=totalsize; 171 181 //#### bugfix 172 182 retval->diffed = false; 183 //std::cout << "end snapShot" << std::endl; 184 COUT(5) << "G.ST.Man: Gamestate size: " << totalsize << std::endl; 173 185 return retval; 174 186 } … … 185 197 186 198 GameStateCompressed *GameStateManager::encode(GameState *a, GameState *b) { 199 COUT(5) << "G.St.Man: this will be a DIFFED gamestate" << std::endl; 187 200 //GameState r = diff(a,b); 188 201 //r.diffed = true; … … 193 206 194 207 GameStateCompressed *GameStateManager::encode(GameState *a) { 208 COUT(5) << "G.St.Man: this will be a not diffed gamestate" << std::endl; 195 209 a->diffed=false; 196 210 return compress_(a); … … 235 249 236 250 GameStateCompressed *GameStateManager::compress_(GameState *a) { 237 COUT(5) << " compressing gamestate" << std::endl;251 COUT(5) << "G.St.Man: compressing gamestate" << std::endl; 238 252 int size = a->size; 239 253 uLongf buffer = (uLongf)((a->size + 12)*1.01)+1; … … 245 259 246 260 switch ( retval ) { 247 case Z_OK: COUT(5) << " successfully compressed" << std::endl; break;248 case Z_MEM_ERROR: COUT(1) << " not enough memory available in gamestate.compress" << std::endl;261 case Z_OK: COUT(5) << "G.St.Man: compress: successfully compressed" << std::endl; break; 262 case Z_MEM_ERROR: COUT(1) << "G.St.Man: compress: not enough memory available in gamestate.compress" << std::endl; 249 263 return NULL; 250 case Z_BUF_ERROR: COUT(2) << " not enough memory available in the buffer in gamestate.compress" << std::endl;264 case Z_BUF_ERROR: COUT(2) << "G.St.Man: compress: not enough memory available in the buffer in gamestate.compress" << std::endl; 251 265 return NULL; 252 case Z_DATA_ERROR: COUT(2) << " decompress: data corrupted in gamestate.compress" << std::endl;266 case Z_DATA_ERROR: COUT(2) << "G.St.Man: compress: data corrupted in gamestate.compress" << std::endl; 253 267 return NULL; 254 268 } … … 263 277 compressedGamestate->diffed = a->diffed; 264 278 compressedGamestate->base_id = a->base_id; 265 279 COUT(5) << "G.St.Man: saved compressed data in GameStateCompressed" << std::endl; 266 280 return compressedGamestate; 267 281 }
Note: See TracChangeset
for help on using the changeset viewer.