Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 29, 2010, 1:16:16 PM (15 years ago)
Author:
dafrick
Message:

Created a new class of triggers called Multitriggers.
MultiTriggers are triggers which (as opposed to normal triggers) have a state for each object triggering the MultiTrigger, that means, that a MultiTrigger can be triggered for two different Players, while not being triggered for a third.
To go with this MultiTrigger I created a data structure (MultitriggerContainer), which helps relaying important information to the objects, that receive the Events of the trigger.
Also there is a MultiDistanceTrigger, which is just the DistanceTrigger as a MultiTrigger.

To make this work I had to make some adjustements to the eventsystem, namely an EventState can now be either an EventState (as it was before) or an EventSink, which means that every efent arriving at the EventState is processed as opposed to just the ones which change the state.
There is a new makro (XMLPortEventSink) to create an EventState with sink behaviour. It can be used exacly as the XMLPortEventState makro.

Location:
code/trunk/src/libraries/core
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/BaseObject.cc

    r6524 r6800  
    103103        }
    104104    }
     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    }
    105112
    106113    /**
     
    356363    {
    357364        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;
    358367
    359368        std::map<std::string, EventState*>::const_iterator it = this->eventStates_.find(event.statename_);
  • code/trunk/src/libraries/core/BaseObject.h

    r6524 r6800  
    188188        private:
    189189            /** @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);
    192191            /** @brief Removes an event listener from this object. */
    193192            inline void unregisterEventListener(BaseObject* object)
  • code/trunk/src/libraries/core/Event.cc

    r6417 r6800  
    5959        this->bProcessingEvent_ = true;
    6060
     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       
    6163        // check if the originator is an instance of the requested class
    6264        if (event.originator_->isA(this->subclass_))
    6365        {
     66            // If the EventState doesn't act as an EventSink.
    6467            // actualize the activationcounter
    65             if (event.activate_)
    66                 ++this->activeEvents_;
    67             else
     68            if(!this->bSink_)
    6869            {
    69                 --this->activeEvents_;
     70                if (event.activate_)
     71                    ++this->activeEvents_;
     72                else
     73                {
     74                    --this->activeEvents_;
    7075
    71                 if (this->activeEvents_ < 0)
    72                     this->activeEvents_ = 0;
     76                    if (this->activeEvents_ < 0)
     77                        this->activeEvents_ = 0;
     78                }
    7379            }
    7480
     
    7884                (*this->statefunction_)();
    7985            }
    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_)) ) )
    8187            {
    8288                // 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]
     
    8490                {
    8591                    // one argument: just the eventstate
    86                     (*this->statefunction_)(this->activeEvents_);
     92                    (*this->statefunction_)(event.activate_);
    8793                }
    8894                else if (this->statefunction_->getParamCount() >= 2)
     
    9298                    {
    9399                        // 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_);
    95101                    }
    96102                    else
     
    98104                        // else cast the pointer to the desired class
    99105                        void* castedOriginator = event.originator_->getDerivedPointer(this->subclass_->getClassID());
    100                         (*this->statefunction_)(this->activeEvents_, castedOriginator);
     106                        (*this->statefunction_)(event.activate_, castedOriginator);
    101107                    }
    102108                }
  • code/trunk/src/libraries/core/Event.h

    r6417 r6800  
    4646        BaseObject* originator_; //!< The object which triggered this event
    4747        std::string name_;       //!< The name of this event
     48
    4849    };
    4950
     
    6667    {
    6768        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) {}
    6970            virtual ~EventState();
    7071
     
    7980            Functor*    statefunction_;     //!< A functor to set the state
    8081            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.
    8183    };
    8284}
  • code/trunk/src/libraries/core/EventIncludes.h

    r6417 r6800  
    5252    } \
    5353    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)
    5463
    5564/**
    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.
    5767*/
    5868#define XMLPortEventStateTemplate(classname, subclassname, statename, function, xmlelement, mode, ...) \
Note: See TracChangeset for help on using the changeset viewer.