Changeset 11071 for code/trunk/src/libraries/network/GamestateManager.cc
- Timestamp:
- Jan 17, 2016, 10:29:21 PM (8 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/network/GamestateManager.cc
r8858 r11071 60 60 { 61 61 GamestateManager::GamestateManager() : 62 currentGamestate_( 0), id_(0)62 currentGamestate_(nullptr), id_(0) 63 63 { 64 64 // trafficControl_ = new TrafficControl(); … … 70 70 { 71 71 if( this->currentGamestate_ ) 72 delete this->currentGamestate_;std::map<unsigned int, packet::Gamestate*>::iterator it; 73 for( it = gamestateQueue.begin(); it != gamestateQueue.end(); ++it ) 74 delete it->second; 75 std::map<uint32_t, peerInfo>::iterator peerIt; 76 std::map<uint32_t, packet::Gamestate*>::iterator gamestateIt; 77 for( peerIt = peerMap_.begin(); peerIt != peerMap_.end(); ++peerIt ) 78 { 79 for( gamestateIt = peerIt->second.gamestates.begin(); gamestateIt != peerIt->second.gamestates.end(); ++gamestateIt ) 80 delete gamestateIt->second; 72 delete this->currentGamestate_; 73 for( const auto& mapEntry : gamestateQueue ) 74 delete mapEntry.second; 75 for( const auto& mapEntryPeer : peerMap_ ) 76 { 77 for( const auto& mapEntryGamestate : mapEntryPeer.second.gamestates ) 78 delete mapEntryGamestate.second; 81 79 } 82 80 // this->trafficControl_->destroy(); … … 107 105 if( this->gamestateQueue.empty() ) 108 106 return true; 109 std::map<unsigned int, packet::Gamestate*>::iterator it;110 107 // now push only the most recent gamestates we received (ignore obsolete ones) 111 for( it = gamestateQueue.begin(); it!=gamestateQueue.end(); it++)112 { 113 OrxVerify(processGamestate( it->second), "ERROR: could not process Gamestate");114 sendAck( it->second->getID(), it->second->getPeerID() );115 delete it->second;108 for(const auto& mapEntry : gamestateQueue) 109 { 110 OrxVerify(processGamestate(mapEntry.second), "ERROR: could not process Gamestate"); 111 sendAck( mapEntry.second->getID(), mapEntry.second->getPeerID() ); 112 delete mapEntry.second; 116 113 } 117 114 // now clear the queue … … 140 137 141 138 bool GamestateManager::getSnapshot(){ 142 if ( currentGamestate_ != 0)139 if ( currentGamestate_ != nullptr ) 143 140 delete currentGamestate_; 144 141 uint8_t gsMode; … … 165 162 { //we have no data to send 166 163 delete currentGamestate_; 167 currentGamestate_= 0;164 currentGamestate_=nullptr; 168 165 return false; 169 166 } … … 177 174 std::vector<packet::Gamestate*> peerGamestates; 178 175 179 std::map<uint32_t, peerInfo>::iterator peerIt; 180 for( peerIt=peerMap_.begin(); peerIt!=peerMap_.end(); ++peerIt ) 181 { 182 if( !peerIt->second.isSynched ) 176 for( const auto& mapEntry : peerMap_ ) 177 { 178 if( !mapEntry.second.isSynched ) 183 179 { 184 180 orxout(verbose_more, context::network) << "Server: not sending gamestate" << endl; 185 181 continue; 186 182 } 187 orxout(verbose_more, context::network) << "client id: " << peerIt->first << endl;183 orxout(verbose_more, context::network) << "client id: " << mapEntry.first << endl; 188 184 orxout(verbose_more, context::network) << "Server: doing gamestate gamestate preparation" << endl; 189 int peerID = peerIt->first; //get client id190 191 unsigned int lastAckedGamestateID = peerIt->second.lastAckedGamestateID;192 193 packet::Gamestate* baseGamestate= 0;185 int peerID = mapEntry.first; //get client id 186 187 unsigned int lastAckedGamestateID = mapEntry.second.lastAckedGamestateID; 188 189 packet::Gamestate* baseGamestate=nullptr; 194 190 if(lastAckedGamestateID != GAMESTATEID_INITIAL) 195 191 { … … 200 196 } 201 197 202 peerGamestates.push_back( 0); // insert an empty gamestate* to be changed198 peerGamestates.push_back(nullptr); // insert an empty gamestate* to be changed 203 199 finishGamestate( peerID, peerGamestates.back(), baseGamestate, currentGamestate_ ); 204 if( peerGamestates.back()== 0)200 if( peerGamestates.back()==nullptr ) 205 201 // nothing to send to remove pointer from vector 206 202 peerGamestates.pop_back(); … … 243 239 { 244 240 delete diffed1; 245 destgamestate = 0;241 destgamestate = nullptr; 246 242 return; 247 243 } … … 340 336 { 341 337 assert(peerMap_.find(peerID)!=peerMap_.end()); 342 std::map<uint32_t, packet::Gamestate*>::iterator peerIt; 343 for( peerIt = peerMap_[peerID].gamestates.begin(); peerIt!=peerMap_[peerID].gamestates.end(); ++peerIt ) 344 { 345 delete peerIt->second; 338 for( const auto& mapEntry : peerMap_[peerID].gamestates ) 339 { 340 delete mapEntry.second; 346 341 } 347 342 peerMap_.erase(peerMap_.find(peerID)); … … 351 346 // void GamestateManager::removeClient(ClientInformation* client){ 352 347 // assert(client); 353 // std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> 348 // std::map<unsigned int, std::map<unsigned int, packet::Gamestate*>>::iterator clientMap = gamestateMap_.find(client->getID()); 354 349 // // first delete all remained gamestates 355 350 // std::map<unsigned int, packet::Gamestate*>::iterator it;
Note: See TracChangeset
for help on using the changeset viewer.