Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1005 for code/branches


Ignore:
Timestamp:
Apr 9, 2008, 8:38:52 PM (17 years ago)
Author:
scheusso
Message:

enhanced memory management in gamestatemanager and gamestateclient

Location:
code/branches/network/src/network
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/src/network/GameStateClient.cc

    r984 r1005  
    3333namespace network
    3434{
     35  struct GameStateItem{
     36    GameState *state;
     37    int id;
     38  };
     39 
    3540  GameStateClient::GameStateClient() {
    3641  }
     
    4146  bool GameStateClient::pushGameState(GameStateCompressed *compstate) {
    4247    GameState *gs;
    43     if(compstate->diffed)
    44       gs = decode(reference, compstate);
     48    if(compstate->diffed){
     49      while(compstate->base_id > gameStateList.front()->id){
     50        // clean up old gamestates
     51        free(gameStateList.front()->data);
     52        // TODO: critical section
     53        delete gameStateList.front();
     54        gameStateList.pop();
     55      }
     56      if(compstate->base_id!=gameStateList.front()->id){
     57        COUT(4) << "pushGameState: no reference found to diff" << std::endl;
     58        return false;
     59      }
     60      gs = decode(gameStateList.front(), compstate);
     61    }
    4562    else
    4663      gs = decode(compstate);
     
    197214  GameState *GameStateClient::decode(GameState *a, GameStateCompressed *x) {
    198215    GameState *t = decompress(x);
     216    gameStateList.push(t);
    199217    return undiff(a, t);
    200218  }
     
    202220  GameState *GameStateClient::decode(GameStateCompressed *x) {
    203221    GameState *t = decompress(x);
     222    gameStateList.push(t);
    204223    return t;
    205224  }
  • code/branches/network/src/network/GameStateClient.h

    r984 r1005  
    1313#define _GameStateClient_H__
    1414
     15#include <queue>
     16
    1517#include "NetworkPrereqs.h"
    16 #include "GameStateManager.h"
     18#include "PacketTypes.h"
    1719
    1820namespace network
     
    3638    void removeObject(orxonox::Iterator<Synchronisable> &it);
    3739
    38     GameState *reference;
     40    GameState     *reference;
     41    std::queue<GameState *> gameStateList;
    3942  };
    4043
  • code/branches/network/src/network/GameStateManager.cc

    r986 r1005  
    6464    ++id;
    6565    return;
     66  }
     67 
     68  void GameStateManager::cleanup(){
     69    /*unsigned int min_id=-1;
     70    int temp_id=0;
     71    ClientInformation *temp = head_;
     72    while(temp){
     73      if(temp->head)
     74        continue;
     75      temp_id=temp->getID();
     76      if(temp_id<min_id)
     77        min_id=temp_id;
     78      temp=temp->next();
     79    }*/ // probably not very efficient
     80   
     81    std::map<int,int>::iterator it = gameStateUsed.begin();
     82    while(it!=gameStateUsed.end()){
     83      if( (*it).second <= 0 ){
     84        free(gameStateMap[(*it).first]->data);
     85        delete gameStateMap[(*it).first];
     86        gameStateMap.erase((*it).first);
     87        gameStateUsed.erase(it++);
     88      }else
     89        it++;
     90    }
    6691  }
    6792
  • code/branches/network/src/network/GameStateManager.h

    r984 r1005  
    4747    //#### END TESTING PURPOSE ####
    4848    void update();
     49    void cleanup(); // "garbage handler"
    4950    GameStateCompressed *popGameState(int clientID);
    5051    void ackGameState(int clientID, int gamestateID);
Note: See TracChangeset for help on using the changeset viewer.