Changeset 2561 for code/branches/presentation/src/network
- Timestamp:
- Jan 1, 2009, 3:48:25 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/presentation/src/network/GamestateManager.cc
r2556 r2561 109 109 } 110 110 111 /**112 * this function is used to keep the memory usage low113 * it tries to delete all the unused gamestates114 *115 *116 */117 /* void GamestateManager::cleanup(){118 std::map<int,int>::iterator it = gamestateUsed.begin();119 while(it!=gamestateUsed.end()){120 if((id_-(*it).first)<KEEP_GAMESTATES)121 break;122 if( (*it).second <= 0 ){123 COUT(5) << "GameStateManager: deleting gamestate with id: " << (*it).first << ", uses: " << (*it).second << std::endl;124 std::map<int, packet::Gamestate *>::iterator tempit = gamestateMap.find((*it).first);125 if( tempit != gamestateMap.end() ){126 packet::Gamestate *temp = tempit->second;127 if(temp){128 delete gamestateMap[(*it).first];129 gamestateMap.erase((*it).first);130 }131 }132 gamestateUsed.erase(it++);133 continue;134 }135 it++;136 }137 }*/138 111 139 112 packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) { 140 113 //why are we searching the same client's gamestate id as we searched in 141 114 //Server::sendGameState? 142 packet::Gamestate *gs , *tempgs;115 packet::Gamestate *gs; 143 116 unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID(); 144 117 if(!reference) … … 147 120 // gs = new packet::Gamestate(*reference); 148 121 // save the (undiffed) gamestate in the clients gamestate map 149 gamestateMap_[clientID] .insert(std::pair<int, packet::Gamestate*>(gs->getID(), gs));122 gamestateMap_[clientID][gs->getID()]=gs; 150 123 //chose wheather the next gamestate is the first or not 151 packet::Gamestate *client= NULL;124 packet::Gamestate *client=0; 152 125 if(gID != GAMESTATEID_INITIAL){ 153 std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(clientID);154 if(clientMap!=gamestateMap_.end()){155 std::map<unsigned int, packet::Gamestate*>::iterator it = clientMap->second.find(gID);156 if(it!=clientMap->second.end())157 126 assert(gamestateMap_.find(clientID)!=gamestateMap_.end()); 127 std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateMap_[clientID].find(gID); 128 if(it!=gamestateMap_[clientID].end()) 129 { 130 client = it->second; 158 131 } 159 132 } 160 133 if(client){ 161 134 // COUT(3) << "diffing" << std::endl; 162 tempgs = gs->diff(client); 163 delete gs; 164 gs = tempgs; 135 gs = gs->diff(client); 165 136 } 166 137 else{ 167 138 // COUT(3) << "not diffing" << std::endl; 168 // gs = new packet::Gamestate(*gs); //not necessary 139 gs = new packet::Gamestate(*gs); 169 140 } 170 141 bool b = gs->compressData(); … … 181 152 if(gamestateID == ACKID_NACK){ 182 153 temp->setGamestateID(GAMESTATEID_INITIAL); 154 // now delete all saved gamestates for this client 155 std::map<unsigned int, packet::Gamestate*>::iterator it; 156 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end(); ){ 157 delete it->second; 158 gamestateMap_[clientID].erase(it++); 159 } 183 160 return true; 184 161 } … … 186 163 assert(curid==(unsigned int)GAMESTATEID_INITIAL || curid<gamestateID); 187 164 COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl; 188 std::map<unsigned int, packet::Gamestate*>::iterator it , tempit;189 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; it++){165 std::map<unsigned int, packet::Gamestate*>::iterator it; 166 for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; ){ 190 167 delete it->second; 191 tempit=it++; 192 gamestateMap_[clientID].erase(tempit); 168 gamestateMap_[clientID].erase(it++); 193 169 } 194 170 temp->setGamestateID(gamestateID);
Note: See TracChangeset
for help on using the changeset viewer.