[1505] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Fabian 'x3n' Landau |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | /** |
---|
[2171] | 30 | @file |
---|
[1505] | 31 | @brief Definition of the BaseObject class. |
---|
| 32 | |
---|
| 33 | The BaseObject is the parent of all classes representing an instance in the game. |
---|
| 34 | */ |
---|
| 35 | |
---|
| 36 | #ifndef _BaseObject_H__ |
---|
| 37 | #define _BaseObject_H__ |
---|
| 38 | |
---|
[2254] | 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 | |
---|
[2087] | 46 | #include <map> |
---|
| 47 | |
---|
[1505] | 48 | #include "CorePrereqs.h" |
---|
| 49 | |
---|
[1747] | 50 | #include "Super.h" |
---|
| 51 | #include "OrxonoxClass.h" |
---|
[1841] | 52 | #include "XMLIncludes.h" |
---|
[2087] | 53 | #include "Event.h" |
---|
[2171] | 54 | #include "util/mbool.h" |
---|
[1505] | 55 | |
---|
| 56 | namespace orxonox |
---|
| 57 | { |
---|
[2087] | 58 | class Scene; |
---|
| 59 | class Gametype; |
---|
| 60 | |
---|
[1505] | 61 | //! The BaseObject is the parent of all classes representing an instance in the game. |
---|
| 62 | class _CoreExport BaseObject : virtual public OrxonoxClass |
---|
| 63 | { |
---|
| 64 | public: |
---|
[2087] | 65 | BaseObject(BaseObject* creator); |
---|
[1505] | 66 | virtual ~BaseObject(); |
---|
| 67 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
| 68 | |
---|
[1558] | 69 | /** @brief Returns if the object was initialized (passed the object registration). @return True was the object is initialized */ |
---|
| 70 | inline bool isInitialized() const { return this->bInitialized_; } |
---|
| 71 | |
---|
[1505] | 72 | /** @brief Sets the name of the object. @param name The name */ |
---|
[2087] | 73 | inline void setName(const std::string& name) { this->oldName_ = this->name_; this->name_ = name; this->changedName(); } |
---|
| 74 | /** @brief Returns the name of the object. */ |
---|
[1505] | 75 | inline const std::string& getName() const { return this->name_; } |
---|
[2087] | 76 | /** @brief Returns the old name of the object. */ |
---|
| 77 | inline const std::string& getOldName() const { return this->oldName_; } |
---|
[1505] | 78 | /** @brief This function gets called if the name of the object changes. */ |
---|
| 79 | virtual void changedName() {} |
---|
| 80 | |
---|
| 81 | /** @brief Sets the state of the objects activity. @param bActive True = active */ |
---|
[2171] | 82 | inline void setActive(bool bActive) |
---|
| 83 | { |
---|
| 84 | if (this->bActive_ != bActive) |
---|
| 85 | { |
---|
| 86 | this->bActive_ = bActive; |
---|
| 87 | this->changedActivity(); |
---|
| 88 | } |
---|
| 89 | } |
---|
[1505] | 90 | /** @brief Returns the state of the objects activity. @return The state of the activity */ |
---|
[2171] | 91 | inline const mbool& isActive() const { return this->bActive_; } |
---|
[1505] | 92 | /** @brief This function gets called if the activity of the object changes. */ |
---|
| 93 | virtual void changedActivity() {} |
---|
| 94 | |
---|
| 95 | /** @brief Sets the state of the objects visibility. @param bVisible True = visible */ |
---|
[2171] | 96 | inline void setVisible(bool bVisible) |
---|
| 97 | { |
---|
| 98 | if (this->bVisible_ != bVisible) |
---|
| 99 | { |
---|
| 100 | this->bVisible_ = bVisible; |
---|
| 101 | this->changedVisibility(); |
---|
| 102 | } |
---|
| 103 | } |
---|
[1505] | 104 | /** @brief Returns the state of the objects visibility. @return The state of the visibility */ |
---|
[2171] | 105 | inline const mbool& isVisible() const { return this->bVisible_; } |
---|
[1505] | 106 | /** @brief This function gets called if the visibility of the object changes. */ |
---|
| 107 | virtual void changedVisibility() {} |
---|
| 108 | |
---|
[2254] | 109 | void setMainState(bool state); |
---|
| 110 | bool getMainState() const; |
---|
| 111 | |
---|
| 112 | void setMainStateName(const std::string& name); |
---|
| 113 | inline const std::string& getMainStateName() const { return this->mainStateName_; } |
---|
| 114 | virtual void changedMainState(); |
---|
| 115 | |
---|
[2087] | 116 | /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */ |
---|
| 117 | inline void setFile(const XMLFile* file) { this->file_ = file; } |
---|
| 118 | /** @brief Returns a pointer to the XMLFile that loaded this object. @return The XMLFile */ |
---|
| 119 | inline const XMLFile* getFile() const { return this->file_; } |
---|
| 120 | const std::string& getFilename() const; |
---|
[1505] | 121 | |
---|
[2087] | 122 | void addTemplate(const std::string& name); |
---|
| 123 | void addTemplate(Template* temp); |
---|
| 124 | /** @brief Returns the set of all aplied templates. */ |
---|
| 125 | inline const std::set<Template*>& getTemplates() const |
---|
| 126 | { return this->templates_; } |
---|
| 127 | |
---|
[1505] | 128 | virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; } |
---|
| 129 | inline Namespace* getNamespace() const { return this->namespace_; } |
---|
| 130 | |
---|
[2087] | 131 | inline void setCreator(BaseObject* creator) { this->creator_ = creator; } |
---|
| 132 | inline BaseObject* getCreator() const { return this->creator_; } |
---|
| 133 | |
---|
| 134 | inline void setScene(Scene* scene) { this->scene_ = scene; } |
---|
| 135 | inline Scene* getScene() const { return this->scene_; } |
---|
| 136 | |
---|
[2428] | 137 | inline void setGametype(Gametype* gametype) |
---|
| 138 | { |
---|
| 139 | if (gametype != this->gametype_) |
---|
| 140 | { |
---|
| 141 | this->oldGametype_ = this->gametype_; |
---|
| 142 | this->gametype_ = gametype; |
---|
| 143 | this->changedGametype(); |
---|
| 144 | } |
---|
| 145 | } |
---|
[2087] | 146 | inline Gametype* getGametype() const { return this->gametype_; } |
---|
| 147 | inline Gametype* getOldGametype() const { return this->oldGametype_; } |
---|
[2428] | 148 | virtual void changedGametype() {} |
---|
[2087] | 149 | |
---|
| 150 | void fireEvent(); |
---|
| 151 | void fireEvent(bool activate); |
---|
| 152 | void fireEvent(bool activate, BaseObject* originator); |
---|
| 153 | void fireEvent(Event& event); |
---|
| 154 | |
---|
| 155 | virtual void processEvent(Event& event); |
---|
| 156 | |
---|
| 157 | inline void registerEventListener(BaseObject* object, const std::string& sectionname) |
---|
| 158 | { this->eventListeners_[object] = sectionname; } |
---|
| 159 | inline void unregisterEventListener(BaseObject* object) |
---|
| 160 | { this->eventListeners_.erase(object); } |
---|
| 161 | |
---|
| 162 | void addEvent(BaseObject* event, const std::string& sectionname); |
---|
| 163 | void removeEvent(BaseObject* event); |
---|
| 164 | BaseObject* getEvent(unsigned int index) const; |
---|
| 165 | |
---|
| 166 | void addEventContainer(const std::string& sectionname, EventContainer* container); |
---|
| 167 | EventContainer* getEventContainer(const std::string& sectionname) const; |
---|
| 168 | |
---|
[1505] | 169 | /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */ |
---|
| 170 | inline void setLoaderIndentation(const std::string& indentation) { this->loaderIndentation_ = indentation; } |
---|
| 171 | /** @brief Returns the indentation of the debug output in the Loader. @return The indentation */ |
---|
| 172 | inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; } |
---|
| 173 | |
---|
[2087] | 174 | protected: |
---|
[1505] | 175 | std::string name_; //!< The name of the object |
---|
[2087] | 176 | std::string oldName_; //!< The old name of the object |
---|
[2254] | 177 | mbool bActive_; //!< True = the object is active |
---|
| 178 | mbool bVisible_; //!< True = the object is visible |
---|
| 179 | std::string mainStateName_; |
---|
| 180 | Functor* functorSetMainState_; |
---|
| 181 | Functor* functorGetMainState_; |
---|
[2087] | 182 | |
---|
| 183 | private: |
---|
| 184 | void setXMLName(const std::string& name); |
---|
| 185 | Template* getTemplate(unsigned int index) const; |
---|
| 186 | |
---|
[2254] | 187 | bool bInitialized_; //!< True if the object was initialized (passed the object registration) |
---|
| 188 | const XMLFile* file_; //!< The XMLFile that loaded this object |
---|
| 189 | std::string loaderIndentation_; //!< Indentation of the debug output in the Loader |
---|
| 190 | Namespace* namespace_; |
---|
| 191 | BaseObject* creator_; |
---|
| 192 | Scene* scene_; |
---|
| 193 | Gametype* gametype_; |
---|
| 194 | Gametype* oldGametype_; |
---|
| 195 | std::set<Template*> templates_; |
---|
| 196 | std::map<BaseObject*, std::string> eventListeners_; |
---|
[2087] | 197 | std::list<BaseObject*> events_; |
---|
| 198 | std::map<std::string, EventContainer*> eventContainers_; |
---|
[1505] | 199 | }; |
---|
[1747] | 200 | |
---|
| 201 | SUPER_FUNCTION(0, BaseObject, XMLPort, false); |
---|
| 202 | SUPER_FUNCTION(2, BaseObject, changedActivity, false); |
---|
| 203 | SUPER_FUNCTION(3, BaseObject, changedVisibility, false); |
---|
[2087] | 204 | SUPER_FUNCTION(4, BaseObject, processEvent, false); |
---|
[2254] | 205 | SUPER_FUNCTION(6, BaseObject, changedMainState, false); |
---|
[2369] | 206 | SUPER_FUNCTION(9, BaseObject, changedName, false); |
---|
[2428] | 207 | SUPER_FUNCTION(10, BaseObject, changedGametype, false); |
---|
[1505] | 208 | } |
---|
| 209 | |
---|
| 210 | #endif /* _BaseObject_H__ */ |
---|