Changeset 6800 for code/trunk
- Timestamp:
- Apr 29, 2010, 1:16:16 PM (15 years ago)
- Location:
- code/trunk/src
- Files:
-
- 6 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/core/BaseObject.cc
r6524 r6800 103 103 } 104 104 } 105 106 /** @brief Adds an object which listens to the events of this object. */ 107 void BaseObject::registerEventListener(BaseObject* object) 108 { 109 COUT(4) << "New EventListener: " << object->getIdentifier()->getName() << " &(" << object << ")." << std::endl; 110 this->eventListeners_.insert(object); 111 } 105 112 106 113 /** … … 356 363 { 357 364 this->registerEventStates(); 365 366 COUT(4) << this->getIdentifier()->getName() << " (&" << this << ") processing event. originator: " << event.originator_->getIdentifier()->getName() << " (&" << event.originator_ << "), activate: " << event.activate_ << ", name: " << event.name_ << ", statename: " << event.statename_ << "." << std::endl; 358 367 359 368 std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(event.statename_); -
code/trunk/src/libraries/core/BaseObject.h
r6524 r6800 188 188 private: 189 189 /** @brief Adds an object which listens to the events of this object. */ 190 inline void registerEventListener(BaseObject* object) 191 { this->eventListeners_.insert(object); } 190 void registerEventListener(BaseObject* object); 192 191 /** @brief Removes an event listener from this object. */ 193 192 inline void unregisterEventListener(BaseObject* object) -
code/trunk/src/libraries/core/Event.cc
r6417 r6800 59 59 this->bProcessingEvent_ = true; 60 60 61 COUT(4) << "Processing event (EventState) : originator: " << event.originator_->getIdentifier()->getName() << " (&" << event.originator_ << "), activate: " << event.activate_ << ", name: " << event.name_ << ", statename: " << event.statename_ << ", object: " << object->getIdentifier()->getName() << " (&" << object << ")" << ", subclass: " << this->subclass_->getName() << ", (?): " << event.originator_->isA(this->subclass_) << "." << std::endl; 62 61 63 // check if the originator is an instance of the requested class 62 64 if (event.originator_->isA(this->subclass_)) 63 65 { 66 // If the EventState doesn't act as an EventSink. 64 67 // actualize the activationcounter 65 if (event.activate_) 66 ++this->activeEvents_; 67 else 68 if(!this->bSink_) 68 69 { 69 --this->activeEvents_; 70 if (event.activate_) 71 ++this->activeEvents_; 72 else 73 { 74 --this->activeEvents_; 70 75 71 if (this->activeEvents_ < 0) 72 this->activeEvents_ = 0; 76 if (this->activeEvents_ < 0) 77 this->activeEvents_ = 0; 78 } 73 79 } 74 80 … … 78 84 (*this->statefunction_)(); 79 85 } 80 else if ( (this->activeEvents_ == 1 && event.activate_) || (this->activeEvents_ == 0 && !event.activate_))86 else if (this->bSink_ || (!this->bSink_ && ((this->activeEvents_ == 1 && event.activate_) || (this->activeEvents_ == 0 && !event.activate_)) ) ) 81 87 { 82 88 // if the eventfunction needs a state, we just call the function if the state changed from 0 to 1 (state = true) or from 1 to 0 (state = false) [but not if activeEvents_ is > 1] … … 84 90 { 85 91 // one argument: just the eventstate 86 (*this->statefunction_)( this->activeEvents_);92 (*this->statefunction_)(event.activate_); 87 93 } 88 94 else if (this->statefunction_->getParamCount() >= 2) … … 92 98 { 93 99 // if the subclass is BaseObject, we don't have to cast the pointer 94 (*this->statefunction_)( this->activeEvents_, event.originator_);100 (*this->statefunction_)(event.activate_, event.originator_); 95 101 } 96 102 else … … 98 104 // else cast the pointer to the desired class 99 105 void* castedOriginator = event.originator_->getDerivedPointer(this->subclass_->getClassID()); 100 (*this->statefunction_)( this->activeEvents_, castedOriginator);106 (*this->statefunction_)(event.activate_, castedOriginator); 101 107 } 102 108 } -
code/trunk/src/libraries/core/Event.h
r6417 r6800 46 46 BaseObject* originator_; //!< The object which triggered this event 47 47 std::string name_; //!< The name of this event 48 48 49 }; 49 50 … … 66 67 { 67 68 public: 68 EventState(Functor* statefunction, Identifier* subclass ) : bProcessingEvent_(false), activeEvents_(0), statefunction_(statefunction), subclass_(subclass) {}69 EventState(Functor* statefunction, Identifier* subclass, bool bSink = false) : bProcessingEvent_(false), activeEvents_(0), statefunction_(statefunction), subclass_(subclass), bSink_(bSink) {} 69 70 virtual ~EventState(); 70 71 … … 79 80 Functor* statefunction_; //!< A functor to set the state 80 81 Identifier* subclass_; //!< Originators must be an instance of this class (usually BaseObject, but some statefunctions allow a second argument with an originator of a specific class) 82 bool bSink_; //!< Determines whether the EventState acts as an EventSink forwarding any Event (even if the state didn't change) or in the normal manner, only processing Events that change the state. 81 83 }; 82 84 } -
code/trunk/src/libraries/core/EventIncludes.h
r6417 r6800 52 52 } \ 53 53 XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode) 54 55 #define XMLPortEventSink(classname, subclassname, statename, function, xmlelement, mode) \ 56 orxonox::EventState* containername##function = this->getEventState(statename); \ 57 if (!containername##function) \ 58 { \ 59 containername##function = new orxonox::EventState(orxonox::createFunctor(&classname::function, this), orxonox::ClassIdentifier<subclassname>::getIdentifier(), true); \ 60 this->addEventState(statename, containername##function); \ 61 } \ 62 XMLPortEventStateIntern(xmlportevent##function, classname, statename, xmlelement, mode) 54 63 55 64 /** 56 @brief Like XMLPortEventState but with additional template arguments to identify the function of the state (if ambiguous). 65 @brief Like XMLPortEventState but creates an event sink instead of an event state. 66 The most important destinction between an EventState and an EventSink is, that an EventState only processes event which change the state of the EventState, where as an EventSink is an EventState that processes any Event that reaches it. 57 67 */ 58 68 #define XMLPortEventStateTemplate(classname, subclassname, statename, function, xmlelement, mode, ...) \ -
code/trunk/src/modules/objects/ObjectsPrereqs.h
r5929 r6800 85 85 // triggers 86 86 class CheckPoint; 87 class DistanceMultiTrigger; 87 88 class DistanceTrigger; 88 89 class EventTrigger; 90 class MultiTrigger; 91 class MultiTriggerContainer; 89 92 class Trigger; 90 93 } -
code/trunk/src/modules/objects/eventsystem/EventListener.cc
r6417 r6800 61 61 return; 62 62 } 63 64 COUT(4) << "EventListener: Processing event: originator: " << event.originator_->getIdentifier()->getName() << " (&" << event.originator_ << ")" << ", activate: " << event.activate_ << ", name: " << event.name_ << std::endl; 63 65 64 66 this->bActive_ = true; -
code/trunk/src/modules/objects/triggers/CMakeLists.txt
r5781 r6800 1 1 ADD_SOURCE_FILES(OBJECTS_SRC_FILES 2 Trigger.cc 2 CheckPoint.cc 3 DistanceMultiTrigger.cc 3 4 DistanceTrigger.cc 4 5 EventTrigger.cc 5 CheckPoint.cc 6 MultiTrigger.cc 7 MultiTriggerContainer.cc 8 Trigger.cc 6 9 ) -
code/trunk/src/modules/questsystem/CMakeLists.txt
r5781 r6800 34 34 LINK_LIBRARIES 35 35 orxonox 36 objects 36 37 overlays 37 38 SOURCE_FILES ${QUESTSYSTEM_SRC_FILES} -
code/trunk/src/modules/questsystem/QuestEffectBeacon.cc
r5938 r6800 39 39 #include "worldentities/pawns/Pawn.h" 40 40 #include "interfaces/PlayerTrigger.h" 41 #include "objects/triggers/MultiTriggerContainer.h" 41 42 #include "QuestEffect.h" 42 43 … … 75 76 XMLPortObject(QuestEffectBeacon, QuestEffect, "effects", addEffect, getEffect, xmlelement, mode); 76 77 77 XMLPortEventState(QuestEffectBeacon, PlayerTrigger, "execute", execute, xmlelement, mode);78 XMLPortEventState(QuestEffectBeacon, BaseObject, "execute", execute, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers. 78 79 79 80 COUT(3) << "New QuestEffectBeacon created." << std::endl; … … 84 85 SUPER(QuestEffectBeacon, XMLEventPort, xmlelement, mode); 85 86 86 XMLPortEventS tate(QuestEffectBeacon, PlayerTrigger, "execute", execute, xmlelement, mode);87 XMLPortEventSink(QuestEffectBeacon, BaseObject, "execute", execute, xmlelement, mode); 87 88 } 88 89 … … 92 93 This means extracting the Pawn from the PlayerTrigger, provided by the Event causing the execution, and the extracting the PlayerInfo from the received Pawn and invoking the QuestEffectbeacon's QuestEffects on the received PlayerInfo. 93 94 @param trigger 94 A pointer to the PlayerTrigger that threw the Event.95 A pointer to the PlayerTrigger that threw the Event. 95 96 @return 96 97 Returns true if successfully executed, false if not. 97 98 */ 98 bool QuestEffectBeacon::execute(bool b, PlayerTrigger* trigger) 99 { 99 bool QuestEffectBeacon::execute(bool b, BaseObject* trigger) 100 { 101 //TODO: Remove debug output. 102 COUT(1) << "Debug: Calling execute on QuestEffectBeacon." << std::endl; 103 100 104 if(!b) 101 105 { … … 108 112 } 109 113 110 if(!trigger->isForPlayer()) //!< The PlayerTrigger is not exclusively for Pawns which means we cannot extract one. 111 { 112 return false; 113 } 114 115 //! Extracting the Pawn from the PlayerTrigger. 116 Pawn* pawn = trigger->getTriggeringPlayer(); 114 PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger); 115 MultiTriggerContainer* mTrigger = orxonox_cast<MultiTriggerContainer*>(trigger); 116 Pawn* pawn = NULL; 117 118 //! If the trigger is neither a Playertrigger nor a MultiTrigger (i.e. a MultitriggerContainer) we can do anything with it. 119 if(pTrigger == NULL && mTrigger == NULL) 120 return false; 121 122 // If the trigger is a PlayerTrigger. 123 if(pTrigger != NULL) 124 { 125 if(!pTrigger->isForPlayer()) //!< The PlayerTrigger is not exclusively for Pawns which means we cannot extract one. 126 return false; 127 else 128 pawn = pTrigger->getTriggeringPlayer(); 129 } 130 131 // If the trigger is a MultiTrigger (i.e. a MultiTriggerContainer) 132 if(mTrigger != NULL) 133 { 134 pawn = orxonox_cast<Pawn*>(mTrigger->getData()); 135 } 117 136 118 137 if(pawn == NULL) -
code/trunk/src/modules/questsystem/QuestEffectBeacon.h
r5938 r6800 88 88 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 89 89 90 bool execute(bool b, PlayerTrigger* trigger); //!< Executes the QuestEffects of the QuestEffectBeacon.90 bool execute(bool b, BaseObject* trigger); //!< Executes the QuestEffects of the QuestEffectBeacon. 91 91 92 92 /**
Note: See TracChangeset
for help on using the changeset viewer.