Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Nov 1, 2008, 7:04:09 PM (16 years ago)
Author:
landauf
Message:

merged objecthierarchy branch back to trunk

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/BaseObject.h

    r1841 r2087  
    3737#define _BaseObject_H__
    3838
     39#include <map>
     40
    3941#include "CorePrereqs.h"
    4042
     
    4244#include "OrxonoxClass.h"
    4345#include "XMLIncludes.h"
     46#include "Event.h"
    4447
    4548namespace orxonox
    4649{
     50    class Scene;
     51    class Gametype;
     52
    4753    //! The BaseObject is the parent of all classes representing an instance in the game.
    4854    class _CoreExport BaseObject : virtual public OrxonoxClass
    4955    {
    50         friend class WorldEntity;
    51 
    5256        public:
    53             BaseObject();
     57            BaseObject(BaseObject* creator);
    5458            virtual ~BaseObject();
    5559            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     
    5963
    6064            /** @brief Sets the name of the object. @param name The name */
    61             inline void setName(const std::string& name) { this->name_ = name; this->changedName(); }
    62             /** @brief Returns the name of the object. @return The name */
     65            inline void setName(const std::string& name) { this->oldName_ = this->name_; this->name_ = name; this->changedName(); }
     66            /** @brief Returns the name of the object. */
    6367            inline const std::string& getName() const { return this->name_; }
     68            /** @brief Returns the old name of the object. */
     69            inline const std::string& getOldName() const { return this->oldName_; }
    6470            /** @brief This function gets called if the name of the object changes. */
    6571            virtual void changedName() {}
     
    7985            virtual void changedVisibility() {}
    8086
    81             /** @brief Sets a pointer to the level that loaded this object. @param level The pointer to the level */
    82             inline void setLevel(const Level* level) { this->level_ = level; }
    83             /** @brief Returns a pointer to the level that loaded this object. @return The level */
    84             inline const Level* getLevel() const { return this->level_; }
    85             const std::string& getLevelfile() const;
     87            /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */
     88            inline void setFile(const XMLFile* file) { this->file_ = file; }
     89            /** @brief Returns a pointer to the XMLFile that loaded this object. @return The XMLFile */
     90            inline const XMLFile* getFile() const { return this->file_; }
     91            const std::string& getFilename() const;
     92
     93            void addTemplate(const std::string& name);
     94            void addTemplate(Template* temp);
     95            /** @brief Returns the set of all aplied templates. */
     96            inline const std::set<Template*>& getTemplates() const
     97                { return this->templates_; }
    8698
    8799            virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; }
    88100            inline Namespace* getNamespace() const { return this->namespace_; }
     101
     102            inline void setCreator(BaseObject* creator) { this->creator_ = creator; }
     103            inline BaseObject* getCreator() const { return this->creator_; }
     104
     105            inline void setScene(Scene* scene) { this->scene_ = scene; }
     106            inline Scene* getScene() const { return this->scene_; }
     107
     108            inline void setGametype(Gametype* gametype) { this->oldGametype_ = this->gametype_; this->gametype_ = gametype; this->changedGametype(); }
     109            inline Gametype* getGametype() const { return this->gametype_; }
     110            inline Gametype* getOldGametype() const { return this->oldGametype_; }
     111            virtual inline void changedGametype() {}
     112
     113            void fireEvent();
     114            void fireEvent(bool activate);
     115            void fireEvent(bool activate, BaseObject* originator);
     116            void fireEvent(Event& event);
     117
     118            virtual void processEvent(Event& event);
     119
     120            inline void registerEventListener(BaseObject* object, const std::string& sectionname)
     121                { this->eventListeners_[object] = sectionname; }
     122            inline void unregisterEventListener(BaseObject* object)
     123                { this->eventListeners_.erase(object); }
     124
     125            void addEvent(BaseObject* event, const std::string& sectionname);
     126            void removeEvent(BaseObject* event);
     127            BaseObject* getEvent(unsigned int index) const;
     128
     129            void addEventContainer(const std::string& sectionname, EventContainer* container);
     130            EventContainer* getEventContainer(const std::string& sectionname) const;
    89131
    90132            /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */
     
    93135            inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; }
    94136
    95         private:
     137        protected:
    96138            std::string name_;                          //!< The name of the object
    97             bool bInitialized_;                         //!< True if the object was initialized (passed the object registration)
     139            std::string oldName_;                       //!< The old name of the object
    98140            bool bActive_;                              //!< True = the object is active
    99141            bool bVisible_;                             //!< True = the object is visible
    100             const Level* level_;                        //!< The level that loaded this object
    101             std::string loaderIndentation_;             //!< Indentation of the debug output in the Loader
    102             Namespace* namespace_;
     142
     143        private:
     144            void setXMLName(const std::string& name);
     145            Template* getTemplate(unsigned int index) const;
     146
     147            bool                  bInitialized_;         //!< True if the object was initialized (passed the object registration)
     148            const XMLFile*        file_;                 //!< The XMLFile that loaded this object
     149            std::string           loaderIndentation_;    //!< Indentation of the debug output in the Loader
     150            Namespace*            namespace_;
     151            BaseObject*           creator_;
     152            Scene*                scene_;
     153            Gametype*             gametype_;
     154            Gametype*             oldGametype_;
     155            std::set<Template*>   templates_;
     156            std::map<BaseObject*, std::string> eventListeners_;
     157            std::list<BaseObject*> events_;
     158            std::map<std::string, EventContainer*> eventContainers_;
    103159    };
    104160
     
    106162    SUPER_FUNCTION(2, BaseObject, changedActivity, false);
    107163    SUPER_FUNCTION(3, BaseObject, changedVisibility, false);
     164    SUPER_FUNCTION(4, BaseObject, processEvent, false);
    108165}
    109166
Note: See TracChangeset for help on using the changeset viewer.