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/GameStateClient.cc

    r1360 r1502  
    2121 *
    2222 *   Author:
    23  *      ...
     23 *      Oliver Scheuss
    2424 *   Co-authors:
    25  *      ...
     25 *      Dumeni Manatschal
    2626 *
    2727 */
     
    3535#include "Synchronisable.h"
    3636
    37 #define GAMESTATEID_INITIAL -1
    3837
    3938namespace network
     
    4342    int id;
    4443  };
    45  
     44
    4645  GameStateClient::GameStateClient() {
    4746    COUT(5) << "this: " << this << std::endl;
    4847    last_diff_=0;
    4948    last_gamestate_=GAMESTATEID_INITIAL-1;
     49    tempGameState_=NULL;
     50    myShip_=NULL;
    5051  }
    5152
     
    9596    return false;
    9697  }
    97  
     98
    9899  GameStateCompressed *GameStateClient::popPartialGameState(){
    99100    GameState *gs = getPartialSnapshot();
     101    if(!gs)
     102      return NULL;
    100103    GameStateCompressed *cgs = compress_(gs);
    101104    delete[] gs->data;
     
    103106    return cgs;
    104107  }
    105  
     108
     109  void GameStateClient::addGameState(GameStateCompressed *gs){
     110    if(tempGameState_!=NULL){
     111      //delete the obsolete gamestate
     112      if(tempGameState_->id>gs->id)
     113        return;
     114      delete[] tempGameState_->data;
     115      delete tempGameState_;
     116    }
     117    tempGameState_=gs;
     118  }
     119  int GameStateClient::processGameState(){
     120    if(tempGameState_==NULL)
     121      return 0;
     122    int id=tempGameState_->id;
     123    bool b = saveShipCache();
     124    if(pushGameState(tempGameState_)){
     125      if(b)
     126        loadShipCache();
     127      return id;
     128    }
     129    else
     130      return GAMESTATEID_INITIAL;
     131  }
     132
    106133
    107134  /**
     
    151178          orxonox::Identifier* id = ID((unsigned int)sync.classID);
    152179          if(!id){
    153             COUT(4) << "We could not identify a new object; classid: " << sync.classID << std::endl;
    154             return false;
     180            COUT(3) << "We could not identify a new object; classid: " << sync.classID << " uint: " << (unsigned int)sync.classID << " objectID: " << sync.objectID << " size: " << sync.length << std::endl;
     181            return false; // most probably the gamestate is corrupted
    155182          }
    156183          Synchronisable *no = dynamic_cast<Synchronisable *>(id->fabricate());
     
    168195          }
    169196          if( !no->create() )
     197          {
    170198            COUT(1) << "We couldn't manifest (create() ) the object: " << sync.objectID << std::endl;
     199          }
    171200          it=orxonox::ObjectList<Synchronisable>::end();
    172201        }
     
    174203        // we have our object
    175204        if(! it->updateData(sync))
     205        {
    176206          COUT(1) << "We couldn't update objectID: " \
    177207          << sync.objectID << "; classID: " << sync.classID << std::endl;
     208        }
    178209      }
    179210      ++it;
     
    213244    }
    214245    //retval->data = (unsigned char*)malloc(size);
     246    if(size==0)
     247      return NULL;
    215248    retval->data = new unsigned char[size];
    216249    if(!retval->data){
     
    245278    return retval;
    246279  }
    247  
    248  
     280
     281
    249282  GameState *GameStateClient::undiff(GameState *old, GameState *diff) {
    250283    if(!old || !diff)
     
    253286    int of=0; // pointers offset
    254287    int dest_length=0;
    255     if(old->size>=diff->size)
     288    /*if(old->size>=diff->size)
    256289      dest_length=old->size;
    257     else
     290    else*/
    258291      dest_length=diff->size;
    259292//     unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
     293    if(dest_length==0)
     294      return NULL;
    260295    unsigned char *dp = new unsigned char[dest_length*sizeof(unsigned char)];
    261296    while(of<old->size && of<diff->size){
     
    270305          of++;
    271306        }
    272       } else{
     307      } /*else{
    273308        while(of<dest_length){
    274309          *(dp+of)=*(ap+of)^n;
    275310          of++;
    276311        }
    277       }
     312      }*/
    278313    }
    279314    // should be finished now
     
    297332
    298333    uLongf buffer = (uLongf)((a->size + 12)*1.01)+1;
     334    if(buffer==0)
     335      return NULL;
    299336    unsigned char *dest = new unsigned char[buffer];
    300337    int retval;
     
    303340    switch ( retval ) {
    304341      case Z_OK: COUT(5) << "G.St.Cl: compress: successfully compressed" << std::endl; break;
    305       case Z_MEM_ERROR: COUT(1) << "G.St.Cl: compress: not enough memory available in gamestate.compress" << std::endl; 
     342      case Z_MEM_ERROR: COUT(1) << "G.St.Cl: compress: not enough memory available in gamestate.compress" << std::endl;
    306343      return NULL;
    307344      case Z_BUF_ERROR: COUT(2) << "G.St.Cl: compress: not enough memory available in the buffer in gamestate.compress" << std::endl;
     
    321358    return compressedGamestate;
    322359  }
    323  
    324  
     360
     361
    325362  GameState *GameStateClient::decompress(GameStateCompressed *a) {
    326363    //COUT(4) << "GameStateClient: uncompressing gamestate. id: " << a->id << ", baseid: " << a->base_id << ", normsize: " << a->normsize << ", compsize: " << a->compsize << std::endl;
     
    333370      bufsize = normsize;
    334371//     unsigned char* dest = (unsigned char*)malloc( bufsize );
     372    if(bufsize==0)
     373      return NULL;
    335374    unsigned char *dest = new unsigned char[bufsize];
    336375    int retval;
     
    376415    return t;
    377416  }
    378  
     417
    379418  void GameStateClient::cleanup(){
    380419    std::map<int, GameState*>::iterator temp, it = gameStateMap.begin();
     
    388427      gameStateMap.erase(temp);
    389428    }
     429    tempGameState_=NULL;
    390430  }
    391431
     
    397437    }
    398438    COUT(4) << std::endl;
    399    
    400   }
    401  
    402  
     439
     440  }
     441
     442  bool GameStateClient::saveShipCache(){
     443    if(myShip_==NULL)
     444      myShip_ = orxonox::SpaceShip::getLocalShip();
     445    if(myShip_){
     446      //      unsigned char *data = new unsigned char[myShip_->getSize()];
     447      int size=myShip_->getSize(0x3);
     448      if(size==0)
     449        return false;
     450      unsigned char *data = new unsigned char [size];
     451      shipCache_ = myShip_->getData(data, 0x1);
     452      return true;
     453    }else
     454      return false;
     455  }
     456
     457  bool GameStateClient::loadShipCache(){
     458    if(myShip_){
     459      myShip_->updateData(shipCache_, 0x2);
     460      if(shipCache_.data){
     461        delete[] shipCache_.data;
     462      }
     463      return true;
     464    }else
     465      return false;
     466  }
     467
    403468    //##### ADDED FOR TESTING PURPOSE #####
    404469  GameState* GameStateClient::testDecompress( GameStateCompressed* gc ) {
    405470    return decompress( gc );
    406471  }
    407  
     472
    408473  GameState* GameStateClient::testUndiff( GameState* g_old, GameState* g_diffed ) {
    409474    return undiff( g_old, g_diffed );
    410475  }
    411476  //##### ADDED FOR TESTING PURPOSE #####
    412  
    413  
     477
     478
    414479}
    415480
Note: See TracChangeset for help on using the changeset viewer.