Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2008, 7:04:09 PM (16 years ago)
Author:
landauf
Message:

merged objecthierarchy branch back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/network/GamestateManager.cc

    r1907 r2087  
    6464    return getSnapshot();
    6565  }
    66  
    67   bool GamestateManager::add(packet::Gamestate *gs, int clientID){
     66
     67  bool GamestateManager::add(packet::Gamestate *gs, unsigned int clientID){
    6868    assert(gs);
    69     std::map<int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID);
     69    std::map<unsigned int, packet::Gamestate*>::iterator it = gamestateQueue.find(clientID);
    7070    if(it!=gamestateQueue.end()){
    7171      // delete obsolete gamestate
     
    7575    return true;
    7676  }
    77  
     77
    7878  bool GamestateManager::processGamestates(){
    79     std::map<int, packet::Gamestate*>::iterator it;
     79    std::map<unsigned int, packet::Gamestate*>::iterator it;
    8080    // now push only the most recent gamestates we received (ignore obsolete ones)
    8181    for(it = gamestateQueue.begin(); it!=gamestateQueue.end(); it++){
    82       assert(processGamestate(it->second));
     82      bool b = processGamestate(it->second);
     83      assert(b);
    8384      delete it->second;
    8485    }
     
    8788    return true;
    8889  }
    89  
    90  
     90
     91
    9192  bool GamestateManager::getSnapshot(){
    9293    reference = new packet::Gamestate();
    93     reference->collectData(++id_);
    94     //COUT(4) << "inserting gamestate: " << reference << std::endl;
    95     //gamestateMap_.insert(std::pair<int, packet::Gamestate*>(id_, reference));
    96 //     gamestateUsed[id_]=0;
    97     return true;
    98   }
    99  
     94    if(!reference->collectData(++id_)){ //we have no data to send
     95      delete reference;
     96      reference=0;
     97    }
     98    return true;
     99  }
     100
    100101  /**
    101102   * this function is used to keep the memory usage low
    102103   * it tries to delete all the unused gamestates
    103    * 
    104    * 
     104   *
     105   *
    105106   */
    106107/*  void GamestateManager::cleanup(){
     
    126127  }*/
    127128
    128   packet::Gamestate *GamestateManager::popGameState(int clientID) {
     129  packet::Gamestate *GamestateManager::popGameState(unsigned int clientID) {
    129130    //why are we searching the same client's gamestate id as we searched in
    130131    //Server::sendGameState?
    131132    packet::Gamestate *gs;
    132     int gID = ClientInformation::findClient(clientID)->getGamestateID();
     133    unsigned int gID = ClientInformation::findClient(clientID)->getGamestateID();
     134    if(!reference)
     135      return 0;
    133136    gs = reference->doSelection(clientID);
    134137//     gs = new packet::Gamestate(*reference);
     
    139142    packet::Gamestate *client=NULL;
    140143    if(gID != GAMESTATEID_INITIAL){
    141       std::map<unsigned int, std::map<int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(clientID);
     144      std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(clientID);
    142145      if(clientMap!=gamestateMap_.end()){
    143         std::map<int, packet::Gamestate*>::iterator it = clientMap->second.find(gID);
     146        std::map<unsigned int, packet::Gamestate*>::iterator it = clientMap->second.find(gID);
    144147        if(it!=clientMap->second.end())
    145148          client = it->second;
     
    158161    return gs;
    159162  }
    160  
    161  
    162   bool GamestateManager::ack(int gamestateID, int clientID) {
     163
     164
     165  bool GamestateManager::ack(unsigned int gamestateID, unsigned int clientID) {
    163166    ClientInformation *temp = ClientInformation::findClient(clientID);
    164167    assert(temp);
    165     int curid = temp->getGamestateID();
    166    
     168    unsigned int curid = temp->getGamestateID();
     169
    167170    if(gamestateID == 0){
    168171      temp->setGamestateID(GAMESTATEID_INITIAL);
    169172      return true;
    170173    }
    171    
    172     assert(curid<gamestateID);
     174
     175    assert(curid==(unsigned int)GAMESTATEID_INITIAL || curid<gamestateID);
    173176    COUT(4) << "acking gamestate " << gamestateID << " for clientid: " << clientID << " curid: " << curid << std::endl;
    174     std::map<int, packet::Gamestate*>::iterator it, tempit;
     177    std::map<unsigned int, packet::Gamestate*>::iterator it, tempit;
    175178    for(it = gamestateMap_[clientID].begin(); it!=gamestateMap_[clientID].end() && it->first<gamestateID; it++){
    176179      delete it->second;
     
    184187  void GamestateManager::removeClient(ClientInformation* client){
    185188    assert(client);
    186     std::map<unsigned int, std::map<int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
     189    std::map<unsigned int, std::map<unsigned int, packet::Gamestate*> >::iterator clientMap = gamestateMap_.find(client->getID());
    187190    // first delete all remained gamestates
    188     std::map<int, packet::Gamestate*>::iterator it;
     191    std::map<unsigned int, packet::Gamestate*>::iterator it;
    189192    for(it=clientMap->second.begin(); it!=clientMap->second.end(); it++)
    190193      delete it->second;
     
    192195    gamestateMap_.erase(clientMap);
    193196  }
    194  
     197
    195198  bool GamestateManager::processGamestate(packet::Gamestate *gs){
    196199    if(gs->isCompressed())
Note: See TracChangeset for help on using the changeset viewer.