Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5916 for code/branches


Ignore:
Timestamp:
Oct 9, 2009, 4:41:30 PM (15 years ago)
Author:
scheusso
Message:

some cleaning up in the network
more to come

Location:
code/branches/core5/src
Files:
13 edited

Legend:

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

    r5855 r5916  
    4949#include "packet/Gamestate.h"
    5050#include "FunctionCallManager.h"
     51#include "core/CoreIncludes.h"
     52#include "core/Game.h"
    5153
    5254namespace orxonox
     
    158160    return;
    159161  }
     162 
     163  void Client::connectionClosed()
     164  {
     165    ObjectList<Synchronisable>::iterator it;
     166    for(it = ObjectList<Synchronisable>::begin(); it; )
     167    {
     168      if( it->getSyncMode() != 0x0 )
     169        (it++)->destroy();
     170      else
     171      {
     172        Synchronisable* blub = *it;
     173        ++it;
     174      }
     175    }
     176    Game::getInstance().popState();
     177    Game::getInstance().popState();
     178  }
    160179
    161180}
  • code/branches/core5/src/libraries/network/Client.h

    r5865 r5916  
    7474
    7575    void update(const Clock& time);
    76 
     76  protected:
     77    virtual void connectionClosed();
    7778  private:
    7879    Client(const Client& copy); // not used
  • code/branches/core5/src/libraries/network/ClientConnection.cc

    r5851 r5916  
    118118          case ENET_EVENT_TYPE_DISCONNECT:
    119119            COUT(4) << "received disconnect confirmation from server" << endl;
     120            this->connectionClosed();
    120121            return true;
    121122        }
     
    123124    }
    124125    enet_peer_reset( this->server_ );
     126    this->connectionClosed();
    125127    return false;
    126128  }
     
    142144    COUT(1) << "Received disconnect Packet from Server!" << endl;
    143145        // server closed the connection
     146    this->connectionClosed();
    144147  }
    145148
  • code/branches/core5/src/libraries/network/ClientConnection.h

    r5851 r5916  
    5353    bool addPacket(ENetPacket *packet);
    5454    inline bool isConnected(){ return this->established_; }
     55  protected:
     56    virtual void connectionClosed()=0;
    5557  private:
    5658    virtual void addPeer(ENetEvent* event);
  • code/branches/core5/src/libraries/network/synchronisable/Synchronisable.cc

    r5839 r5916  
    4747  /**
    4848  * Constructor:
    49   * Initializes all Variables and sets the right objectID
     49  * Initializes all Variables and sets the right objectID_
    5050  */
    51   Synchronisable::Synchronisable(BaseObject* creator){
     51  Synchronisable::Synchronisable(BaseObject* creator ){
    5252    RegisterRootObject(Synchronisable);
    5353    static uint32_t idCounter=0;
     
    5555    if ( GameMode::isMaster() || ( Host::running() && Host::isServer() ) )
    5656    {
    57       this->objectID = idCounter++; //this is only needed when running a server
    58     //add synchronisable to the objectMap
    59       objectMap_[this->objectID] = this;
     57      this->setObjectID( idCounter++ );
    6058    }
    6159    else
    6260    {
    63       objectID=OBJECTID_UNKNOWN;
    64       this->setObjectMode(0x0);   //make sure this object doesn't get synchronized
    65     }
    66     classID = static_cast<uint32_t>(-1);
     61      objectID_=OBJECTID_UNKNOWN;
     62    }
     63    classID_ = static_cast<uint32_t>(-1);
    6764   
    6865    // set dataSize to 0
     
    7370    // get creator id
    7471    if( creator )
    75       this->creatorID = creator->getSceneID();
     72      this->creatorID_ = creator->getSceneID();
    7673    else
    77       this->creatorID = OBJECTID_UNKNOWN;
     74      this->creatorID_ = OBJECTID_UNKNOWN;
    7875
    7976    /*searchcreatorID:
     
    9592  /**
    9693   * Destructor:
    97    * Delete all callback objects and remove objectID from the objectMap_
     94   * Delete all callback objects and remove objectID_ from the objectMap_
    9895   */
    9996  Synchronisable::~Synchronisable(){
     
    10299      // remove object from the static objectMap
    103100      if (this->objectMode_ != 0x0 && (Host::running() && Host::isServer()))
    104         deletedObjects_.push(objectID);
     101        deletedObjects_.push(objectID_);
    105102    }
    106103    // delete all Synchronisable Variables from syncList ( which are also in stringList )
     
    110107    stringList.clear();
    111108    std::map<uint32_t, Synchronisable*>::iterator it;
    112     it = objectMap_.find(objectID);
     109    it = objectMap_.find(objectID_);
    113110    if (it != objectMap_.end())
    114111      objectMap_.erase(it);
     
    175172    Synchronisable *no = orxonox_cast<Synchronisable*>(bo);
    176173    assert(no);
    177     no->objectID=header.getObjectID();
     174    assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() );
     175    no->setObjectID(header.getObjectID());
    178176    //no->creatorID=header.getCreatorID(); //TODO: remove this
    179     no->classID=header.getClassID();
    180     assert(no->creatorID == header.getCreatorID());
    181     //assert(no->classID == header.getClassID());
    182     COUT(4) << "fabricate objectID: " << no->objectID << " classID: " << no->classID << std::endl;
     177    no->setClassID(header.getClassID());
     178    assert(no->creatorID_ == header.getCreatorID());
     179    //assert(no->classID_ == header.getClassID());
     180    COUT(4) << "fabricate objectID_: " << no->objectID_ << " classID_: " << no->classID_ << std::endl;
    183181          // update data and create object/entity...
    184     assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() );
    185     Synchronisable::objectMap_[header.getObjectID()] = no;
    186182    bool b = no->updateData(mem, mode, true);
    187183    assert(b);
     
    196192
    197193  /**
    198    * Finds and deletes the Synchronisable with the appropriate objectID
    199    * @param objectID objectID of the Synchronisable
     194   * Finds and deletes the Synchronisable with the appropriate objectID_
     195   * @param objectID_ objectID_ of the Synchronisable
    200196   * @return true/false
    201197   */
    202   bool Synchronisable::deleteObject(uint32_t objectID){
    203     if(!getSynchronisable(objectID))
     198  bool Synchronisable::deleteObject(uint32_t objectID_){
     199    if(!getSynchronisable(objectID_))
    204200      return false;
    205     assert(getSynchronisable(objectID)->objectID==objectID);
    206     Synchronisable *s = getSynchronisable(objectID);
     201    assert(getSynchronisable(objectID_)->objectID_==objectID_);
     202    Synchronisable *s = getSynchronisable(objectID_);
    207203    if(s)
    208204      s->destroy(); // or delete?
     
    213209
    214210  /**
    215    * This function looks up the objectID in the objectMap_ and returns a pointer to the right Synchronisable
    216    * @param objectID objectID of the Synchronisable
    217    * @return pointer to the Synchronisable with the objectID
    218    */
    219   Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID){
     211   * This function looks up the objectID_ in the objectMap_ and returns a pointer to the right Synchronisable
     212   * @param objectID_ objectID_ of the Synchronisable
     213   * @return pointer to the Synchronisable with the objectID_
     214   */
     215  Synchronisable* Synchronisable::getSynchronisable(uint32_t objectID_){
    220216    std::map<uint32_t, Synchronisable*>::iterator it1;
    221     it1 = objectMap_.find(objectID);
     217    it1 = objectMap_.find(objectID_);
    222218    if (it1 != objectMap_.end())
    223219      return it1->second;
     
    225221//     ObjectList<Synchronisable>::iterator it;
    226222//     for(it = ObjectList<Synchronisable>::begin(); it; ++it){
    227 //       if( it->getObjectID()==objectID ){
    228 //         objectMap_[objectID] = *it;
     223//       if( it->getObjectID()==objectID_ ){
     224//         objectMap_[objectID_] = *it;
    229225//         return *it;
    230226//       }
     
    236232
    237233  /**
    238    * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID and classID to the given memory
     234   * This function takes all SynchronisableVariables out of the Synchronisable and saves them together with the size, objectID_ and classID_ to the given memory
    239235   * takes a pointer to already allocated memory (must have at least getSize bytes length)
    240236   * structure of the bitstream:
    241    * |totalsize,objectID,classID,var1,var2,string1_length,string1,var3,...|
     237   * |totalsize,objectID_,classID_,var1,var2,string1_length,string1,var3,...|
    242238   * length of varx: size saved int syncvarlist
    243239   * @param mem pointer to allocated memory with enough size
     
    257253    uint32_t tempsize = 0;
    258254#ifndef NDEBUG
    259     if (this->classID==0)
     255    if (this->classID_==0)
    260256      COUT(3) << "classid 0 " << this->getIdentifier()->getName() << std::endl;
    261257#endif
    262258
    263     if (this->classID == static_cast<uint32_t>(-1))
    264         this->classID = this->getIdentifier()->getNetworkID();
    265 
    266     assert(ClassByID(this->classID));
    267     assert(this->classID==this->getIdentifier()->getNetworkID());
     259    if (this->classID_ == static_cast<uint32_t>(-1))
     260        this->classID_ = this->getIdentifier()->getNetworkID();
     261
     262    assert(ClassByID(this->classID_));
     263    assert(this->classID_==this->getIdentifier()->getNetworkID());
     264    assert(this->objectID_!=OBJECTID_UNKNOWN);
    268265    std::vector<SynchronisableVariableBase*>::iterator i;
    269266
     
    274271
    275272
    276     COUT(5) << "Synchronisable getting data from objectID: " << objectID << " classID: " << classID << std::endl;
     273    COUT(5) << "Synchronisable getting data from objectID_: " << objectID_ << " classID_: " << classID_ << std::endl;
    277274    // copy to location
    278275    for(i=syncList.begin(); i!=syncList.end(); ++i){
     
    282279   
    283280    tempsize += SynchronisableHeader::getSize();
    284     header.setObjectID( this->objectID );
    285     header.setCreatorID( this->creatorID );
    286     header.setClassID( this->classID );
     281    header.setObjectID( this->objectID_ );
     282    header.setCreatorID( this->creatorID_ );
     283    header.setClassID( this->classID_ );
    287284    header.setDataAvailable( true );
    288285    header.setDataSize( tempsize );
     
    316313    // start extract header
    317314    SynchronisableHeader syncHeader(mem);
    318     assert(syncHeader.getObjectID()==this->objectID);
    319     assert(syncHeader.getCreatorID()==this->creatorID);
    320     assert(syncHeader.getClassID()==this->classID);
     315    assert(syncHeader.getObjectID()==this->objectID_);
     316    assert(syncHeader.getCreatorID()==this->creatorID_);
     317    assert(syncHeader.getClassID()==this->classID_);
    321318    if(syncHeader.isDataAvailable()==false){
    322319      mem += syncHeader.getDataSize();
     
    327324    // stop extract header
    328325
    329     //COUT(5) << "Synchronisable: objectID " << syncHeader.getObjectID() << ", classID " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
     326    //COUT(5) << "Synchronisable: objectID_ " << syncHeader.getObjectID() << ", classID_ " << syncHeader.getClassID() << " size: " << syncHeader.getDataSize() << " synchronising data" << std::endl;
    330327    for(i=syncList.begin(); i!=syncList.end(); i++)
    331328    {
     
    366363    if(mode==0x0)
    367364      mode=state_;
    368     return ( (objectMode_&mode)!=0 && (!syncList.empty() ) );
    369   }
    370 
    371   /**
    372    * This function looks at the header located in the bytestream and checks wheter objectID and classID match with the Synchronisables ones
     365    return ( (this->objectMode_ & mode)!=0 && (!syncList.empty() ) );
     366  }
     367
     368  /**
     369   * This function looks at the header located in the bytestream and checks wheter objectID_ and classID_ match with the Synchronisables ones
    373370   * @param mem pointer to the bytestream
    374371   */
     
    376373  {
    377374    SynchronisableHeader header(mem);
    378     assert(header.getObjectID()==this->objectID);
     375    assert(header.getObjectID()==this->objectID_);
    379376    return header.isDataAvailable();
    380377  }
     
    388385   * @param mode same as in registerVar
    389386   */
    390   void Synchronisable::setObjectMode(uint8_t mode){
     387  void Synchronisable::setSyncMode(uint8_t mode){
    391388    assert(mode==0x0 || mode==0x1 || mode==0x2 || mode==0x3);
    392     objectMode_=mode;
     389    this->objectMode_=mode;
    393390  }
    394391
  • code/branches/core5/src/libraries/network/synchronisable/Synchronisable.h

    r5738 r5916  
    6868   * @brief: stores information about a Synchronisable
    6969   *
    70    * This class stores the information about a Synchronisable (objectID, classID, creatorID, dataSize)
     70   * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)
    7171   * in an emulated bitset.
    7272   * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
    7373   * Bit 32 is a bool and defines whether the data is actually stored or is just filled up with 0
    74    * Byte 5 to 8: objectID
    75    * Byte 9 to 12: classID
    76    * Byte 13 to 16: creatorID
     74   * Byte 5 to 8: objectID_
     75   * Byte 9 to 12: classID_
     76   * Byte 13 to 16: creatorID_
    7777   */
    7878  class _NetworkExport SynchronisableHeader{
     
    9494      inline uint32_t getObjectID() const
    9595        { return *(uint32_t*)(data_+4); }
    96       inline void setObjectID(uint32_t objectID)
    97         { *(uint32_t*)(data_+4) = objectID; }
     96      inline void setObjectID(uint32_t objectID_)
     97        { *(uint32_t*)(data_+4) = objectID_; }
    9898      inline uint32_t getClassID() const
    9999        { return *(uint32_t*)(data_+8); }
    100       inline void setClassID(uint32_t classID)
    101         { *(uint32_t*)(data_+8) = classID; }
     100      inline void setClassID(uint32_t classID_)
     101        { *(uint32_t*)(data_+8) = classID_; }
    102102      inline uint32_t getCreatorID() const
    103103        { return *(uint32_t*)(data_+12); }
    104       inline void setCreatorID(uint32_t creatorID)
    105         { *(uint32_t*)(data_+12) = creatorID; }
     104      inline void setCreatorID(uint32_t creatorID_)
     105        { *(uint32_t*)(data_+12) = creatorID_; }
    106106      inline void operator=(SynchronisableHeader& h)
    107107        { memcpy(data_, h.data_, getSize()); }
     
    122122
    123123    static Synchronisable *fabricate(uint8_t*& mem, uint8_t mode=0x0);
    124     static bool deleteObject(uint32_t objectID);
    125     static Synchronisable *getSynchronisable(uint32_t objectID);
     124    static bool deleteObject(uint32_t objectID_);
     125    static Synchronisable *getSynchronisable(uint32_t objectID_);
    126126    static unsigned int getNumberOfDeletedObject(){ return deletedObjects_.size(); }
    127127    static uint32_t popDeletedObject(){ uint32_t i = deletedObjects_.front(); deletedObjects_.pop(); return i; }
    128128
    129     inline uint32_t getObjectID() const {return objectID;}
    130     inline unsigned int getCreatorID() const {return creatorID;}
    131     inline uint32_t getClassID() const {return classID;}
    132     inline unsigned int getPriority() const { return objectFrequency_;}
     129    inline uint32_t getObjectID() const {return this->objectID_;}
     130    inline unsigned int getCreatorID() const {return this->creatorID_;}
     131    inline uint32_t getClassID() const {return this->classID_;}
     132    inline unsigned int getPriority() const { return this->objectFrequency_;}
     133    inline uint8_t getSyncMode() const { return this->objectMode_; }
     134   
     135    void setSyncMode(uint8_t mode);
    133136
    134137  protected:
     
    136139    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
    137140    //template <class T> void unregisterVariable(T& var);
    138     void setObjectMode(uint8_t mode);
    139141    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
    140142
     
    146148    bool isMyData(uint8_t* mem);
    147149    bool doSync(int32_t id, uint8_t mode=0x0);
    148 
    149     uint32_t objectID;
    150     uint32_t creatorID;
    151     uint32_t classID;
     150   
     151    inline void setObjectID(uint32_t id){ this->objectID_ = id; objectMap_[this->objectID_] = this; }
     152    inline void setClassID(uint32_t id){ this->classID_ = id; }
     153
     154    uint32_t objectID_;
     155    uint32_t creatorID_;
     156    uint32_t classID_;
    152157
    153158    std::vector<SynchronisableVariableBase*> syncList;
  • code/branches/core5/src/modules/objects/triggers/Trigger.cc

    r5738 r5916  
    7272    }
    7373
    74     this->setObjectMode(0x0);
     74    this->setSyncMode(0x0);
    7575  }
    7676
  • code/branches/core5/src/orxonox/graphics/Camera.cc

    r5911 r5916  
    6868        this->nearClipDistance_ = 1;
    6969
    70         this->setObjectMode(0x0);
     70        this->setSyncMode(0x0);
    7171
    7272        this->setConfigValues();
  • code/branches/core5/src/orxonox/infos/HumanPlayer.cc

    r5846 r5916  
    116116
    117117            if (!GameMode::isMaster())
    118                 this->setObjectMode(ObjectDirection::Bidirectional);
     118                this->setSyncMode(ObjectDirection::Bidirectional);
    119119            else
    120120                this->setName(this->nick_);
  • code/branches/core5/src/orxonox/worldentities/CameraPosition.cc

    r5738 r5916  
    4646        this->bRenderCamera_ = false;
    4747
    48         this->setObjectMode(0x0);
     48        this->setSyncMode(0x0);
    4949    }
    5050
  • code/branches/core5/src/orxonox/worldentities/ControllableEntity.cc

    r5894 r5916  
    238238            {
    239239                this->client_overwrite_ = this->server_overwrite_;
    240                 this->setObjectMode(ObjectDirection::Bidirectional);
     240                this->setSyncMode(ObjectDirection::Bidirectional);
    241241            }
    242242        }
     
    254254        this->bHasLocalController_ = false;
    255255        this->bHasHumanController_ = false;
    256         this->setObjectMode(ObjectDirection::ToClient);
     256        this->setSyncMode(ObjectDirection::ToClient);
    257257
    258258        this->changedPlayer();
  • code/branches/core5/src/orxonox/worldentities/SpawnPoint.cc

    r5738 r5916  
    5050            COUT(1) << "Error: SpawnPoint has no Gametype" << std::endl;
    5151
    52         this->setObjectMode(0x0);
     52        this->setSyncMode(0x0);
    5353    }
    5454
  • code/branches/core5/src/orxonox/worldentities/pawns/Spectator.cc

    r5738 r5916  
    145145        ControllableEntity::setPlayer(player);
    146146
    147 //        this->setObjectMode(ObjectDirection::ToClient);
     147//        this->setSyncMode(ObjectDirection::ToClient);
    148148    }
    149149
Note: See TracChangeset for help on using the changeset viewer.