Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 10, 2008, 5:03:34 PM (17 years ago)
Author:
bknecht
Message:

merged back that script-branch

File:
1 edited

Legend:

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

    r871 r1021  
    4040
    4141  bool GameStateClient::pushGameState(GameStateCompressed *compstate) {
     42    GameState *gs;
    4243    if(compstate->diffed)
    43       return loadSnapshot(decode(reference, *compstate));
     44      gs = decode(reference, compstate);
    4445    else
    45       return loadSnapshot(decode(*compstate));
     46      gs = decode(compstate);
     47    if(gs)
     48      return loadSnapshot(gs);
     49    COUT(4) << "could not use gamestate sent by server" << std::endl;
     50    return false;
    4651  }
    4752
     
    6166  * @param state a GameState struct containing the size of the gamestate and a pointer linking to a flat list (returned by getSnapshot)
    6267  */
    63   bool GameStateClient::loadSnapshot(GameState state) {
    64     unsigned char *data=state.data;
    65     std::cout << "loadSnapshot: loading gs: " << state.id << std::endl;
     68  bool GameStateClient::loadSnapshot(GameState *state) {
     69    unsigned char *data=state->data;
     70    COUT(4) << "loadSnapshot: loading gs: " << state->id << std::endl;
    6671    // get the start of the Synchronisable list
    6772    orxonox::Iterator<Synchronisable> it=orxonox::ObjectList<Synchronisable>::start();
    6873    syncData sync;
    6974    // loop as long as we have some data ;)
    70     while(data < state.data+state.size){
     75    while(data < state->data+state->size){
    7176      // prepare the syncData struct
    7277      sync.length = (int)*data;
     
    8287        // bad luck ;)
    8388        // delete the synchronisable (obviously seems to be deleted on the server)
    84         while(it && it->objectID!=sync.objectID){
     89        while(it && it->objectID!=sync.objectID)
    8590          removeObject(it);
    86         }
    87         if(it==0){
    88           std::cout << "classid: " << sync.classID << ", name: " << ID(sync.classID)->getName() << std::endl;
    89           Synchronisable *no = (Synchronisable*)(ID(sync.classID)->fabricate());
     91       
     92       
     93        if(!it){
     94          COUT(5) << "classid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
     95          Synchronisable *no = (Synchronisable*)(ID((unsigned int) sync.classID)->fabricate());
    9096          no->objectID=sync.objectID;
    9197          no->classID=sync.classID;
     
    9399          // update data and create object/entity...
    94100          if( !no->updateData(sync) && !no->create() )
    95             COUT(0) << "We couldn't create/update the object: " << sync.objectID << std::endl;
     101            COUT(1) << "We couldn't create/update the object: " << sync.objectID << std::endl;
    96102          ++it;
    97103        }
     
    99105        // we have our object
    100106        if(! it->updateData(sync))
    101           std::cout << "We couldn't update objectID: " \
     107          COUT(1) << "We couldn't update objectID: " \
    102108          << sync.objectID << "; classID: " << sync.classID << std::endl;
    103109      }
     
    108114  }
    109115
    110   GameState GameStateClient::diff(GameState a, GameState b) {
    111     unsigned char *ap = a.data, *bp = b.data;
     116  GameState *GameStateClient::undiff(GameState *a, GameState *b) {
     117    unsigned char *ap = a->data, *bp = b->data;
    112118    int of=0; // pointers offset
    113119    int dest_length=0;
    114     if(a.size>=b.size)
    115       dest_length=a.size;
     120    if(a->size>=b->size)
     121      dest_length=a->size;
    116122    else
    117       dest_length=b.size;
     123      dest_length=b->size;
    118124    unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
    119     while(of<a.size && of<b.size){
     125    while(of<a->size && of<b->size){
    120126      *(dp+of)=*(ap+of)^*(bp+of); // do the xor
    121127      ++of;
    122128    }
    123     if(a.size!=b.size){ // do we have to fill up ?
     129    if(a->size!=b->size){ // do we have to fill up ?
    124130      unsigned char n=0;
    125       if(a.size<b.size){
     131      if(a->size<b->size){
    126132        while(of<dest_length){
    127133          *(dp+of)=n^*(bp+of);
     
    137143    // should be finished now
    138144    // FIXME: is it true or false now? (struct has changed, producing warnings)
    139     GameState r = {b.id, dest_length, true, dp};
     145    GameState *r = new GameState;
     146    r->id = b->id;
     147    r->size = dest_length;
     148    r->diffed = false;
     149    r->data = dp;
    140150    return r;
    141151  }
    142152
    143   GameState GameStateClient::decompress(GameStateCompressed a) {
    144     int normsize = a.normsize;
    145     int compsize = a.compsize;
     153  GameState *GameStateClient::decompress(GameStateCompressed *a) {
     154    int normsize = a->normsize;
     155    int compsize = a->compsize;
    146156    int bufsize;
    147157    if(normsize < compsize)
     
    154164    //std::cout << "gamestateclient" << std::endl;
    155165    //std::cout << "normsize " << a.normsize << " compsize " << a.compsize << " " << bufsize << std::endl;
    156     retval = uncompress( dest, &length, a.data, (uLong)compsize );
     166    retval = uncompress( dest, &length, a->data, (uLong)compsize );
    157167    //std::cout << "length " << length << std::endl;
    158168    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;
     169      case Z_OK: COUT(4) << "successfully decompressed" << std::endl; break;
     170      case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL;
     171      case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL;
     172      case Z_DATA_ERROR: COUT(2) << "data corrupted" << std::endl; return NULL;
    163173    }
    164174
    165     GameState gamestate;
    166     gamestate.id = a.id;
    167     gamestate.size = normsize;
    168     gamestate.data = dest;
    169     gamestate.diffed = a.diffed;
     175    GameState *gamestate = new GameState;
     176    gamestate->id = a->id;
     177    gamestate->size = normsize;
     178    gamestate->data = dest;
     179    gamestate->diffed = a->diffed;
     180   
     181    delete a->data; //delete compressed data
     182    delete a; //we do not need the old (struct) gamestate anymore
    170183
    171184    return gamestate;
    172185  }
    173186
    174   GameState GameStateClient::decode(GameState a, GameStateCompressed x) {
    175     GameState t = decompress(x);
    176     return diff(a, t);
     187  GameState *GameStateClient::decode(GameState *a, GameStateCompressed *x) {
     188    GameState *t = decompress(x);
     189    return undiff(a, t);
    177190  }
    178191
    179   GameState GameStateClient::decode(GameStateCompressed x) {
    180     GameState t = decompress(x);
     192  GameState *GameStateClient::decode(GameStateCompressed *x) {
     193    GameState *t = decompress(x);
    181194    return t;
    182195  }
Note: See TracChangeset for help on using the changeset viewer.