Changeset 5866 for code/branches/core5/src
- Timestamp:
- Oct 3, 2009, 6:32:05 PM (15 years ago)
- Location:
- code/branches/core5/src
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/core5/src/libraries/core/BaseObject.cc
r5858 r5866 94 94 if (this->isInitialized()) 95 95 { 96 for (std:: list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)97 (*it)->unregisterEventListener(this);98 99 for (std:: map<BaseObject*, std::string>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)100 it->first->removeEvent(this);96 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventSources_.begin(); it != this->eventSources_.end(); ) 97 this->removeEventSource((it++)->first); 98 99 for (std::set<BaseObject*>::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ) 100 (*(it++))->removeEventSource(this); 101 101 102 102 for (std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.begin(); it != this->eventContainers_.end(); ++it) … … 145 145 { 146 146 std::string sectionname = (*it); 147 ExecutorMember<BaseObject>* loadexecutor = createExecutor(createFunctor(&BaseObject::addEvent ), std::string( "BaseObject" ) + "::" + "addEvent");148 ExecutorMember<BaseObject>* saveexecutor = createExecutor(createFunctor(&BaseObject::getEvent ), std::string( "BaseObject" ) + "::" + "getEvent");147 ExecutorMember<BaseObject>* loadexecutor = createExecutor(createFunctor(&BaseObject::addEventSource), std::string( "BaseObject" ) + "::" + "addEventSource"); 148 ExecutorMember<BaseObject>* saveexecutor = createExecutor(createFunctor(&BaseObject::getEventSource), std::string( "BaseObject" ) + "::" + "getEventSource"); 149 149 loadexecutor->setDefaultValue(1, sectionname); 150 saveexecutor->setDefaultValue(1, sectionname); 150 151 151 152 XMLPortClassObjectContainer<BaseObject, BaseObject>* container = 0; … … 224 225 } 225 226 226 void BaseObject::addEvent(BaseObject* event, const std::string& sectionname) 227 { 228 event->registerEventListener(this, sectionname); 229 this->events_.push_back(event); 230 } 231 232 void BaseObject::removeEvent(BaseObject* event) 233 { 234 this->events_.remove(event); 235 } 236 237 BaseObject* BaseObject::getEvent(unsigned int index) const 227 /** 228 @brief Adds a new event source for a specific state. 229 @param source The object which sends events to this object 230 @param state The state of this object which will be affected by the events 231 */ 232 void BaseObject::addEventSource(BaseObject* source, const std::string& state) 233 { 234 this->eventSources_[source] = state; 235 source->registerEventListener(this); 236 } 237 238 /** 239 @brief Removes an eventsource (but doesn't unregister itself at the source). 240 */ 241 void BaseObject::removeEventSource(BaseObject* source) 242 { 243 this->eventSources_.erase(source); 244 source->unregisterEventListener(this); 245 } 246 247 /** 248 @brief Returns an eventsource with a given index. 249 */ 250 BaseObject* BaseObject::getEventSource(unsigned int index, const std::string& state) const 238 251 { 239 252 unsigned int i = 0; 240 for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it) 241 { 253 for (std::map<BaseObject*, std::string>::const_iterator it = this->eventSources_.begin(); it != this->eventSources_.end(); ++it) 254 { 255 if (it->second != state) 256 continue; 257 242 258 if (i == index) 243 return (*it);259 return it->first; 244 260 ++i; 245 261 } … … 268 284 } 269 285 286 /** 287 @brief Fires an event (without a state). 288 */ 270 289 void BaseObject::fireEvent() 271 290 { … … 274 293 } 275 294 295 /** 296 @brief Fires an event which activates or deactivates a state. 297 */ 276 298 void BaseObject::fireEvent(bool activate) 277 299 { … … 279 301 } 280 302 303 /** 304 @brief Fires an event which activates or deactivates a state with agiven originator (the object which sends the event). 305 */ 281 306 void BaseObject::fireEvent(bool activate, BaseObject* originator) 282 307 { 283 308 Event event(activate, originator); 284 309 285 for (std::map<BaseObject*, std::string>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 286 { 287 event.sectionname_ = it->second; 288 it->first->processEvent(event); 289 } 290 } 291 310 for (std::set<BaseObject*>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 311 { 312 event.sectionname_ = (*it)->eventSources_[this]; 313 (*it)->processEvent(event); 314 } 315 } 316 317 /** 318 @brief Fires an event, using the Event struct. 319 */ 292 320 void BaseObject::fireEvent(Event& event) 293 321 { 294 for (std:: map<BaseObject*, std::string>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)295 it->first->processEvent(event);322 for (std::set<BaseObject*>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it) 323 (*it)->processEvent(event); 296 324 } 297 325 -
code/branches/core5/src/libraries/core/BaseObject.h
r5839 r5866 152 152 virtual void changedGametype() {} 153 153 154 void addEventSource(BaseObject* source, const std::string& state); 155 void removeEventSource(BaseObject* source); 156 BaseObject* getEventSource(unsigned int index, const std::string& state) const; 157 154 158 void fireEvent(); 155 159 void fireEvent(bool activate); … … 159 163 virtual void processEvent(Event& event); 160 164 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 165 /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */ 174 166 inline void setLoaderIndentation(const std::string& indentation) { this->loaderIndentation_ = indentation; } … … 177 169 178 170 protected: 171 /** @brief Adds an object which listens to the events of this object. */ 172 inline void registerEventListener(BaseObject* object) 173 { this->eventListeners_.insert(object); } 174 /** @brief Removes an event listener from this object. */ 175 inline void unregisterEventListener(BaseObject* object) 176 { this->eventListeners_.erase(object); } 177 178 void addEventContainer(const std::string& sectionname, EventContainer* container); 179 EventContainer* getEventContainer(const std::string& sectionname) const; 180 179 181 std::string name_; //!< The name of the object 180 182 std::string oldName_; //!< The old name of the object … … 197 199 BaseObject* creator_; 198 200 SmartPtr<Scene> scene_; 201 uint32_t sceneID_; 199 202 SmartPtr<Gametype> gametype_; 200 203 Gametype* oldGametype_; 201 204 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_;205 206 std::map<BaseObject*, std::string> eventSources_; //!< List of objects which send events to this object, mapped to the state which they affect 207 std::set<BaseObject*> eventListeners_; //!< List of objects which listen to the events of this object 208 std::map<std::string, EventContainer*> eventContainers_; 206 209 }; 207 210 -
code/branches/core5/src/libraries/core/Event.cc
r5738 r5866 30 30 31 31 #include "BaseObject.h" 32 #include "Executor.h"33 32 34 33 namespace orxonox -
code/branches/core5/src/libraries/core/Event.h
r5738 r5866 48 48 { 49 49 public: 50 EventContainer(const std::string& eventname, Executor* eventfunction, Identifier* subclass) : bActive_(false), eventname_(eventname), eventfunction_(eventfunction), subclass_(subclass), activeEvents_(0) {}50 EventContainer(const std::string& eventname, Functor* eventfunction, Identifier* subclass) : bActive_(false), eventname_(eventname), eventfunction_(eventfunction), subclass_(subclass), activeEvents_(0) {} 51 51 virtual ~EventContainer(); 52 52 … … 56 56 bool bActive_; 57 57 std::string eventname_; 58 Executor* eventfunction_;58 Functor* eventfunction_; 59 59 Identifier* subclass_; 60 60 -
code/branches/core5/src/libraries/core/EventIncludes.h
r5829 r5866 40 40 41 41 #define ORXONOX_SET_SUBCLASS_EVENT(classname, eventname, functionname, event, subclassname) \ 42 event.castedOriginator_ = orxonox::orxonox_cast<subclassname*>(event.originator_); \ 42 43 ORXONOX_SET_EVENT_GENERIC(eventcontainer##classname##functionname, classname, eventname, functionname, event, subclassname) 43 44 44 45 #define ORXONOX_SET_SUBCLASS_EVENT_TEMPLATE(classname, eventname, functionname, event, subclassname, ...) \ 46 event.castedOriginator_ = orxonox::orxonox_cast<subclassname*>(event.originator_); \ 45 47 ORXONOX_SET_EVENT_GENERIC_TEMPLATE(eventcontainer##classname##functionname, classname, eventname, functionname, event, subclassname, __VA_ARGS__) 46 48 … … 49 51 if (!containername) \ 50 52 { \ 51 ExecutorMember<classname>* executor = orxonox::createExecutor(orxonox::createFunctor(&classname::functionname, this), std::string( #classname ) + "::" + #functionname); \52 containername = new orxonox::EventContainer(std::string(eventname), executor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \53 Functor* functor = orxonox::createFunctor(&classname::functionname, this); \ 54 containername = new orxonox::EventContainer(std::string(eventname), functor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \ 53 55 this->addEventContainer(eventname, containername); \ 54 56 } \ 55 event.castedOriginator_ = orxonox::orxonox_cast<subclassname*>(event.originator_); \56 57 containername->process(this, event) 57 58 … … 60 61 if (!containername) \ 61 62 { \ 62 ExecutorMember<classname>* executor = orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::functionname, this), std::string( #classname ) + "::" + #functionname); \63 containername = new orxonox::EventContainer(std::string(eventname), executor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \63 Functor* functor = orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::functionname, this); \ 64 containername = new orxonox::EventContainer(std::string(eventname), functor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \ 64 65 this->addEventContainer(eventname, containername); \ 65 66 } \ 66 event.castedOriginator_ = orxonox::orxonox_cast<subclassname*>(event.originator_); \67 67 containername->process(this, event) 68 68 -
code/branches/core5/src/libraries/core/Identifier.h
r5783 r5866 261 261 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); } 262 262 263 void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container); 264 XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname); 265 266 void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container); 267 XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname); 268 269 270 ////////////////// 271 ///// Events ///// 272 ////////////////// 263 273 /** @brief Returns the map that stores all XMLPort events. @return The const_iterator */ 264 274 inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortEventMap() const { return this->xmlportEventContainers_; } … … 267 277 /** @brief Returns a const_iterator to the end of the map that stores all XMLPort events. @return The const_iterator */ 268 278 inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapEnd() const { return this->xmlportEventContainers_.end(); } 269 270 void addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container);271 XMLPortParamContainer* getXMLPortParamContainer(const std::string& paramname);272 273 void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container);274 XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname);275 279 276 280 void addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container); -
code/branches/core5/src/modules/objects/eventsystem/EventListener.cc
r5738 r5866 78 78 for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it) 79 79 if (it->getName() == this->eventName_) 80 this-> registerAsListener(*it);80 this->addEventSource(*it, ""); 81 81 } 82 82 … … 87 87 88 88 if (object->getName() == this->eventName_) 89 this->registerAsListener(object); 90 } 91 92 void EventListener::registerAsListener(BaseObject* object) 93 { 94 object->registerEventListener(this, ""); 89 this->addEventSource(object, ""); 95 90 } 96 91 } -
code/branches/core5/src/modules/objects/eventsystem/EventListener.h
r5738 r5866 54 54 private: 55 55 virtual void loadedNewXMLName(BaseObject* object); 56 void registerAsListener(BaseObject* object);57 56 58 57 std::string eventName_; -
code/branches/core5/src/modules/objects/eventsystem/EventTarget.cc
r5738 r5866 49 49 for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it) 50 50 if (it->getName() == this->getName()) 51 this->add AsEvent(*it);51 this->addEventTarget(*it); 52 52 } 53 53 … … 58 58 59 59 if (object->getName() == this->getName()) 60 this->add AsEvent(object);60 this->addEventTarget(object); 61 61 } 62 62 63 void EventTarget::add AsEvent(BaseObject* object)63 void EventTarget::addEventTarget(BaseObject* object) 64 64 { 65 65 if (object != static_cast<BaseObject*>(this)) 66 object->addEvent (this, "");66 object->addEventSource(this, ""); 67 67 } 68 68 } -
code/branches/core5/src/modules/objects/eventsystem/EventTarget.h
r5738 r5866 47 47 private: 48 48 virtual void loadedNewXMLName(BaseObject* object); 49 void add AsEvent(BaseObject* object);49 void addEventTarget(BaseObject* object); 50 50 }; 51 51 }
Note: See TracChangeset
for help on using the changeset viewer.