Changeset 5774 for code/trunk/src/libraries/core/BaseObject.h
- Timestamp:
- Sep 23, 2009, 11:31:02 PM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/core/BaseObject.h
r5738 r5774 37 37 #define _BaseObject_H__ 38 38 39 #define SetMainState(classname, statename, setfunction, getfunction) \40 if (this->getMainStateName() == statename) \41 { \42 this->functorSetMainState_ = createFunctor(&classname::setfunction)->setObject(this); \43 this->functorGetMainState_ = createFunctor(&classname::getfunction)->setObject(this); \44 }45 46 47 39 #include "CorePrereqs.h" 48 49 #include <map>50 #include <list>51 52 #include "util/mbool.h"53 40 #include "OrxonoxClass.h" 54 #include "Super.h"55 41 56 42 namespace orxonox 57 43 { 58 class Scene;59 class Gametype;60 61 44 //! The BaseObject is the parent of all classes representing an instance in the game. 62 45 class _CoreExport BaseObject : virtual public OrxonoxClass 63 46 { 64 template <class T> friend class XMLPortClassParamContainer;65 66 47 public: 67 48 BaseObject(BaseObject* creator); 68 49 virtual ~BaseObject(); 69 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);70 50 71 51 /** @brief Returns if the object was initialized (passed the object registration). @return True was the object is initialized */ 72 52 inline bool isInitialized() const { return this->bInitialized_; } 73 53 74 /** @brief Sets the name of the object. @param name The name */75 inline void setName(const std::string& name) { this->oldName_ = this->name_; this->name_ = name; this->changedName(); }76 /** @brief Returns the name of the object. */77 inline const std::string& getName() const { return this->name_; }78 /** @brief Returns the old name of the object. */79 inline const std::string& getOldName() const { return this->oldName_; }80 /** @brief This function gets called if the name of the object changes. */81 virtual void changedName() {}82 83 /** @brief Sets the state of the objects activity. @param bActive True = active */84 inline void setActive(bool bActive)85 {86 if (this->bActive_ != bActive)87 {88 this->bActive_ = bActive;89 this->changedActivity();90 }91 }92 /** @brief Returns the state of the objects activity. @return The state of the activity */93 inline const mbool& isActive() const { return this->bActive_; }94 /** @brief This function gets called if the activity of the object changes. */95 virtual void changedActivity() {}96 97 /** @brief Sets the state of the objects visibility. @param bVisible True = visible */98 inline void setVisible(bool bVisible)99 {100 if (this->bVisible_ != bVisible)101 {102 this->bVisible_ = bVisible;103 this->changedVisibility();104 }105 }106 /** @brief Returns the state of the objects visibility. @return The state of the visibility */107 inline const mbool& isVisible() const { return this->bVisible_; }108 /** @brief This function gets called if the visibility of the object changes. */109 virtual void changedVisibility() {}110 111 void setMainState(bool state);112 bool getMainState() const;113 114 void setMainStateName(const std::string& name);115 inline const std::string& getMainStateName() const { return this->mainStateName_; }116 virtual void changedMainState();117 118 /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */119 inline void setFile(const XMLFile* file) { this->file_ = file; }120 /** @brief Returns a pointer to the XMLFile that loaded this object. @return The XMLFile */121 inline const XMLFile* getFile() const { return this->file_; }122 const std::string& getFilename() const;123 124 void addTemplate(const std::string& name);125 void addTemplate(Template* temp);126 /** @brief Returns the set of all aplied templates. */127 inline const std::set<Template*>& getTemplates() const128 { return this->templates_; }129 130 virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; }131 inline Namespace* getNamespace() const { return this->namespace_; }132 133 54 inline void setCreator(BaseObject* creator) { this->creator_ = creator; } 134 55 inline BaseObject* getCreator() const { return this->creator_; } 135 56 136 inline void setScene(Scene* scene) { this->scene_ = scene; }137 inline Scene* getScene() const { return this->scene_; }138 139 inline void setGametype(Gametype* gametype)140 {141 if (gametype != this->gametype_)142 {143 this->oldGametype_ = this->gametype_;144 this->gametype_ = gametype;145 this->changedGametype();146 }147 }148 inline Gametype* getGametype() const { return this->gametype_; }149 inline Gametype* getOldGametype() const { return this->oldGametype_; }150 virtual void changedGametype() {}151 152 void fireEvent();153 void fireEvent(bool activate);154 void fireEvent(bool activate, BaseObject* originator);155 void fireEvent(Event& event);156 157 virtual void processEvent(Event& event);158 159 inline void registerEventListener(BaseObject* object, const std::string& sectionname)160 { this->eventListeners_[object] = sectionname; }161 inline void unregisterEventListener(BaseObject* object)162 { this->eventListeners_.erase(object); }163 164 void addEvent(BaseObject* event, const std::string& sectionname);165 void removeEvent(BaseObject* event);166 BaseObject* getEvent(unsigned int index) const;167 168 void addEventContainer(const std::string& sectionname, EventContainer* container);169 EventContainer* getEventContainer(const std::string& sectionname) const;170 171 /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */172 inline void setLoaderIndentation(const std::string& indentation) { this->loaderIndentation_ = indentation; }173 /** @brief Returns the indentation of the debug output in the Loader. @return The indentation */174 inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; }175 176 protected:177 std::string name_; //!< The name of the object178 std::string oldName_; //!< The old name of the object179 mbool bActive_; //!< True = the object is active180 mbool bVisible_; //!< True = the object is visible181 std::string mainStateName_;182 Functor* functorSetMainState_;183 Functor* functorGetMainState_;184 185 57 private: 186 void setXMLName(const std::string& name);187 Template* getTemplate(unsigned int index) const;188 189 58 bool bInitialized_; //!< True if the object was initialized (passed the object registration) 190 const XMLFile* file_; //!< The XMLFile that loaded this object191 Element* lastLoadedXMLElement_; //!< Non 0 if the TinyXML attributes have already been copied to our own lowercase map192 std::map<std::string, std::string> xmlAttributes_; //!< Lowercase XML attributes193 std::string loaderIndentation_; //!< Indentation of the debug output in the Loader194 Namespace* namespace_;195 59 BaseObject* creator_; 196 Scene* scene_;197 Gametype* gametype_;198 Gametype* oldGametype_;199 std::set<Template*> templates_;200 std::map<BaseObject*, std::string> eventListeners_;201 std::list<BaseObject*> events_;202 std::map<std::string, EventContainer*> eventContainers_;203 60 }; 204 205 SUPER_FUNCTION(0, BaseObject, XMLPort, false);206 SUPER_FUNCTION(2, BaseObject, changedActivity, false);207 SUPER_FUNCTION(3, BaseObject, changedVisibility, false);208 SUPER_FUNCTION(4, BaseObject, processEvent, false);209 SUPER_FUNCTION(6, BaseObject, changedMainState, false);210 SUPER_FUNCTION(9, BaseObject, changedName, false);211 SUPER_FUNCTION(10, BaseObject, changedGametype, false);212 61 } 213 62
Note: See TracChangeset
for help on using the changeset viewer.