Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 9, 2013, 9:26:46 PM (12 years ago)
Author:
landauf
Message:

BaseObject now requires a Context instead of a creator (BaseObject*) in its constructor.
Namespace, Level, and Scene inherit from Context

File:
1 edited

Legend:

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

    r9564 r9629  
    4949  * Initializes all Variables and sets the right objectID_
    5050  */
    51   Synchronisable::Synchronisable(BaseObject* creator )
     51  Synchronisable::Synchronisable(Context* context)
    5252  {
    5353    RegisterRootObject(Synchronisable);
     
    6969    this->setPriority( Priority::Normal );
    7070
    71     // get creator id
    72     if( creator )
    73       this->creatorID_ = creator->getSceneID();
    74     else
    75       this->creatorID_ = OBJECTID_UNKNOWN;
     71    // get context id
     72    this->contextID_ = this->findContextID(context);
    7673  }
    7774
     
    10097  }
    10198
     99  /**
     100   * @brief Returns the id of the context.
     101   * If the context is not Synchronisable, it moves on to its parent, recursively.
     102   */
     103  uint32_t Synchronisable::findContextID(Context* context)
     104  {
     105      if (context == NULL)
     106          return OBJECTID_UNKNOWN;
     107
     108      Synchronisable* synchronisableContext = orxonox_cast<Synchronisable*>(context);
     109      if (synchronisableContext != NULL)
     110          return synchronisableContext->getObjectID();
     111      else
     112          return this->findContextID(context->getParentContext());
     113  }
    102114
    103115  /**
     
    142154    }
    143155    assert(id);
    144     BaseObject* creator = 0;
    145     if (header.getCreatorID() != OBJECTID_UNKNOWN)
    146     {
    147       Synchronisable* synchronisable_creator = Synchronisable::getSynchronisable(header.getCreatorID());
    148       if (!synchronisable_creator)
     156    Context* context = 0;
     157    if (header.getContextID() != OBJECTID_UNKNOWN)
     158    {
     159      Synchronisable* synchronisable_context = Synchronisable::getSynchronisable(header.getContextID());
     160      if (!synchronisable_context)
    149161      {
    150162        mem += header.getDataSize()+SynchronisableHeader::getSize(); //.TODO: this suckz.... remove size from header
     
    153165      }
    154166      else
    155         creator = orxonox_cast<BaseObject*>(synchronisable_creator);
     167        context = orxonox_cast<Context*>(synchronisable_context);
    156168    }
    157169    assert(getSynchronisable(header.getObjectID())==0);   //make sure no object with this id exists
    158     BaseObject *bo = orxonox_cast<BaseObject*>(id->fabricate(creator));
     170    BaseObject *bo = orxonox_cast<BaseObject*>(id->fabricate(context));
    159171    assert(bo);
    160172    Synchronisable *no = orxonox_cast<Synchronisable*>(bo);
     
    162174    assert( Synchronisable::objectMap_.find(header.getObjectID()) == Synchronisable::objectMap_.end() );
    163175    no->setObjectID(header.getObjectID());
    164     //no->creatorID=header.getCreatorID(); //TODO: remove this
     176    //no->contextID=header.getContextID(); //TODO: remove this
    165177    no->setClassID(header.getClassID());
    166     assert(no->creatorID_ == header.getCreatorID());
    167     if( creator )
    168       bo->setLevel(creator->getLevel());          // Note: this ensures that the level is known on the client for child objects of the scene (and the scene itself)
     178    assert(no->contextID_ == header.getContextID());
     179    if( context )
     180    {
     181      BaseObject* boContext = orxonox_cast<BaseObject*>(context);
     182      if (boContext)
     183          bo->setLevel(boContext->getLevel()); // Note: this ensures that the level is known on the client for child objects of the scene (and the scene itself)
     184    }
    169185    //assert(no->classID_ == header.getClassID());
    170186    orxout(verbose, context::network) << "fabricate objectID_: " << no->objectID_ << " classID_: " << no->classID_ << endl;
     
    274290
    275291    header.setObjectID( this->objectID_ );
    276     header.setCreatorID( this->creatorID_ );
     292    header.setContextID( this->contextID_ );
    277293    header.setClassID( this->classID_ );
    278294    header.setDataSize( tempsize );
     
    331347      SynchronisableHeader syncHeader2(mem);
    332348      assert( this->getClassID() == syncHeader2.getClassID() );
    333       assert( this->getCreatorID() == syncHeader2.getCreatorID() );
     349      assert( this->getContextID() == syncHeader2.getContextID() );
    334350      mem += SynchronisableHeader::getSize();
    335351      std::vector<SynchronisableVariableBase *>::iterator i;
Note: See TracChangeset for help on using the changeset viewer.