Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1742 for code/branches/network


Ignore:
Timestamp:
Sep 8, 2008, 2:21:00 PM (16 years ago)
Author:
scheusso
Message:

compressing and diffing works now (also shipCache on client). server can't move while client connected. preparations for synchronise frequency of synchronisables

Location:
code/branches/network
Files:
2 added
10 edited

Legend:

Unmodified
Added
Removed
  • code/branches/network/bin/levels/sample.oxw

    r1680 r1742  
    2222<NPC position="0,-200,450" scale="1" mesh="razor.mesh"/>
    2323<NPC position="100,0,400" scale="1" mesh="razor.mesh"/>
    24 
    25 <?lua
    26 for i = 1, 10, 1
    27 do ?>
    28   <SpaceShipAI position="<?lua print(math.random() * 6000 - 3000) ?>,<?lua print(math.random() * 6000 - 3000) ?>,<?lua print(math.random() * 6000 - 3000) ?>" scale="10" yawpitchroll="0,0,0" mesh="assff.mesh" maxSpeed="500" maxSideAndBackSpeed="50" maxRotation="1.0" transAcc="200" rotAcc="3.0" transDamp="75" rotDamp="1.0" />
    29 <?lua
    30 end
    31 ?>
    3224
    3325<!--Model name="starship" position="200,0,500" scale="10" mesh="starship.mesh" yawpitchroll="-90,-90,0" />
  • code/branches/network/src/network/GamestateClient.cc

    r1741 r1742  
    7373      return 0;
    7474    int id = GAMESTATEID_INITIAL;
    75     //bool b = saveShipCache();
     75    bool b = saveShipCache();
    7676    packet::Gamestate *processed = processGamestate(tempGamestate_);
    7777    assert(processed);
     
    8181    last_diff_ = processed->getBaseID();
    8282    last_gamestate_ = processed->getID();
    83     //if(b)
    84       //loadShipCache();
     83    if(b)
     84      loadShipCache();
    8585    id = processed->getID();
    8686    cleanup();
     
    134134    if(myShip_){
    135135      //      unsigned char *data = new unsigned char[myShip_->getSize()];
    136       int size=myShip_->getSize(0x1);
     136      int size=myShip_->getSize2(0, 0x1);
    137137      if(size==0)
    138138        return false;
    139139      shipCache_ = new unsigned char [size];
    140140      unsigned char *temp = shipCache_;
    141       if(!myShip_->getData2(temp, 0x1))
     141      if(!myShip_->getData(temp, 0, 0x1))
    142142        COUT(3) << "could not save shipCache" << std::endl;
    143143      return true;
     
    157157
    158158  packet::Gamestate *GamestateClient::processGamestate(packet::Gamestate *gs){
    159     if(gs->isCompressed()){
    160       bool b = gs->decompressData();
    161       assert(b);
    162     }
     159    if(gs->isCompressed())
     160      assert(gs->decompressData());
    163161    if(gs->isDiffed()){
    164162      packet::Gamestate *base = gamestateMap_[gs->getBaseID()];
  • code/branches/network/src/network/GamestateManager.cc

    r1741 r1742  
    131131    packet::Gamestate *gs;
    132132    int gID = ClientInformation::findClient(clientID)->getGamestateID();
    133     COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id_ << " diffed from: " << gID << std::endl;
    134 //     COUT(3) << "gamestatemap: " << &gameStateMap << std::endl;
     133    //COUT(4) << "G.St.Man: popgamestate: sending gstate_id: " << id_ << " diffed from: " << gID << std::endl;
    135134    //chose wheather the next gamestate is the first or not
    136135    if(gID != GAMESTATEID_INITIAL){
     
    147146      gs = new packet::Gamestate(*reference);
    148147    }
    149 #ifndef NDEBUG
    150     packet::Gamestate *ns = new packet::Gamestate(*gs);
    151     ns->compressData();
    152     ns->decompressData();
    153     assert(*gs==*ns);
    154     delete ns;
    155 #endif
    156148    assert(gs->compressData());
    157149    return gs;
  • code/branches/network/src/network/Server.cc

    r1739 r1742  
    264264      //std::cout << "adding gamestate" << std::endl;
    265265      gs->setClientID(cid);
    266       assert(gs->compressData());
    267266      if ( !gs->send() ){
    268267        COUT(3) << "Server: packet with client id (cid): " << cid << " not sended: " << temp->getFailures() << std::endl;
     
    298297      return false;
    299298    }
    300     if(temp->prev()->getBegin()) { //not good if you use anything else than insertBack
    301       temp->prev()->setID(0); //bugfix: not necessary but usefull
     299    if(temp==ClientInformation::getBegin()) { //not good if you use anything else than insertBack
    302300      temp->setID(1);
    303301    }
  • code/branches/network/src/network/Synchronisable.cc

    r1741 r1742  
    6363    static int idCounter=0;
    6464    datasize=0;
     65    objectFrequency_=1;
    6566    objectID=idCounter++;
    6667    syncList = new std::list<synchronisableVariable *>;
     
    9495    objectID = *(unsigned int*)(mem+sizeof(unsigned int));
    9596    classID = *(unsigned int*)(mem+2*sizeof(unsigned int));
     97   
     98    if(size==3*sizeof(unsigned int)) //not our turn, dont do anything
     99      return true;
    96100   
    97101    orxonox::Identifier* id = ID(classID);
     
    141145    syncList->push_back(temp);
    142146  }
    143 
    144 
    145   /**
    146   * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
    147   * Difference to the above function:
    148   * takes a pointer to already allocated memory (must have at least getSize bytes length)
    149   * structure of the bitstream:
    150   * (var1_size,var1,var2_size,var2,...)
    151   * varx_size: size = sizeof(int)
    152   * varx: size = varx_size
    153   * @return data containing all variables and their sizes
    154   */
    155   syncData Synchronisable::getData(unsigned char *mem, int mode){
    156     //std::cout << "inside getData" << std::endl;
    157     if(mode==0x0)
    158       mode=state_;
    159     if(classID==0)
    160       COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
    161     this->classID=this->getIdentifier()->getNetworkID();
    162     std::list<synchronisableVariable *>::iterator i;
    163     syncData retVal;
    164     retVal.objectID=this->objectID;
    165     retVal.classID=this->classID;
    166     retVal.length=getSize();
    167     COUT(5) << "Synchronisable getting data from objectID: " << retVal.objectID << " classID: " << retVal.classID << " length: " << retVal.length << std::endl;
    168     retVal.data=mem;
    169     // copy to location
    170     int n=0; //offset
    171     for(i=syncList->begin(); n<datasize && i!=syncList->end(); ++i){
    172       //(std::memcpy(retVal.data+n, (const void*)(&(i->size)), sizeof(int));
    173       if( ((*i)->mode & mode) == 0 ){
    174         COUT(5) << "not getting data: " << std::endl;
    175         continue;  // this variable should only be received
    176       }
    177       switch((*i)->type){
    178       case DATA:
    179         memcpy( (void *)(retVal.data+n), (void*)((*i)->var), (*i)->size);
    180         n+=(*i)->size;
    181         break;
    182       case STRING:
    183         memcpy( (void *)(retVal.data+n), (void *)&((*i)->size), sizeof(int) );
    184         n+=sizeof(int);
    185         const char *data = ( ( *(std::string *) (*i)->var).c_str());
    186         memcpy( retVal.data+n, (void*)data, (*i)->size);
    187         COUT(5) << "synchronisable: char: " << (const char *)(retVal.data+n) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl;
    188         n+=(*i)->size;
    189         break;
    190       }
    191     }
    192     return retVal;
    193   }
    194147 
    195148  /**
    196149   * This function takes all SynchronisableVariables out of the Synchronisable and saves it into a syncData struct
    197   * Difference to the above function:
     150   * Difference to the above function:
    198151   * takes a pointer to already allocated memory (must have at least getSize bytes length)
    199   * structure of the bitstream:
     152   * structure of the bitstream:
    200153   * (var1_size,var1,var2_size,var2,...)
    201154   * varx_size: size = sizeof(int)
     
    203156   * @return data containing all variables and their sizes
    204157   */
    205   bool Synchronisable::getData2(unsigned char*& mem, int mode){
     158  bool Synchronisable::getData(unsigned char*& mem, unsigned int id, int mode){
    206159    //std::cout << "inside getData" << std::endl;
    207160    unsigned int tempsize = 0;
     
    210163    if(classID==0)
    211164      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
    212     this->classID=this->getIdentifier()->getNetworkID();
     165    this->classID=this->getIdentifier()->getNetworkID(); // TODO: correct this
    213166    std::list<synchronisableVariable *>::iterator i;
    214167    unsigned int size;
    215     size=getSize2(mode);
     168    size=getSize2(id, mode);
    216169   
    217170    // start copy header
     
    224177    tempsize+=12;
    225178    // end copy header
     179   
     180    //if this tick is we dont synchronise, then abort now
     181    if(!isMyTick(id))
     182      return true;
    226183   
    227184    COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl;
     
    254211  }
    255212
    256   /*bool Synchronisable::getData(Bytestream& bs, int mode)
    257   {
    258     //std::cout << "inside getData" << std::endl;
    259     if(mode==0x0)
    260       mode=state_;
    261     if(classID==0)
    262       COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
    263     this->classID=this->getIdentifier()->getNetworkID();
    264     std::list<synchronisableVariable *>::iterator i;
    265     bs << this->getSize();
    266     bs << this->objectID;
    267     bs << this->classID;
    268     // copy to location
    269     for(i=syncList->begin(); i!=syncList->end(); ++i){
    270       if( ((*i)->mode & mode) == 0 ){
    271         COUT(5) << "not getting data: " << std::endl;
    272         continue;  // this variable should only be received
    273       }
    274       switch((*i)->type){
    275         case DATA:
    276           bs << *(*i)->var;
    277           //std::memcpy( (void *)(retVal.data+n), (void*)((*i)->var), (*i)->size);
    278           //n+=(*i)->size;
    279           break;
    280         case STRING:
    281           bs << *(String *)((*i)->var);
    282           //memcpy( (void *)(retVal.data+n), (void *)&((*i)->size), sizeof(int) );
    283           //n+=sizeof(int);
    284           //const char *data = ( ( *(std::string *) (*i)->var).c_str());
    285           //std::memcpy( retVal.data+n, (void*)data, (*i)->size);
    286           //COUT(5) << "synchronisable: char: " << (const char *)(retVal.data+n) << " data: " << data << " string: " << *(std::string *)((*i)->var) << std::endl;
    287           //n+=(*i)->size;
    288           break;
    289       }
    290     }
    291     return true;
    292   }*/
    293 
    294  
    295   /**
    296   * This function takes a syncData struct and takes it to update the variables
    297   * @param vars data of the variables
    298   * @return true/false
    299   */
    300   bool Synchronisable::updateData(syncData vars, int mode){
    301     if(mode==0x0)
    302       mode=state_;
    303     unsigned char *data=vars.data;
    304     std::list<synchronisableVariable *>::iterator i;
    305     if(syncList->empty()){
    306       COUT(4) << "Synchronisable::updateData syncList is empty" << std::endl;
    307       return false;
    308     }
    309     COUT(5) << "Synchronisable: objectID " << vars.objectID << ", classID " << vars.classID << " size: " << vars.length << " synchronising data" << std::endl;
    310     for(i=syncList->begin(); i!=syncList->end(); i++){
    311       if( ((*i)->mode ^ mode) == 0 ){
    312         COUT(5) << "synchronisable: not updating variable " << std::endl;
    313         continue;  // this variable should only be set
    314       }
    315       COUT(5) << "Synchronisable: element size: " << (*i)->size << " type: " << (*i)->type << std::endl;
    316       bool callback=false;
    317       switch((*i)->type){
    318       case DATA:
    319         if((*i)->callback) // check whether this variable changed (but only if callback was set)
    320           if(strncmp((char *)(*i)->var, (char *)data, (*i)->size)!=0)
    321             callback=true;
    322         memcpy((void*)(*i)->var, data, (*i)->size);
    323         data+=(*i)->size;
    324         break;
    325       case STRING:
    326         (*i)->size = *(int *)data;
    327         COUT(5) << "string size: " << (*i)->size << std::endl;
    328         data+=sizeof(int);
    329         if((*i)->callback) // check whether this string changed
    330           if( *(std::string *)((*i)->var) != std::string((char *)data) )
    331             callback=true;
    332         *((std::string *)((*i)->var)) = std::string((const char*)data);
    333         COUT(5) << "synchronisable: char: " << (const char*)data << " string: " << std::string((const char*)data) << std::endl;
    334         data += (*i)->size;
    335         break;
    336       }
    337       // call the callback function, if defined
    338       if(callback && (*i)->callback)
    339         (*i)->callback->call();
    340     }
    341     return true;
    342   }
    343213 
    344214  /**
     
    368238    assert(this->objectID==objectID);
    369239    assert(this->classID==classID);
     240    if(size==3*sizeof(unsigned int)) //if true, only the header is available
     241      return true;
     242      //assert(0);
    370243   
    371244    COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " size: " << size << " synchronising data" << std::endl;
     
    408281  * @return amount of bytes
    409282  */
    410   int Synchronisable::getSize(int mode){
     283  int Synchronisable::getSize(unsigned int id, int mode){
     284    if(!isMyTick(id))
     285      return 0;
    411286    int tsize=0;
    412287    if(mode==0x0)
     
    435310   * @return amount of bytes
    436311   */
    437   int Synchronisable::getSize2(int mode){
    438     return 3*sizeof(unsigned int) + getSize( mode );
     312  int Synchronisable::getSize2(unsigned int id, int mode){
     313    return sizeof(synchronisableHeader) + getSize( id, mode );
     314  }
     315 
     316  bool Synchronisable::isMyTick(unsigned int id){
     317//     return true;
     318    return id==0 || id%objectFrequency_==objectID%objectFrequency_;
    439319  }
    440320 
  • code/branches/network/src/network/Synchronisable.h

    r1735 r1742  
    4343  };
    4444
    45   struct syncData{
    46     unsigned int length;
     45  struct synchronisableHeader{
     46    unsigned int size;
    4747    unsigned int objectID;
    4848    unsigned int classID;
    49     unsigned char *data;
    5049  };
    5150
     
    7372
    7473    void registerVar(void *var, int size, variableType t, int mode=1, NetworkCallbackBase *cb=0);
    75     //  syncData getData();
    76     syncData getData(unsigned char *mem, int mode=0x0);
    77     bool getData2(unsigned char*& men, int mode=0x0);
    78     //bool getData(Bytestream& bs, int mode=0x0);
    79     int getSize(int mode=0x0);
    80     int getSize2(int mode=0x0);
    81     bool updateData(syncData vars, int mode=0x0);
     74    bool getData(unsigned char*& men, unsigned int id, int mode=0x0);
     75    int getSize2(unsigned int id, int mode=0x0);
    8276    bool updateData(unsigned char*& mem, int mode=0x0);
    8377    bool isMyData(unsigned char* mem);
     
    9286    Synchronisable();
    9387  private:
    94     /*  bool removeObject(Iterator<Synchronisable> it);*/
    95 
     88    int getSize(unsigned int id, int mode=0x0);
     89    bool isMyTick(unsigned int id);
    9690    std::list<synchronisableVariable *> *syncList;
    9791    int datasize;
    9892    static int state_; // detemines wheter we are server (default) or client
    9993    bool backsync_; // if true the variables with mode > 1 will be synchronised to server (client -> server)
     94    unsigned int objectFrequency_;
    10095  };
    10196}
  • code/branches/network/src/network/packet/Gamestate.cc

    r1741 r1742  
    6262{
    6363  int tempsize=0, currentsize=0;
    64   assert(data_==0 /*&& bs_==0*/);
    65   int size = calcGamestateSize(mode);
     64  assert(data_==0);
     65  int size = calcGamestateSize(id, mode);
    6666 
    6767  COUT(4) << "G.ST.Man: producing gamestate with id: " << id << std::endl;
    68     //retval->data = (unsigned char*)malloc(size);
    6968  if(size==0)
    7069    return false;
    7170  data_ = new unsigned char[size + sizeof(GamestateHeader)];
    72   //bs_ = new Bytestream(data_+sizeof(GamestateHeader), size);
    7371  if(!data_){
    7472    COUT(2) << "GameStateManager: could not allocate memory" << std::endl;
     
    8179  orxonox::Iterator<Synchronisable> it;
    8280  for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it){
    83     tempsize=it->getSize2(mode);
     81    tempsize=it->getSize2(id, mode);
    8482   
    8583    if(currentsize+tempsize > size){
     
    8987      int addsize=tempsize;
    9088      while(++temp)
    91         addsize+=temp->getSize2(mode);
     89        addsize+=temp->getSize2(id, mode);
    9290      data_ = (unsigned char *)realloc(data_, sizeof(GamestateHeader) + currentsize + addsize);
    9391      if(!data_)
     
    9694    }// stop allocate additional memory
    9795
    98     if(!it->getData2(mem, mode))
     96    if(!it->getData(mem, id, mode))
    9997      return false; // mem pointer gets automatically increased because of call by reference
    10098    // increase size counter by size of current synchronisable
     
    199197{
    200198  assert(HEADER);
     199  assert(!HEADER->compressed);
    201200  uLongf buffer = (uLongf)(((HEADER->normsize + 12)*1.01)+1);
    202201  if(buffer==0)
     
    228227
    229228  //copy and modify header
     229#ifndef NDEBUG
     230  HEADER->crc32 = calcCRC(data_+sizeof(GamestateHeader), HEADER->normsize);
     231#endif
    230232  *GAMESTATE_HEADER(ndata) = *HEADER;
    231233  //delete old data
     
    241243bool Gamestate::decompressData()
    242244{
     245  assert(HEADER);
    243246  assert(HEADER->compressed);
    244247  COUT(3) << "GameStateClient: uncompressing gamestate. id: " << HEADER->id << ", baseid: " << HEADER->base_id << ", normsize: " << HEADER->normsize << ", compsize: " << HEADER->compsize << std::endl;
     
    261264    case Z_DATA_ERROR: COUT(2) << "data corrupted (zlib)" << std::endl; return false;
    262265  }
     266#ifndef NDEBUG
     267  assert(HEADER->crc32==calcCRC(ndata+sizeof(GamestateHeader), HEADER->normsize));
     268#endif
    263269 
    264270  //copy over the header
     
    276282Gamestate *Gamestate::diff(Gamestate *base)
    277283{
     284  assert(HEADER);
     285  assert(!HEADER->compressed);
     286  assert(!HEADER->diffed);
    278287  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
    279288  unsigned char *basep = GAMESTATE_START(base->data_), *gs = GAMESTATE_START(this->data_);
     
    310319Gamestate *Gamestate::undiff(Gamestate *base)
    311320{
    312   assert(this && base);
     321  assert(this && base);assert(HEADER);
     322  assert(HEADER->diffed);
    313323  assert(!HEADER->compressed && !GAMESTATE_HEADER(base->data_)->compressed);
    314324  //unsigned char *basep = base->getGs()/*, *gs = getGs()*/;
     
    346356
    347357
    348 unsigned int Gamestate::calcGamestateSize(int mode)
     358unsigned int Gamestate::calcGamestateSize(unsigned int id, int mode)
    349359{
    350360  int size=0;
     
    353363    // get total size of gamestate
    354364  for(it = orxonox::ObjectList<Synchronisable>::start(); it; ++it)
    355     size+=it->getSize2(mode); // size of the actual data of the synchronisable
     365    size+=it->getSize2(id, mode); // size of the actual data of the synchronisable
    356366//  size+=sizeof(GamestateHeader);
    357367  return size;
  • code/branches/network/src/network/packet/Gamestate.h

    r1741 r1742  
    2929#include "Packet.h"
    3030#include "network/Synchronisable.h"
    31 //#include "util/Bytestream.h"
     31#ifndef NDEBUG
     32#include "util/CRC32.h"
     33#endif
    3234#include "core/CoreIncludes.h"
    3335
     
    4850  bool complete; // wheter it is a complete gamestate or only partial
    4951  bool compressed;
     52#ifndef NDEBUG
     53  uint32_t crc32;
     54#endif
    5055};
    5156
     
    7782    bool operator ==(packet::Gamestate gs);
    7883  private:
    79     unsigned int calcGamestateSize(int mode=0x0);
     84    unsigned int calcGamestateSize(unsigned int id, int mode=0x0);
    8085    void removeObject(orxonox::Iterator<Synchronisable> &it);
    8186
  • code/branches/network/src/orxonox/objects/SpaceShip.cc

    r1735 r1742  
    243243
    244244        // START CREATING ADDITIONAL EFFECTS
    245         this->backlight_ = new Backlight(this->maxSpeed_, 0.8);
    246         this->attachObject(this->backlight_);
    247         this->backlight_->setPosition(-2.35, 0, 0.2);
    248         this->backlight_->setColour(this->getProjectileColour());
    249 
    250         this->smoke_ = new ParticleSpawner();
    251         this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3);
    252         this->attachObject(this->smoke_);
    253 
    254         this->fire_ = new ParticleSpawner();
    255         this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1);
    256         this->attachObject(this->fire_);
     245        /*if(!network::Host::running() || network::Host::isServer()){
     246          this->backlight_ = new Backlight(this->maxSpeed_, 0.8);
     247          this->attachObject(this->backlight_);
     248          this->backlight_->setPosition(-2.35, 0, 0.2);
     249          this->backlight_->setColour(this->getProjectileColour());
     250   
     251          this->smoke_ = new ParticleSpawner();
     252          this->smoke_->setParticle("Orxonox/smoke5", LODParticle::normal, 0, 0, 3);
     253          this->attachObject(this->smoke_);
     254   
     255          this->fire_ = new ParticleSpawner();
     256          this->fire_->setParticle("Orxonox/fire3", LODParticle::normal, 0, 0, 1);
     257          this->attachObject(this->fire_);
     258        }*/
    257259        // END CREATING ADDITIONAL EFFECTS
    258260
  • code/branches/network/src/util/CMakeLists.txt

    r1505 r1742  
    22  ArgReader.cc
    33  Clipboard.cc
     4  CRC32.cc
    45  ExprParser.cc
    56  Math.cc
Note: See TracChangeset for help on using the changeset viewer.