Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 6, 2008, 4:45:49 PM (16 years ago)
Author:
scheusso
Message:

some changes

File:
1 edited

Legend:

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

    r790 r868  
    6161  * @param state a GameState struct containing the size of the gamestate and a pointer linking to a flat list (returned by getSnapshot)
    6262  */
    63   bool GameStateClient::loadSnapshot(GameState state) {
    64     unsigned char *data=state.data;
    65     std::cout << "loadSnapshot: loading gs: " << state.id << std::endl;
     63  bool GameStateClient::loadSnapshot(GameState *state) {
     64    unsigned char *data=state->data;
     65    COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl;
    6666    // get the start of the Synchronisable list
    6767    orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
    6868    syncData sync;
    6969    // loop as long as we have some data ;)
    70     while(data < state.data+state.size){
     70    while(data < state->data+state->size){
    7171      // prepare the syncData struct
    7272      sync.length = (int)*data;
     
    8282        // bad luck ;)
    8383        // delete the synchronisable (obviously seems to be deleted on the server)
    84         while(it != 0 && it->objectID!=sync.objectID){
     84        while(it && it->objectID!=sync.objectID){
    8585          removeObject(it);
    8686        }
    87         if(it==0){
    88           std::cout << "classid: " << sync.classID << ", name: " << ID(sync.classID)->getName() << std::endl;
     87        if(!it){
     88          COUT(4) << "classid: " << sync.classID << ", name: " << ID(sync.classID)->getName() << std::endl;
    8989          Synchronisable *no = (Synchronisable*)(ID(sync.classID)->fabricate());
    9090          no->objectID=sync.objectID;
     
    9393          // update data and create object/entity...
    9494          if( !no->updateData(sync) && !no->create() )
    95             COUT(0) << "We couldn't create/update the object: " << sync.objectID << std::endl;
     95            COUT(2) << "We couldn't create/update the object: " << sync.objectID << std::endl;
    9696          ++it;
    9797        }
     
    9999        // we have our object
    100100        if(! it->updateData(sync))
    101           std::cout << "We couldn't update objectID: " \
     101          COUT(2) << "We couldn't update objectID: " \
    102102          << sync.objectID << "; classID: " << sync.classID << std::endl;
    103103      }
     
    108108  }
    109109
    110   GameState GameStateClient::diff(GameState a, GameState b) {
     110  GameState *GameStateClient::diff(GameState a, GameState b) {
    111111    unsigned char *ap = a.data, *bp = b.data;
    112112    int of=0; // pointers offset
     
    137137    // should be finished now
    138138    // FIXME: is it true or false now? (struct has changed, producing warnings)
    139     GameState r = {b.id, dest_length, true, dp};
     139    GameState *r = new GameState;
     140    r->id = b.id;
     141    r->size = dest_length;
     142    r->diffed = true;
     143    r->data = dp;
    140144    return r;
    141145  }
    142146
    143   GameState GameStateClient::decompress(GameStateCompressed a) {
     147  GameState *GameStateClient::decompress(GameStateCompressed a) {
    144148    int normsize = a.normsize;
    145149    int compsize = a.compsize;
     
    157161    //std::cout << "length " << length << std::endl;
    158162    switch ( retval ) {
    159       case Z_OK: std::cout << "successfully decompressed" << std::endl; break;
    160       case Z_MEM_ERROR: std::cout << "not enough memory available" << std::endl; break;
    161       case Z_BUF_ERROR: std::cout << "not enough memory available in the buffer" << std::endl; break;
    162       case Z_DATA_ERROR: std::cout << "data corrupted" << std::endl; break;
    163     }
    164 
    165     GameState gamestate;
    166     gamestate.id = a.id;
    167     gamestate.size = normsize;
    168     gamestate.data = dest;
    169     gamestate.diffed = a.diffed;
    170 
     163      case Z_OK:
     164        COUT(3) << "successfully decompressed" << std::endl; break;
     165      case Z_MEM_ERROR:
     166        COUT(1) << "not enough memory available" << std::endl;
     167        return NULL;
     168      case Z_BUF_ERROR:
     169        COUT(2) << "not enough memory available in the buffer" << std::endl;
     170        return NULL;
     171      case Z_DATA_ERROR:
     172        COUT(2) << "data corrupted" << std::endl;
     173        return NULL;
     174    }
     175
     176    GameState *gamestate = new GameState;
     177    gamestate->id = a.id;
     178    gamestate->size = normsize;
     179    gamestate->data = dest;
     180    gamestate->diffed = a.diffed;
     181
     182    free(a.data);
     183   
    171184    return gamestate;
    172185  }
    173186
    174   GameState GameStateClient::decode(GameState a, GameStateCompressed x) {
    175     GameState t = decompress(x);
    176     return diff(a, t);
    177   }
    178 
    179   GameState GameStateClient::decode(GameStateCompressed x) {
    180     GameState t = decompress(x);
    181     return t;
     187  GameState *GameStateClient::decode(GameState a, GameStateCompressed x) {
     188    GameState *t = decompress(x);
     189    if(t==NULL)
     190      return NULL;
     191    else
     192      return diff(a, *t);
     193  }
     194
     195  GameState *GameStateClient::decode(GameStateCompressed x) {
     196    GameState *t = decompress(x);
     197    if(t==NULL)
     198      return NULL;
     199    else
     200      return t;
    182201  }
    183202
Note: See TracChangeset for help on using the changeset viewer.