Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/lodfinal/src/core/BaseObject.h @ 3021

Last change on this file since 3021 was 2171, checked in by landauf, 16 years ago

merged revisions 2111-2170 from objecthierarchy branch back to trunk.

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