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