Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jan 1, 2009, 3:48:25 PM (16 years ago)
Author:
scheusso
Message:

reverted some changes (assumed memory leaks)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation/src/network/GamestateManager.cc

    r2556 r2561  
    109109  }
    110110
    111   /**
    112    * this function is used to keep the memory usage low
    113    * it tries to delete all the unused gamestates
    114    *
    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   }*/
    138111
    139112  packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) {
    140113    //why are we searching the same client's gamestate id as we searched in
    141114    //Server::sendGameState?
    142     packet::Gamestate *gs, *tempgs;
     115    packet::Gamestate *gs;
    143116    unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID();
    144117    if(!reference)
     
    147120//     gs = new packet::Gamestate(*reference);
    148121    // 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;
    150123    //chose wheather the next gamestate is the first or not
    151     packet::Gamestate *client=NULL;
     124    packet::Gamestate *client=0;
    152125    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           client = it->second;
     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;
    158131      }
    159132    }
    160133    if(client){
    161134//       COUT(3) << "diffing" << std::endl;
    162       tempgs = gs->diff(client);
    163       delete gs;
    164       gs = tempgs;
     135      gs = gs->diff(client);
    165136    }
    166137    else{
    167138//       COUT(3) << "not diffing" << std::endl;
    168 //       gs = new packet::Gamestate(*gs); //not necessary
     139      gs = new packet::Gamestate(*gs);
    169140    }
    170141    bool b = gs->compressData();
     
    181152    if(gamestateID == ACKID_NACK){
    182153      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      }
    183160      return true;
    184161    }
     
    186163    assert(curid==(unsigned int)GAMESTATEID_INITIAL || curid<gamestateID);
    187164    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; ){
    190167      delete it->second;
    191       tempit=it++;
    192       gamestateMap_[clientID].erase(tempit);
     168      gamestateMap_[clientID].erase(it++);
    193169    }
    194170    temp->setGamestateID(gamestateID);
Note: See TracChangeset for help on using the changeset viewer.