Changeset 5929 for code/trunk/src/libraries/core/BaseObject.h
- Timestamp:
- Oct 12, 2009, 8:20:07 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/core5 (added) merged: 5768-5769,5772,5775-5780,5783-5785,5791-5792,5795-5807,5809-5814,5816-5832,5836-5839,5842-5853,5855-5899,5904-5922,5924-5928
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/BaseObject.h
r5781 r5929 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 40 … … 53 45 #include "OrxonoxClass.h" 54 46 #include "Super.h" 47 #include "SmartPtr.h" 55 48 56 49 namespace orxonox … … 68 61 virtual ~BaseObject(); 69 62 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 63 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 70 64 71 65 /** @brief Returns if the object was initialized (passed the object registration). @return True was the object is initialized */ … … 110 104 111 105 void setMainState(bool state); 112 bool getMainState() const; 113 114 void setMainStateName(const std::string& name); 106 107 /** @brief Sets the name of the main state (used for event reactions). */ 108 void setMainStateName(const std::string& name) 109 { 110 if (this->mainStateName_ != name) 111 { 112 this->mainStateName_ = name; 113 this->changedMainStateName(); 114 } 115 } 116 /** @brief Returns the name of the main state. */ 115 117 inline const std::string& getMainStateName() const { return this->mainStateName_; } 116 virtual void changedMainState(); 118 /** @brief This function gets called if the main state name of the object changes. */ 119 virtual void changedMainStateName(); 117 120 118 121 /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */ … … 134 137 inline BaseObject* getCreator() const { return this->creator_; } 135 138 136 inline void setScene(Scene* scene) { this->scene_ = scene; } 137 inline Scene* getScene() const { return this->scene_; } 138 139 inline void setGametype(Gametype* gametype) 139 inline void setScene(const SmartPtr<Scene>& scene, uint32_t sceneID) { this->scene_ = scene; this->sceneID_=sceneID; } 140 inline const SmartPtr<Scene>& getScene() const { return this->scene_; } 141 inline virtual uint32_t getSceneID() const { return this->sceneID_; } 142 143 inline void setGametype(const SmartPtr<Gametype>& gametype) 140 144 { 141 145 if (gametype != this->gametype_) … … 146 150 } 147 151 } 148 inline Gametype*getGametype() const { return this->gametype_; }152 inline const SmartPtr<Gametype>& getGametype() const { return this->gametype_; } 149 153 inline Gametype* getOldGametype() const { return this->oldGametype_; } 150 154 virtual void changedGametype() {} 151 155 152 void fireEvent(); 153 void fireEvent(bool activate); 154 void fireEvent(bool activate, BaseObject* originator); 156 void addEventSource(BaseObject* source, const std::string& state); 157 void removeEventSource(BaseObject* source); 158 BaseObject* getEventSource(unsigned int index, const std::string& state) const; 159 160 void addEventListener(BaseObject* listener); 161 BaseObject* getEventListener(unsigned int index) const; 162 163 void fireEvent(const std::string& name = ""); 164 void fireEvent(bool activate, const std::string& name = ""); 165 void fireEvent(bool activate, BaseObject* originator, const std::string& name = ""); 155 166 void fireEvent(Event& event); 156 167 157 168 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 169 171 170 /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */ … … 173 172 /** @brief Returns the indentation of the debug output in the Loader. @return The indentation */ 174 173 inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; } 174 175 static void loadAllEventStates(Element& xmlelement, XMLPort::Mode mode, BaseObject* object, Identifier* identifier); 175 176 176 177 protected: 178 void addEventState(const std::string& name, EventState* container); 179 EventState* getEventState(const std::string& name) const; 180 177 181 std::string name_; //!< The name of the object 178 182 std::string oldName_; //!< The old name of the object … … 180 184 mbool bVisible_; //!< True = the object is visible 181 185 std::string mainStateName_; 182 Functor* functorSetMainState_; 183 Functor* functorGetMainState_; 186 Functor* mainStateFunctor_; 184 187 185 188 private: 189 /** @brief Adds an object which listens to the events of this object. */ 190 inline void registerEventListener(BaseObject* object) 191 { this->eventListeners_.insert(object); } 192 /** @brief Removes an event listener from this object. */ 193 inline void unregisterEventListener(BaseObject* object) 194 { this->eventListeners_.erase(object); } 195 186 196 void setXMLName(const std::string& name); 187 197 Template* getTemplate(unsigned int index) const; 198 void registerEventStates(); 188 199 189 200 bool bInitialized_; //!< True if the object was initialized (passed the object registration) … … 194 205 Namespace* namespace_; 195 206 BaseObject* creator_; 196 Scene* scene_; 197 Gametype* gametype_; 207 SmartPtr<Scene> scene_; 208 uint32_t sceneID_; 209 SmartPtr<Gametype> gametype_; 198 210 Gametype* oldGametype_; 199 211 std::set<Template*> templates_; 200 std::map<BaseObject*, std::string> eventListeners_; 201 std::list<BaseObject*> events_; 202 std::map<std::string, EventContainer*> eventContainers_; 212 213 std::map<BaseObject*, std::string> eventSources_; //!< List of objects which send events to this object, mapped to the state which they affect 214 std::set<BaseObject*> eventListeners_; //!< List of objects which listen to the events of this object 215 std::set<BaseObject*> eventListenersXML_; //!< List of objects which listen to the events of this object through the "eventlisteners" subsection in XML 216 std::map<std::string, EventState*> eventStates_; //!< Maps the name of the event states to their helper objects 217 bool bRegisteredEventStates_; //!< Becomes true after the object registered its event states (with XMLEventPort) 203 218 }; 204 219 … … 206 221 SUPER_FUNCTION(2, BaseObject, changedActivity, false); 207 222 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); 223 SUPER_FUNCTION(4, BaseObject, XMLEventPort, false); 224 SUPER_FUNCTION(8, BaseObject, changedName, false); 225 SUPER_FUNCTION(9, BaseObject, changedGametype, false); 212 226 } 213 227
Note: See TracChangeset
for help on using the changeset viewer.