Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 1, 2008, 3:54:20 PM (16 years ago)
Author:
rgrieder
Message:
  • @everyone: Do not create a branch until I've added the svn:eol-style property correctly. Otherwise this would cost me another 4 hours or so when we want to merge back.
  • merged network branch back to trunk
  • I had to omit the changes from last evening concerning the line endings
  • might not work yet because of the line endings
  • @beni: script branch is the only branch still open. you probably will have to apply a patch because of inconsistent new lines
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/network/GameStateManager.cc

    r1360 r1502  
    6868    printGameStates();
    6969    return;
     70  }
     71 
     72  void GameStateManager::addGameState(GameStateCompressed *gs, int clientID){
     73    if(!gs)
     74      return;
     75    std::map<int, GameStateCompressed*>::iterator it = gameStateQueue.find(clientID);
     76    if(it!=gameStateQueue.end()){
     77      // delete obsolete gamestate
     78      delete[] it->second->data;
     79      delete it->second;
     80    }
     81    gameStateQueue[clientID] = gs;
     82    return;
     83  }
     84 
     85  void GameStateManager::processGameStates(){
     86    std::map<int, GameStateCompressed*>::iterator it;
     87    // now push only the most recent gamestates we received (ignore obsolete ones)
     88    for(it = gameStateQueue.begin(); it!=gameStateQueue.end(); it++){
     89      pushGameState(it->second, it->first);
     90    }
     91    // now clear the queue
     92    gameStateQueue.clear();
    7093  }
    7194 
     
    117140        client = it->second;
    118141      GameState *server = reference;
    119       COUT(3) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap << std::endl;
     142      COUT(4) << "client: " << client << " server: " << server << " gamestatemap: " << &gameStateMap << " size: " << server->size << std::endl;
    120143      if(client)
    121144        return encode(client, server);
     
    170193    }
    171194    //retval->data = (unsigned char*)malloc(size);
     195    if(size==0)
     196      return NULL;
    172197    retval->data = new unsigned char[size];
    173198    if(!retval->data){
     
    237262      data+=sizeof(int);
    238263      sync.classID = *(int*)data;
     264      if(sync.classID == 0) // TODO: remove this
     265        COUT(3) << "received a classid 0" << std::endl;
    239266      data+=sizeof(int);
    240267      sync.data = data;
     
    246273
    247274      if(!it){
    248         // the object does not exist yet
     275        // the objectaber ich glaub die does not exist yet
    249276        COUT(4) << "loadsnapshot: creating new object " << std::endl;
    250277        //COUT(4) << "loadSnapshot:\tclassid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
     
    314341  }
    315342
    316   GameState *GameStateManager::diff(GameState *a, GameState *b) {
    317     unsigned char *ap = a->data, *bp = b->data;
     343  GameState *GameStateManager::diff(GameState *alt, GameState *neu) {
     344    unsigned char *ap = alt->data, *bp = neu->data;
    318345    int of=0; // pointers offset
    319346    int dest_length=0;
    320     if(a->size>=b->size)
    321       dest_length=a->size;
    322     else
    323       dest_length=b->size;
     347    /*if(alt->size>neu->size)
     348      dest_length=alt->size;
     349    else*/
     350      dest_length=neu->size;
     351    if(dest_length==0)
     352      return NULL;
    324353    //unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
    325354    unsigned char *dp = new unsigned char[dest_length*sizeof(unsigned char)];
    326     while(of<a->size && of<b->size){
     355    while(of<alt->size && of<neu->size){
    327356      *(dp+of)=*(ap+of)^*(bp+of); // do the xor
    328357      ++of;
    329358    }
    330     if(a->size!=b->size){ // do we have to fill up ?
     359    if(alt->size!=neu->size){ // do we have to fill up ?
    331360      unsigned char n=0;
    332       if(a->size<b->size){
     361      if(alt->size<neu->size){
    333362        while(of<dest_length){
    334363          *(dp+of)=n^*(bp+of);
    335364          of++;
    336365        }
    337       } else{
     366      } /*else{
    338367        while(of<dest_length){
    339368          *(dp+of)=*(ap+of)^n;
    340369          of++;
    341370        }
    342       }
     371      }*/
    343372    }
    344373
    345374    GameState *r = new GameState;
    346     r->id = b->id;
     375    r->id = neu->id;
    347376    r->size = dest_length;
    348377    r->diffed = true;
    349     r->base_id = a->id;
     378    r->base_id = alt->id;
    350379    r->data = dp;
    351380    r->complete = true;
     
    362391    //COUT(4) << "size: " << size << ", buffer: " << buffer << std::endl;
    363392    //unsigned char* dest = (unsigned char*)malloc( buffer );
     393    if(buffer==0)
     394      return NULL;
    364395    unsigned char *dest = new unsigned char[buffer];
    365396    //COUT(4) << "dest: " << dest << std::endl;
     
    404435      bufsize = normsize;
    405436//     unsigned char* dest = (unsigned char*)malloc( bufsize );
     437    if(bufsize==0)
     438      return NULL;
    406439    unsigned char *dest = new unsigned char[bufsize];
    407440    int retval;
     
    436469      return;
    437470    int curid = temp->getGamestateID();
     471   
     472    if(gamestateID == GAMESTATEID_INITIAL){
     473      temp->setGameStateID(GAMESTATEID_INITIAL);
     474      if(curid!=GAMESTATEID_INITIAL)
     475        --(gameStateUsed.find(curid)->second);
     476      return;
     477    }
    438478    if(curid > gamestateID)
    439479      // the network packets got messed up
     
    446486      --(gameStateUsed.find(curid)->second);
    447487    ++(gameStateUsed.find(gamestateID)->second);
    448     temp->setGamestateID(gamestateID);
     488    temp->setGameStateID(gamestateID);
    449489    /*
    450490    GameState *old = clientGameState[clientID];
Note: See TracChangeset for help on using the changeset viewer.