Changeset 8327 for code/trunk/src/libraries/network/GamestateManager.cc
- Timestamp:
- Apr 25, 2011, 8:22:36 PM (13 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/network6 (added) merged: 7823-7825,7875,7878,7881-7882,7898,7900,7931,8315
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/GamestateManager.cc
r7801 r8327 57 57 58 58 namespace orxonox 59 { 59 { 60 60 GamestateManager::GamestateManager() : 61 61 currentGamestate_(0), id_(0) … … 122 122 bool GamestateManager::sendAck(unsigned int gamestateID, uint32_t peerID) 123 123 { 124 assert( gamestateID != ACKID_NACK ); 124 125 packet::Acknowledgement *ack = new packet::Acknowledgement(gamestateID, peerID); 125 126 if( !this->sendPacket(ack)) … … 139 140 if ( currentGamestate_ != 0 ) 140 141 delete currentGamestate_; 141 currentGamestate_ = new packet::Gamestate();142 142 uint8_t gsMode; 143 143 if( GameMode::isMaster() ) … … 149 149 newID = ++id_; 150 150 else 151 newID = peerMap_[NETWORK_PEER_ID_SERVER].lastProcessedGamestateID; 151 { 152 assert(peerMap_.size()!=0); 153 newID = peerMap_[NETWORK_PEER_ID_SERVER].lastReceivedGamestateID; 154 if( newID == GAMESTATEID_INITIAL ) 155 { 156 return false; 157 } 158 } 152 159 153 if(!currentGamestate_->collectData(newID, gsMode)){ //we have no data to send 160 currentGamestate_ = new packet::Gamestate(); 161 162 if(!currentGamestate_->collectData(newID, gsMode)) 163 { //we have no data to send 154 164 delete currentGamestate_; 155 165 currentGamestate_=0; 166 return false; 156 167 } 157 168 return true; … … 172 183 continue; 173 184 } 174 COUT( 4) << "client id: " << peerIt->first << std::endl;185 COUT(5) << "client id: " << peerIt->first << std::endl; 175 186 COUT(5) << "Server: doing gamestate gamestate preparation" << std::endl; 176 187 int peerID = peerIt->first; //get client id … … 187 198 } 188 199 189 peerGamestates.push_back(0); // insert an empty gamestate* to change200 peerGamestates.push_back(0); // insert an empty gamestate* to be changed 190 201 finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ ); 191 202 if( peerGamestates.back()==0 ) … … 244 255 // assert(b); 245 256 clock.capture(); 246 COUT( 4) << "diff and compress time: " << clock.getDeltaTime() << endl;257 COUT(5) << "diff and compress time: " << clock.getDeltaTime() << endl; 247 258 // COUT(5) << "sending gamestate with id " << gs->getID(); 248 259 // if(gamestate->isDiffed()) … … 263 274 unsigned int curid = it->second.lastAckedGamestateID; 264 275 265 if(gamestateID == ACKID_NACK){ 266 it->second.lastAckedGamestateID = GAMESTATEID_INITIAL; 267 // temp->setGamestateID(GAMESTATEID_INITIAL); 268 // now delete all saved gamestates for this client 269 std::map<uint32_t, packet::Gamestate*>::iterator it2; 270 for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){ 271 delete it2->second; 272 } 273 it->second.gamestates.clear(); 274 return true; 275 } 276 277 assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID); 278 COUT(5) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl; 276 assert(gamestateID != ACKID_NACK); 277 // if(gamestateID == ACKID_NACK){ 278 // it->second.lastAckedGamestateID = GAMESTATEID_INITIAL; 279 // // temp->setGamestateID(GAMESTATEID_INITIAL); 280 // // now delete all saved gamestates for this client 281 // std::map<uint32_t, packet::Gamestate*>::iterator it2; 282 // for(it2 = it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ++it2 ){ 283 // delete it2->second; 284 // } 285 // it->second.gamestates.clear(); 286 // return true; 287 // } 288 289 // assert(curid==GAMESTATEID_INITIAL || curid<=gamestateID); // this line is commented out because acknowledgements are unreliable and may arrive in distorted order 290 if( gamestateID <= curid ) 291 return true; 292 COUT(4) << "acking gamestate " << gamestateID << " for peerID: " << peerID << " curid: " << curid << std::endl; 279 293 std::map<uint32_t, packet::Gamestate*>::iterator it2; 280 294 for( it2=it->second.gamestates.begin(); it2!=it->second.gamestates.end(); ) … … 300 314 } 301 315 302 uint32_t GamestateManager::getLast ProcessedGamestateID(unsigned int peerID)316 uint32_t GamestateManager::getLastReceivedGamestateID(unsigned int peerID) 303 317 { 304 318 assert( this->peerMap_.find(peerID)!=this->peerMap_.end() ); 305 319 if( this->peerMap_.find(peerID) != this->peerMap_.end() ) 306 return this->peerMap_[peerID].last ProcessedGamestateID;320 return this->peerMap_[peerID].lastReceivedGamestateID; 307 321 else 308 322 return GAMESTATEID_INITIAL; … … 314 328 assert(peerMap_.find(peerID)==peerMap_.end()); 315 329 peerMap_[peerID].peerID = peerID; 316 peerMap_[peerID].last ProcessedGamestateID = GAMESTATEID_INITIAL;330 peerMap_[peerID].lastReceivedGamestateID = GAMESTATEID_INITIAL; 317 331 peerMap_[peerID].lastAckedGamestateID = GAMESTATEID_INITIAL; 318 332 if( GameMode::isMaster() ) … … 360 374 if( gs->spreadData(gsMode) ) 361 375 { 362 this->peerMap_[gs->getPeerID()].last ProcessedGamestateID = gs->getID();376 this->peerMap_[gs->getPeerID()].lastReceivedGamestateID = gs->getID(); 363 377 return true; 364 378 }
Note: See TracChangeset
for help on using the changeset viewer.