Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 12, 2008, 5:36:57 PM (16 years ago)
Author:
scheusso
Message:

we have a new gamestate concept now: dont transmit synchronisable header of objects, that dont get updated that tick. transmit objectids of deleted objects to delete them on the client too

File:
1 edited

Legend:

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

    r1758 r1775  
    5252{
    5353
     54  std::map<unsigned int, Synchronisable *> Synchronisable::objectMap_;
     55  std::queue<unsigned int> Synchronisable::deletedObjects_;
    5456
    5557  int Synchronisable::state_=0x1; // detemines wheter we are server (default) or client
     
    6163  Synchronisable::Synchronisable(){
    6264    RegisterRootObject(Synchronisable);
    63     static int idCounter=0;
     65    static unsigned int idCounter=0;
    6466    datasize=0;
    6567    objectFrequency_=1;
     
    6769    objectID=idCounter++;
    6870    syncList = new std::list<synchronisableVariable *>;
    69     //registerAllVariables();
    7071  }
    7172
    7273  Synchronisable::~Synchronisable(){
    7374    // delete callback function objects
    74     if(!orxonox::Identifier::isCreatingHierarchy())
     75    if(!orxonox::Identifier::isCreatingHierarchy()){
    7576      for(std::list<synchronisableVariable *>::iterator it = syncList->begin(); it!=syncList->end(); it++)
    7677        delete (*it)->callback;
     78      assert(objectMap_[objectID]->objectID==objectID);
     79      objectMap_.erase(objectID);
     80    }
    7781  }
    7882
    7983  bool Synchronisable::create(){
     84    objectMap_[objectID]=this;
     85    assert(objectMap_[objectID]==this);
    8086    this->classID = this->getIdentifier()->getNetworkID();
    8187    COUT(4) << "creating synchronisable: setting classid from " << this->getIdentifier()->getName() << " to: " << classID << std::endl;
     
    9197  }
    9298 
    93   bool Synchronisable::fabricate(unsigned char*& mem, int mode)
     99  Synchronisable *Synchronisable::fabricate(unsigned char*& mem, int mode)
    94100  {
    95101    unsigned int size, objectID, classID;
     
    98104    classID = *(unsigned int*)(mem+2*sizeof(unsigned int));
    99105   
    100     if(size==3*sizeof(unsigned int)){ //not our turn, dont do anything
    101       mem+=3*sizeof(unsigned int);
    102       return true;
    103     }
    104    
    105106    orxonox::Identifier* id = GetIdentifier(classID);
    106     if(!id){
    107       COUT(3) << "We could not identify a new object; classid: " << classID << " uint: " << (unsigned int)classID << " objectID: " << objectID << " size: " << size << std::endl;
    108       assert(0);
    109       return false; // most probably the gamestate is corrupted
    110     }
     107    assert(id);
    111108    orxonox::BaseObject *bo = id->fabricate();
    112109    Synchronisable *no = dynamic_cast<Synchronisable *>(bo);
     
    116113    COUT(3) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
    117114          // update data and create object/entity...
    118     if( !no->updateData(mem, mode) ){
    119       COUT(1) << "We couldn't update the object: " << objectID << std::endl;
    120       return false;
    121     }
    122     if( !no->create() )
    123     {
    124       COUT(1) << "We couldn't manifest (create() ) the object: " << objectID << std::endl;
    125       return false;
    126     }
     115    assert(no->updateData(mem, mode));
     116    assert( no->create() );
     117    return no;
     118  }
     119
     120 
     121  bool Synchronisable::deleteObject(unsigned int objectID){
     122    assert(getSynchronisable(objectID));
     123    assert(getSynchronisable(objectID)->objectID==objectID);
     124    delete objectMap_[objectID];
    127125    return true;
    128126  }
    129 
     127 
     128  Synchronisable* Synchronisable::getSynchronisable(unsigned int objectID){
     129    std::map<unsigned int, Synchronisable *>::iterator i = objectMap_.find(objectID);
     130    if(i==objectMap_.end())
     131      return NULL;
     132    assert(i->second->objectID==objectID);
     133    return (*i).second;
     134  }
     135
     136 
    130137  /**
    131138  * This function is used to register a variable to be synchronized
     
    161168   */
    162169  bool Synchronisable::getData(unsigned char*& mem, unsigned int id, int mode){
     170    //if this tick is we dont synchronise, then abort now
     171    if(!isMyTick(id))
     172      return true;
    163173    //std::cout << "inside getData" << std::endl;
    164174    unsigned int tempsize = 0;
     
    170180    std::list<synchronisableVariable *>::iterator i;
    171181    unsigned int size;
    172     size=getSize2(id, mode);
     182    size=getSize(id, mode);
    173183   
    174184    // start copy header
     
    182192    // end copy header
    183193   
    184     //if this tick is we dont synchronise, then abort now
    185     if(!isMyTick(id))
    186       return true;
    187194   
    188195    COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << " length: " << size << std::endl;
     
    222229   */
    223230  bool Synchronisable::updateData(unsigned char*& mem, int mode){
    224     unsigned char *data = mem;
    225231    if(mode==0x0)
    226232      mode=state_;
     
    230236      return false;
    231237    }
    232    
     238    unsigned char *data=mem;
    233239    // start extract header
     240    if(!isMyData(mem))
     241      return true;
    234242    unsigned int objectID, classID, size;
    235243    size = *(int *)mem;
     
    242250    assert(this->objectID==objectID);
    243251    assert(this->classID==classID);
    244     if(size==3*sizeof(unsigned int)) //if true, only the header is available
    245       return true;
    246       //assert(0);
    247252   
    248253    COUT(5) << "Synchronisable: objectID " << objectID << ", classID " << classID << " size: " << size << " synchronising data" << std::endl;
     
    288293    if(!isMyTick(id))
    289294      return 0;
    290     int tsize=0;
     295    int tsize=sizeof(synchronisableHeader);
    291296    if(mode==0x0)
    292297      mode=state_;
     
    311316
    312317  /**
    313    * This function returns the total amount of bytes needed by getData to save the whole content of the variables
    314    * @return amount of bytes
    315    */
    316   int Synchronisable::getSize2(unsigned int id, int mode){
    317     return sizeof(synchronisableHeader) + getSize( id, mode );
    318   }
    319  
    320   /**
    321318   *
    322319   * @param id
Note: See TracChangeset for help on using the changeset viewer.