Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 905 for code


Ignore:
Timestamp:
Mar 20, 2008, 2:31:45 PM (17 years ago)
Author:
scheusso
Message:

revided and checked gamestate handling

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

Legend:

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

    r891 r905  
    203203    if(id!=NULL)
    204204      id->setNetworkID(clid->clid);
     205    COUT(4) << "received network id: " << clid->clid << "; classname: " << clid->message << std::endl;
    205206    return;
    206207  }
  • code/branches/network/src/network/ConnectionManager.cc

    r888 r905  
    257257
    258258  void ConnectionManager::syncClassid(int clientID) {
    259     int i=0;
     259    unsigned int network_id=0;
    260260    std::string classname;
    261     bool abort=false;
    262261    orxonox::Identifier *id;
    263     while(!abort){
    264       id = ID(i);
    265       std::cout << "syncid: " << i << ", ID(id): " << id << std::endl;
    266       if(id == NULL){
    267         if(i!=0)
    268           abort=true;
    269         else{
    270           ++i;
    271           continue;
    272         }
    273       }
    274       else{
    275         classname = id->getName();
    276         addPacket(packet_gen.clid( i, classname ),clientID);
    277       }
    278       ++i;
     262    std::map<std::string, orxonox::Identifier*>::const_iterator it = orxonox::Factory::getFactoryBegin();
     263    while(it != orxonox::Factory::getFactoryEnd()){
     264      id = (*it).second;
     265      if(id == NULL)
     266        continue;
     267      classname = id->getName();
     268      network_id = id->getNetworkID();
     269      COUT(4) << "network_id: " << network_id << ", classname: " << classname << std::endl;
     270     
     271      addPacket(packet_gen.clid( (int)network_id, classname ), clientID);
     272     
     273      ++it;
    279274    }
    280275    sendPackets();
  • code/branches/network/src/network/GameStateClient.cc

    r871 r905  
    4141  bool GameStateClient::pushGameState(GameStateCompressed *compstate) {
    4242    if(compstate->diffed)
    43       return loadSnapshot(decode(reference, *compstate));
     43      return loadSnapshot(decode(reference, compstate));
    4444    else
    45       return loadSnapshot(decode(*compstate));
     45      return loadSnapshot(decode(compstate));
    4646  }
    4747
     
    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 && it->objectID!=sync.objectID){
     84        while(it && it->objectID!=sync.objectID)
    8585          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());
     86       
     87       
     88        if(!it){
     89          COUT(5) << "classid: " << sync.classID << ", name: " << ID((unsigned int) sync.classID)->getName() << std::endl;
     90          Synchronisable *no = (Synchronisable*)(ID((unsigned int) sync.classID)->fabricate());
    9091          no->objectID=sync.objectID;
    9192          no->classID=sync.classID;
     
    9394          // update data and create object/entity...
    9495          if( !no->updateData(sync) && !no->create() )
    95             COUT(0) << "We couldn't create/update the object: " << sync.objectID << std::endl;
     96            COUT(1) << "We couldn't create/update the object: " << sync.objectID << std::endl;
    9697          ++it;
    9798        }
     
    99100        // we have our object
    100101        if(! it->updateData(sync))
    101           std::cout << "We couldn't update objectID: " \
     102          COUT(1) << "We couldn't update objectID: " \
    102103          << sync.objectID << "; classID: " << sync.classID << std::endl;
    103104      }
     
    108109  }
    109110
    110   GameState GameStateClient::diff(GameState a, GameState b) {
    111     unsigned char *ap = a.data, *bp = b.data;
     111  GameState *GameStateClient::undiff(GameState *a, GameState *b) {
     112    unsigned char *ap = a->data, *bp = b->data;
    112113    int of=0; // pointers offset
    113114    int dest_length=0;
    114     if(a.size>=b.size)
    115       dest_length=a.size;
     115    if(a->size>=b->size)
     116      dest_length=a->size;
    116117    else
    117       dest_length=b.size;
     118      dest_length=b->size;
    118119    unsigned char *dp = (unsigned char *)malloc(dest_length*sizeof(unsigned char));
    119     while(of<a.size && of<b.size){
     120    while(of<a->size && of<b->size){
    120121      *(dp+of)=*(ap+of)^*(bp+of); // do the xor
    121122      ++of;
    122123    }
    123     if(a.size!=b.size){ // do we have to fill up ?
     124    if(a->size!=b->size){ // do we have to fill up ?
    124125      unsigned char n=0;
    125       if(a.size<b.size){
     126      if(a->size<b->size){
    126127        while(of<dest_length){
    127128          *(dp+of)=n^*(bp+of);
     
    137138    // should be finished now
    138139    // FIXME: is it true or false now? (struct has changed, producing warnings)
    139     GameState r = {b.id, dest_length, true, dp};
     140    GameState *r = new GameState;
     141    r->id = b->id;
     142    r->size = dest_length;
     143    r->diffed = false;
     144    r->data = dp;
    140145    return r;
    141146  }
    142147
    143   GameState GameStateClient::decompress(GameStateCompressed a) {
    144     int normsize = a.normsize;
    145     int compsize = a.compsize;
     148  GameState *GameStateClient::decompress(GameStateCompressed *a) {
     149    int normsize = a->normsize;
     150    int compsize = a->compsize;
    146151    int bufsize;
    147152    if(normsize < compsize)
     
    154159    //std::cout << "gamestateclient" << std::endl;
    155160    //std::cout << "normsize " << a.normsize << " compsize " << a.compsize << " " << bufsize << std::endl;
    156     retval = uncompress( dest, &length, a.data, (uLong)compsize );
     161    retval = uncompress( dest, &length, a->data, (uLong)compsize );
    157162    //std::cout << "length " << length << std::endl;
    158163    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;
     164      case Z_OK: COUT(4) << "successfully decompressed" << std::endl; break;
     165      case Z_MEM_ERROR: COUT(1) << "not enough memory available" << std::endl; return NULL;
     166      case Z_BUF_ERROR: COUT(2) << "not enough memory available in the buffer" << std::endl; return NULL;
     167      case Z_DATA_ERROR: COUT(2) << "data corrupted" << std::endl; return NULL;
    163168    }
    164169
    165     GameState gamestate;
    166     gamestate.id = a.id;
    167     gamestate.size = normsize;
    168     gamestate.data = dest;
    169     gamestate.diffed = a.diffed;
     170    GameState *gamestate = new GameState;
     171    gamestate->id = a->id;
     172    gamestate->size = normsize;
     173    gamestate->data = dest;
     174    gamestate->diffed = a->diffed;
     175   
     176    delete a->data; //delete compressed data
     177    delete a; //we do not need the old (struct) gamestate anymore
    170178
    171179    return gamestate;
    172180  }
    173181
    174   GameState GameStateClient::decode(GameState a, GameStateCompressed x) {
    175     GameState t = decompress(x);
    176     return diff(a, t);
     182  GameState *GameStateClient::decode(GameState *a, GameStateCompressed *x) {
     183    GameState *t = decompress(x);
     184    return undiff(a, t);
    177185  }
    178186
    179   GameState GameStateClient::decode(GameStateCompressed x) {
    180     GameState t = decompress(x);
     187  GameState *GameStateClient::decode(GameStateCompressed *x) {
     188    GameState *t = decompress(x);
    181189    return t;
    182190  }
  • code/branches/network/src/network/GameStateClient.h

    r790 r905  
    2525    bool pushGameState(GameStateCompressed *compstate);
    2626  private:
    27     bool loadSnapshot(GameState state);
    28     GameState diff(GameState a, GameState b);
    29     GameState decompress(GameStateCompressed a);
    30     GameState decode(GameState a, GameStateCompressed x);
    31     GameState decode(GameStateCompressed x);
     27    bool loadSnapshot(GameState *state);
     28    GameState *undiff(GameState *a, GameState *b);
     29    GameState *decompress(GameStateCompressed *a);
     30    GameState *decode(GameState *a, GameStateCompressed *x);
     31    GameState *decode(GameStateCompressed *x);
    3232    void removeObject(orxonox::Iterator<Synchronisable> &it);
    3333
    34     GameState reference;
     34    GameState *reference;
    3535  };
    3636
  • code/branches/network/src/network/GameStateManager.cc

    r894 r905  
    4343
    4444#include "core/CoreIncludes.h"
     45
    4546#include "ClientInformation.h"
    4647#include "Synchronisable.h"
  • code/branches/network/src/orxonox/Orxonox.cc

    r904 r905  
    107107        usleep(10);
    108108
     109        if(mode_!=CLIENT){
    109110        mKeyboard->capture();
    110111        return !mKeyboard->isKeyDown(OIS::KC_ESCAPE);
     112        }else
     113          return true;
    111114      }
    112115
     
    225228   
    226229   
    227     setupInputSystem();
     230    //setupInputSystem();
    228231   
    229232    createFrameListener();
Note: See TracChangeset for help on using the changeset viewer.