Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 9, 2013, 9:26:46 PM (11 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

Location:
code/branches/core6/src/libraries
Files:
21 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core6/src/libraries/core/BaseObject.cc

    r9590 r9629  
    5555        @brief Constructor: Registers the object in the BaseObject-list.
    5656    */
    57     BaseObject::BaseObject(BaseObject* creator) : bInitialized_(false)
     57    BaseObject::BaseObject(Context* context) : bInitialized_(false)
    5858    {
    5959        RegisterRootObject(BaseObject);
     
    7070        this->mainStateFunctor_ = 0;
    7171
     72        if (context)
     73            this->setContext(context);
     74
     75        BaseObject* creator = orxonox_cast<BaseObject*>(context);
    7276        this->setCreator(creator);
    7377        if (this->creator_)
     
    201205        {
    202206            this->networkTemplateNames_.insert(temp->getLink());
    203            
     207
    204208            Template* link;
    205209            assert(!(link = Template::getTemplate(temp->getLink())) || !link->isLink());
  • code/branches/core6/src/libraries/core/BaseObject.h

    r9607 r9629  
    6565
    6666        public:
    67             BaseObject(BaseObject* creator);
     67            BaseObject(Context* context);
    6868            virtual ~BaseObject();
    6969            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
  • code/branches/core6/src/libraries/core/Loader.cc

    r9557 r9629  
    209209
    210210            orxout(verbose, context::loader) << "  creating root-namespace..." << endl;
    211             Namespace* rootNamespace = new Namespace(0);
     211            Namespace* rootNamespace = new Namespace(Context::getRootContext());
    212212            rootNamespace->setLoaderIndentation("    ");
    213213            rootNamespace->setFile(file);
  • code/branches/core6/src/libraries/core/Namespace.cc

    r7401 r9629  
    4040    CreateFactory(Namespace);
    4141
    42     Namespace::Namespace(BaseObject* creator) : BaseObject(creator),
     42    Namespace::Namespace(Context* context) : BaseObject(context), Context(context),
    4343      bAutogeneratedFileRootNamespace_(false),
    4444      bRoot_(false),
  • code/branches/core6/src/libraries/core/Namespace.h

    r7401 r9629  
    4040#include <string>
    4141#include "BaseObject.h"
     42#include "object/Context.h"
    4243
    4344namespace orxonox
    4445{
    45     class Namespace : public BaseObject
     46    class Namespace : public BaseObject, public Context
    4647    {
    4748        public:
    48             Namespace(BaseObject* creator);
     49            Namespace(Context* context);
    4950            virtual ~Namespace();
    5051
  • code/branches/core6/src/libraries/core/Template.cc

    r9564 r9629  
    4040    CreateFactory(Template);
    4141
    42     Template::Template(BaseObject* creator) : BaseObject(creator)
     42    Template::Template(Context* context) : BaseObject(context)
    4343    {
    4444        this->xmlelement_ = new TiXmlElement("");
  • code/branches/core6/src/libraries/core/Template.h

    r7401 r9629  
    5151    {
    5252        public:
    53             Template(BaseObject* creator);
     53            Template(Context* context);
    5454            virtual ~Template();
    5555
  • code/branches/core6/src/libraries/core/XMLPort.cc

    r9564 r9629  
    8989                        orxout(verbose, context::xml) << object->getLoaderIndentation() << "fabricating " << child->Value() << "..." << endl;
    9090
    91                         BaseObject* newObject = orxonox_cast<BaseObject*>(identifier->fabricate(object));
     91                        BaseObject* newObject = orxonox_cast<BaseObject*>(identifier->fabricate(object->getContext()));
    9292                        newObject->setLoaderIndentation(object->getLoaderIndentation() + "  ");
    9393
  • code/branches/core6/src/libraries/core/class/Identifier.cc

    r9606 r9629  
    174174        @return The new object
    175175    */
    176     OrxonoxClass* Identifier::fabricate(BaseObject* creator)
     176    OrxonoxClass* Identifier::fabricate(Context* context)
    177177    {
    178178        if (this->factory_)
    179179        {
    180             return this->factory_->fabricate(creator);
     180            return this->factory_->fabricate(context);
    181181        }
    182182        else
  • code/branches/core6/src/libraries/core/class/Identifier.h

    r9626 r9629  
    125125            inline bool hasFactory() const { return (this->factory_ != 0); }
    126126
    127             OrxonoxClass* fabricate(BaseObject* creator);
     127            OrxonoxClass* fabricate(Context* context);
    128128
    129129            /// Returns true if the class can be loaded through XML.
  • code/branches/core6/src/libraries/core/class/SubclassIdentifier.h

    r9563 r9629  
    163163
    164164            /// Creates a new object of the type of the assigned Identifier and dynamic_casts it to the minimal type given by T.
    165             T* fabricate(BaseObject* creator) const
    166             {
    167                 OrxonoxClass* newObject = this->identifier_->fabricate(creator);
     165            T* fabricate(Context* context) const
     166            {
     167                OrxonoxClass* newObject = this->identifier_->fabricate(context);
    168168
    169169                // Check if the creation was successful
  • code/branches/core6/src/libraries/core/object/ClassFactory.h

    r9602 r9629  
    5555        public:
    5656            virtual ~Factory() {};
    57             virtual OrxonoxClass* fabricate(BaseObject* creator) = 0;
     57            virtual OrxonoxClass* fabricate(Context* context) = 0;
    5858    };
    5959
     
    8282                @return The new object
    8383            */
    84             inline OrxonoxClass* fabricate(BaseObject* creator)
     84            inline OrxonoxClass* fabricate(Context* context)
    8585            {
    86                 return static_cast<OrxonoxClass*>(new T(creator));
     86                return static_cast<OrxonoxClass*>(new T(context));
    8787            }
    8888    };
  • code/branches/core6/src/libraries/core/object/Context.cc

    r9610 r9629  
    5656    /*static*/ Context* Context::getRootContext()
    5757    {
    58         static Context rootContext;
     58        static Context rootContext(NULL);
    5959        return &rootContext;
    6060    }
  • code/branches/core6/src/libraries/core/object/Context.h

    r9610 r9629  
    4848            static Context* getRootContext();
    4949
    50             Context(Context* context = NULL);
     50            Context(Context* context);
    5151            virtual ~Context();
    5252
  • code/branches/core6/src/libraries/network/packet/Gamestate.cc

    r9579 r9629  
    133133    tempsize = it->getData(mem, this->sizes_, id, mode);
    134134    if ( tempsize != 0 )
    135       dataVector_.push_back( obj(it->getObjectID(), it->getCreatorID(), tempsize, mem-data_) );
     135      dataVector_.push_back( obj(it->getObjectID(), it->getContextID(), tempsize, mem-data_) );
    136136
    137137#ifndef NDEBUG
     
    469469    {
    470470      assert( objectHeader.getClassID() == htemp.getClassID() );
    471       assert( objectHeader.getCreatorID() == htemp.getCreatorID() );
     471      assert( objectHeader.getContextID() == htemp.getContextID() );
    472472      return true;
    473473    }
  • 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;
  • code/branches/core6/src/libraries/network/synchronisable/Synchronisable.h

    r9587 r9629  
    107107   * @brief: stores information about a Synchronisable
    108108   *
    109    * This class stores the information about a Synchronisable (objectID_, classID_, creatorID_, dataSize)
     109   * This class stores the information about a Synchronisable (objectID_, classID_, contextID_, dataSize)
    110110   * in an emulated bitset.
    111111   * Bit 1 to 31 store the size of the Data the synchronisable consumes in the stream
     
    113113   * Byte 5 to 8: objectID_
    114114   * Byte 9 to 12: classID_
    115    * Byte 13 to 16: creatorID_
     115   * Byte 13 to 16: contextID_
    116116   */
    117117  class _NetworkExport SynchronisableHeader: public SynchronisableHeaderLight
     
    126126      inline void setClassID(uint32_t classID_)
    127127        { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()) = classID_; }
    128       inline uint32_t getCreatorID() const
     128      inline uint32_t getContextID() const
    129129        { return *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4); }
    130       inline void setCreatorID(uint32_t creatorID_)
    131         { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4) = creatorID_; }
     130      inline void setContextID(uint32_t contextID_)
     131        { *(uint32_t*)(data_+SynchronisableHeaderLight::getSize()+4) = contextID_; }
    132132      inline void operator=(SynchronisableHeader& h)
    133133        { memcpy(data_, h.data_, getSize()); }
     
    158158
    159159    inline uint32_t getObjectID() const {return this->objectID_;}
    160     inline unsigned int getCreatorID() const {return this->creatorID_;}
     160    inline unsigned int getContextID() const {return this->contextID_;}
    161161    inline uint32_t getClassID() const {return this->classID_;}
    162162    inline unsigned int getPriority() const { return this->objectFrequency_;}
     
    170170
    171171  protected:
    172     Synchronisable(BaseObject* creator);
     172    Synchronisable(Context* context);
    173173    template <class T> void registerVariable(T& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
    174174    template <class T> void registerVariable(std::set<T>& variable, uint8_t mode=0x1, NetworkCallbackBase *cb=0, bool bidirectional=false);
     
    176176
    177177    void setPriority(unsigned int freq){ objectFrequency_ = freq; }
    178 
     178    uint32_t findContextID(Context* context);
    179179
    180180  private:
     
    189189
    190190    uint32_t objectID_;
    191     uint32_t creatorID_;
     191    uint32_t contextID_;
    192192    uint32_t classID_;
    193193
  • code/branches/core6/src/libraries/tools/ResourceCollection.cc

    r8858 r9629  
    3939    CreateFactory(ResourceCollection);
    4040
    41     ResourceCollection::ResourceCollection(BaseObject* creator)
    42         : BaseObject(creator)
     41    ResourceCollection::ResourceCollection(Context* context)
     42        : BaseObject(context)
    4343    {
    4444        RegisterObject(ResourceCollection);
  • code/branches/core6/src/libraries/tools/ResourceCollection.h

    r7401 r9629  
    4141    {
    4242    public:
    43         ResourceCollection(BaseObject* creator);
     43        ResourceCollection(Context* context);
    4444        virtual ~ResourceCollection();
    4545
  • code/branches/core6/src/libraries/tools/ResourceLocation.cc

    r8858 r9629  
    4343    CreateFactory(ResourceLocation);
    4444
    45     ResourceLocation::ResourceLocation(BaseObject* creator)
    46         : BaseObject(creator)
     45    ResourceLocation::ResourceLocation(Context* context)
     46        : BaseObject(context)
    4747    {
    4848        RegisterObject(ResourceLocation);
  • code/branches/core6/src/libraries/tools/ResourceLocation.h

    r7401 r9629  
    4343
    4444    public:
    45         ResourceLocation(BaseObject* creator);
     45        ResourceLocation(Context* context);
    4646        virtual ~ResourceLocation();
    4747
Note: See TracChangeset for help on using the changeset viewer.