Changeset 5935 for code/branches/pickup/src/modules/objects/eventsystem
- Timestamp:
- Oct 13, 2009, 5:05:17 PM (15 years ago)
- Location:
- code/branches/pickup
- Files:
-
- 8 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup
- Property svn:mergeinfo changed
-
code/branches/pickup/src/modules/objects/eventsystem/CMakeLists.txt
r5781 r5935 1 1 ADD_SOURCE_FILES(OBJECTS_SRC_FILES 2 2 EventDispatcher.cc 3 EventFilter.cc 3 4 EventListener.cc 5 EventName.cc 4 6 EventTarget.cc 5 7 ) -
code/branches/pickup/src/modules/objects/eventsystem/EventDispatcher.cc
r5781 r5935 32 32 #include "core/EventIncludes.h" 33 33 #include "core/XMLPort.h" 34 #include "EventTarget.h"35 34 36 35 namespace orxonox … … 46 45 { 47 46 if (this->isInitialized()) 48 for (std::list< EventTarget*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it)49 delete (*it);47 for (std::list<BaseObject*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it) 48 (*it)->destroy(); 50 49 } 51 50 … … 54 53 SUPER(EventDispatcher, XMLPort, xmlelement, mode); 55 54 56 XMLPortObject(EventDispatcher, EventTarget, "targets", addTarget, getTarget, xmlelement, mode); 55 XMLPortObject(EventDispatcher, BaseObject, "targets", addTarget, getTarget, xmlelement, mode); 56 57 // since we need event sources mapped to any state, we have to parse XML by ourselves 58 this->loadAllEventStates(xmlelement, mode, this, Class(EventDispatcher)); 57 59 } 58 60 59 61 void EventDispatcher::processEvent(Event& event) 60 62 { 61 for (std::list< EventTarget*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it)62 (*it)-> fireEvent(event);63 for (std::list<BaseObject*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it) 64 (*it)->processEvent(event); 63 65 } 64 66 65 void EventDispatcher::addTarget( EventTarget* target)67 void EventDispatcher::addTarget(BaseObject* target) 66 68 { 67 69 this->targets_.push_back(target); 68 70 } 69 71 70 EventTarget* EventDispatcher::getTarget(unsigned int index) const72 BaseObject* EventDispatcher::getTarget(unsigned int index) const 71 73 { 72 74 unsigned int i = 0; 73 for (std::list< EventTarget*>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); ++it)75 for (std::list<BaseObject*>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); ++it) 74 76 { 75 77 if (i == index) -
code/branches/pickup/src/modules/objects/eventsystem/EventDispatcher.h
r5781 r5935 47 47 virtual void processEvent(Event& event); 48 48 49 void addTarget( EventTarget* target);50 EventTarget* getTarget(unsigned int index) const;49 void addTarget(BaseObject* target); 50 BaseObject* getTarget(unsigned int index) const; 51 51 52 52 private: 53 std::list< EventTarget*> targets_;53 std::list<BaseObject*> targets_; 54 54 }; 55 55 } -
code/branches/pickup/src/modules/objects/eventsystem/EventListener.cc
r5781 r5935 63 63 64 64 this->bActive_ = true; 65 66 this->fireEvent(event.activate_, event.originator_); 67 65 this->fireEvent(event.activate_, event.originator_, event.name_); 68 66 this->bActive_ = false; 69 67 } … … 78 76 for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it) 79 77 if (it->getName() == this->eventName_) 80 this-> registerAsListener(*it);78 this->addEventSource(*it, ""); 81 79 } 82 80 … … 87 85 88 86 if (object->getName() == this->eventName_) 89 this->registerAsListener(object); 90 } 91 92 void EventListener::registerAsListener(BaseObject* object) 93 { 94 object->registerEventListener(this, ""); 87 this->addEventSource(object, ""); 95 88 } 96 89 } -
code/branches/pickup/src/modules/objects/eventsystem/EventListener.h
r5781 r5935 54 54 private: 55 55 virtual void loadedNewXMLName(BaseObject* object); 56 void registerAsListener(BaseObject* object);57 56 58 57 std::string eventName_; -
code/branches/pickup/src/modules/objects/eventsystem/EventTarget.cc
r5781 r5935 29 29 #include "EventTarget.h" 30 30 #include "core/CoreIncludes.h" 31 #include "core/XMLPort.h" 31 32 32 33 namespace orxonox … … 37 38 { 38 39 RegisterObject(EventTarget); 40 41 this->bActive_ = false; 39 42 } 40 43 … … 42 45 { 43 46 } 47 48 void EventTarget::XMLPort(Element& xmlelement, XMLPort::Mode mode) 49 { 50 SUPER(EventTarget, XMLPort, xmlelement, mode); 44 51 45 void EventTarget::changedName() 52 XMLPortParam(EventTarget, "target", setTargetName, getTargetName, xmlelement, mode); 53 54 // since we need event sources mapped to any state, we have to parse XML by ourselves 55 this->loadAllEventStates(xmlelement, mode, this, Class(EventTarget)); 56 } 57 58 void EventTarget::processEvent(Event& event) 46 59 { 47 SUPER(EventTarget, changedName); 60 if (this->bActive_) 61 { 62 COUT(2) << "Warning: Detected Event loop in EventTarget \"" << this->getName() << "\"" << std::endl; 63 return; 64 } 48 65 66 this->bActive_ = true; 67 this->fireEvent(event); 68 this->bActive_ = false; 69 } 70 71 void EventTarget::setTargetName(const std::string& name) 72 { 73 this->target_ = name; 74 49 75 for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it) 50 if (it->getName() == this-> getName())51 this->add AsEvent(*it);76 if (it->getName() == this->target_) 77 this->addEventTarget(*it); 52 78 } 53 79 54 80 void EventTarget::loadedNewXMLName(BaseObject* object) 55 81 { 56 if (this-> getName()== "")82 if (this->target_ == "") 57 83 return; 58 84 59 if (object->getName() == this-> getName())60 this->add AsEvent(object);85 if (object->getName() == this->target_) 86 this->addEventTarget(object); 61 87 } 62 88 63 void EventTarget::add AsEvent(BaseObject* object)89 void EventTarget::addEventTarget(BaseObject* object) 64 90 { 65 91 if (object != static_cast<BaseObject*>(this)) 66 object->addEvent (this, "");92 object->addEventSource(this, ""); 67 93 } 68 94 } -
code/branches/pickup/src/modules/objects/eventsystem/EventTarget.h
r5781 r5935 42 42 EventTarget(BaseObject* creator); 43 43 virtual ~EventTarget(); 44 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 47 virtual void processEvent(Event& event); 44 48 45 virtual void changedName(); 49 void setTargetName(const std::string& name); 50 inline const std::string& getTargetName() const 51 { return this->target_; } 46 52 47 53 private: 48 54 virtual void loadedNewXMLName(BaseObject* object); 49 void addAsEvent(BaseObject* object); 55 void addEventTarget(BaseObject* object); 56 57 std::string target_; 58 bool bActive_; 50 59 }; 51 60 }
Note: See TracChangeset
for help on using the changeset viewer.