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 | #include <map> |
---|
40 | |
---|
41 | #include "CorePrereqs.h" |
---|
42 | |
---|
43 | #include "Super.h" |
---|
44 | #include "OrxonoxClass.h" |
---|
45 | #include "XMLIncludes.h" |
---|
46 | #include "Event.h" |
---|
47 | |
---|
48 | namespace orxonox |
---|
49 | { |
---|
50 | class Scene; |
---|
51 | class Gametype; |
---|
52 | |
---|
53 | //! The BaseObject is the parent of all classes representing an instance in the game. |
---|
54 | class _CoreExport BaseObject : virtual public OrxonoxClass |
---|
55 | { |
---|
56 | public: |
---|
57 | BaseObject(BaseObject* creator); |
---|
58 | virtual ~BaseObject(); |
---|
59 | virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); |
---|
60 | |
---|
61 | /** @brief Returns if the object was initialized (passed the object registration). @return True was the object is initialized */ |
---|
62 | inline bool isInitialized() const { return this->bInitialized_; } |
---|
63 | |
---|
64 | /** @brief Sets the name of the object. @param name 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. */ |
---|
67 | 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_; } |
---|
70 | /** @brief This function gets called if the name of the object changes. */ |
---|
71 | virtual void changedName() {} |
---|
72 | |
---|
73 | /** @brief Sets the state of the objects activity. @param bActive True = active */ |
---|
74 | inline void setActive(bool bActive) |
---|
75 | { |
---|
76 | bool bTemp = this->bActive_; |
---|
77 | this->bActive_ = bActive; |
---|
78 | if ( bTemp != bActive ) |
---|
79 | this->changedActivity(); |
---|
80 | } |
---|
81 | /** @brief Returns the state of the objects activity. @return The state of the activity */ |
---|
82 | inline bool isActive() const { return this->bActive_; } |
---|
83 | /** @brief This function gets called if the activity of the object changes. */ |
---|
84 | virtual void changedActivity() {} |
---|
85 | |
---|
86 | /** @brief Sets the state of the objects visibility. @param bVisible True = visible */ |
---|
87 | inline void setVisible(bool bVisible) { this->bVisible_ = bVisible; this->changedVisibility(); } |
---|
88 | /** @brief Returns the state of the objects visibility. @return The state of the visibility */ |
---|
89 | inline bool isVisible() const { return this->bVisible_; } |
---|
90 | /** @brief This function gets called if the visibility of the object changes. */ |
---|
91 | virtual void changedVisibility() {} |
---|
92 | |
---|
93 | /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */ |
---|
94 | inline void setFile(const XMLFile* file) { this->file_ = file; } |
---|
95 | /** @brief Returns a pointer to the XMLFile that loaded this object. @return The XMLFile */ |
---|
96 | inline const XMLFile* getFile() const { return this->file_; } |
---|
97 | const std::string& getFilename() const; |
---|
98 | |
---|
99 | void addTemplate(const std::string& name); |
---|
100 | void addTemplate(Template* temp); |
---|
101 | /** @brief Returns the set of all aplied templates. */ |
---|
102 | inline const std::set<Template*>& getTemplates() const |
---|
103 | { return this->templates_; } |
---|
104 | |
---|
105 | virtual inline void setNamespace(Namespace* ns) { this->namespace_ = ns; } |
---|
106 | inline Namespace* getNamespace() const { return this->namespace_; } |
---|
107 | |
---|
108 | inline void setCreator(BaseObject* creator) { this->creator_ = creator; } |
---|
109 | inline BaseObject* getCreator() const { return this->creator_; } |
---|
110 | |
---|
111 | inline void setScene(Scene* scene) { this->scene_ = scene; } |
---|
112 | inline Scene* getScene() const { return this->scene_; } |
---|
113 | |
---|
114 | inline void setGametype(Gametype* gametype) { this->oldGametype_ = this->gametype_; this->gametype_ = gametype; this->changedGametype(); } |
---|
115 | inline Gametype* getGametype() const { return this->gametype_; } |
---|
116 | inline Gametype* getOldGametype() const { return this->oldGametype_; } |
---|
117 | virtual inline void changedGametype() {} |
---|
118 | |
---|
119 | void fireEvent(); |
---|
120 | void fireEvent(bool activate); |
---|
121 | void fireEvent(bool activate, BaseObject* originator); |
---|
122 | void fireEvent(Event& event); |
---|
123 | |
---|
124 | virtual void processEvent(Event& event); |
---|
125 | |
---|
126 | inline void registerEventListener(BaseObject* object, const std::string& sectionname) |
---|
127 | { this->eventListeners_[object] = sectionname; } |
---|
128 | inline void unregisterEventListener(BaseObject* object) |
---|
129 | { this->eventListeners_.erase(object); } |
---|
130 | |
---|
131 | void addEvent(BaseObject* event, const std::string& sectionname); |
---|
132 | void removeEvent(BaseObject* event); |
---|
133 | BaseObject* getEvent(unsigned int index) const; |
---|
134 | |
---|
135 | void addEventContainer(const std::string& sectionname, EventContainer* container); |
---|
136 | EventContainer* getEventContainer(const std::string& sectionname) const; |
---|
137 | |
---|
138 | /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */ |
---|
139 | inline void setLoaderIndentation(const std::string& indentation) { this->loaderIndentation_ = indentation; } |
---|
140 | /** @brief Returns the indentation of the debug output in the Loader. @return The indentation */ |
---|
141 | inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; } |
---|
142 | |
---|
143 | protected: |
---|
144 | std::string name_; //!< The name of the object |
---|
145 | std::string oldName_; //!< The old name of the object |
---|
146 | bool bActive_; //!< True = the object is active |
---|
147 | bool bVisible_; //!< True = the object is visible |
---|
148 | |
---|
149 | private: |
---|
150 | void setXMLName(const std::string& name); |
---|
151 | Template* getTemplate(unsigned int index) const; |
---|
152 | |
---|
153 | bool bInitialized_; //!< True if the object was initialized (passed the object registration) |
---|
154 | const XMLFile* file_; //!< The XMLFile that loaded this object |
---|
155 | std::string loaderIndentation_; //!< Indentation of the debug output in the Loader |
---|
156 | Namespace* namespace_; |
---|
157 | BaseObject* creator_; |
---|
158 | Scene* scene_; |
---|
159 | Gametype* gametype_; |
---|
160 | Gametype* oldGametype_; |
---|
161 | std::set<Template*> templates_; |
---|
162 | std::map<BaseObject*, std::string> eventListeners_; |
---|
163 | std::list<BaseObject*> events_; |
---|
164 | std::map<std::string, EventContainer*> eventContainers_; |
---|
165 | }; |
---|
166 | |
---|
167 | SUPER_FUNCTION(0, BaseObject, XMLPort, false); |
---|
168 | SUPER_FUNCTION(2, BaseObject, changedActivity, false); |
---|
169 | SUPER_FUNCTION(3, BaseObject, changedVisibility, false); |
---|
170 | SUPER_FUNCTION(4, BaseObject, processEvent, false); |
---|
171 | } |
---|
172 | |
---|
173 | #endif /* _BaseObject_H__ */ |
---|