Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6864


Ignore:
Timestamp:
May 9, 2010, 10:56:43 AM (15 years ago)
Author:
dafrick
Message:

Created a new MutliTrigger: EventMultiTrigger, which essentially does the same as EventTrigger but for every object that is a target as specified by teh EventMultiTrigger an Event is fired with information as being triggered by the target object.
This allows, e.g. to use the EventMultiTrigger to trigger QuestEffectBeacons.
I've also added a fireEvent() to Pawn such that an Event is fired when the Pawn is destroyed (forcebly). With EventMultiTrigger (but also with EventTrigger) one can now find out whether a Pawn died.
Here a little piece of example XML code to illustrate the usage:
<EventMutliTrigger name="trigger1">

<events>

<trigger>

<Spaceship />

</trigger>

</events>

</EventMultiTrigger>
To be able to implement this another feature was added to MultiTrigger, which is called broadcast. If enabled the MultiTrigger sends all Events triggered by NULL as to have come by all possible triggerers.

Additionally I've fixed a bug:
In DistanceMultiTrigger, an infinite loop occured under some circumstances. Not any more.

And did some niceifying (aka. documenting, renaming and code restructuring).

Location:
code/trunk/src
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/objects/ObjectsPrereqs.h

    r6800 r6864  
    8787    class DistanceMultiTrigger;
    8888    class DistanceTrigger;
     89    class EventMultiTrigger;
    8990    class EventTrigger;
    9091    class MultiTrigger;
  • code/trunk/src/modules/objects/triggers/CMakeLists.txt

    r6800 r6864  
    33  DistanceMultiTrigger.cc
    44  DistanceTrigger.cc
     5  EventMultiTrigger.cc
    56  EventTrigger.cc
    67  MultiTrigger.cc
  • code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.cc

    r6860 r6864  
    5959    DistanceMultiTrigger::~DistanceMultiTrigger()
    6060    {
    61        
    6261    }
    6362
     
    8180    std::queue<MultiTriggerState*>* DistanceMultiTrigger::letTrigger(void)
    8281    {
    83         ClassTreeMask& targetMask = this->getTargetMask();
    8482
    8583        std::queue<MultiTriggerState*>* queue = NULL;
     
    9290            if(entity == NULL)
    9391            {
    94                 it++;
     92                ++it;
    9593                this->removeFromRange(key);
    9694                continue;
     
    10199            if (distanceVec.length() > this->distance_)
    102100            {
    103                 if(!this->removeFromRange(entity))
     101                if(!this->removeFromRange(key))
     102                {
     103                    ++it;
    104104                    continue;
     105                }
    105106
    106107                // If no queue has been created, yet.
     
    117118                ++it;
    118119        }
     120
     121        ClassTreeMask& targetMask = this->getTargetMask();
    119122
    120123        // Check for new objects that are in range
  • code/trunk/src/modules/objects/triggers/DistanceMultiTrigger.h

    r6860 r6864  
    9292            */
    9393            inline bool removeFromRange(WorldEntity* entity)
    94                 { (*this->range_.find(entity)->second)->destroy(); bool erased = this->range_.erase(entity) > 0; return erased; }
     94                { WeakPtr<WorldEntity>* weakptr = this->range_.find(entity)->second; bool erased = this->range_.erase(entity) > 0; if(erased) delete weakptr; return erased; }
    9595               
    9696        private:
  • code/trunk/src/modules/objects/triggers/MultiTrigger.cc

    r6859 r6864  
    7272        this->mode_ = MultiTriggerMode::EventTriggerAND;
    7373
     74        this->bBroadcast_ = false;
     75
    7476        this->parentTrigger_ = NULL;
    7577       
     
    8587    MultiTrigger::~MultiTrigger()
    8688    {
    87         COUT(4) << "Destorying MultiTrigger &" << this << ". " << this->stateQueue_.size() << " states still in queue. Deleting." << std::endl;
     89        COUT(4) << "Destroying MultiTrigger &" << this << ". " << this->stateQueue_.size() << " states still in queue. Deleting." << std::endl;
    8890        while(this->stateQueue_.size() > 0)
    8991        {
     
    110112        XMLPortParam(MultiTrigger, "invert", setInvert, getInvert, xmlelement, mode);
    111113        XMLPortParamTemplate(MultiTrigger, "mode", setMode, getModeString, xmlelement, mode, const std::string&);
     114        XMLPortParam(MultiTrigger, "broadcast", setBroadcast, getBroadcast, xmlelement, mode);
    112115        XMLPortParamLoadOnly(MultiTrigger, "target", addTargets, xmlelement, mode).defaultValues("Pawn"); //TODO: Remove load only
    113116
     
    257260                            if(bFire)
    258261                            {
    259                                 this->fire(bActive, state->originator);
     262                                if(this->bBroadcast_ && state->originator == NULL)
     263                                {
     264                                    this->broadcast(bActive);
     265                                }
     266                                else
     267                                    this->fire(bActive, state->originator);
     268                               
    260269                                bStateChanged = true;
    261270                            }
     
    265274                        if(bStateChanged)
    266275                        {
    267                             COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << bActive << ", triggered: " << state->bTriggered << "." << std::endl;
     276                            if(state->originator != NULL)
     277                                COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << bActive << ", triggered: " << state->bTriggered << "." << std::endl;
     278                            else
     279                                COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: NULL, active: " << bActive << ", triggered: " << state->bTriggered << "." << std::endl;
    268280                            if(this->parentTrigger_ != NULL)
    269                                 this->parentTrigger_->activityChanged(state->originator);
     281                                this->parentTrigger_->subTrigggerActivityChanged(state->originator);
    270282                        }
    271283
     
    425437        This method is called by the MultiTrigger to get information about new trigger events that need to be looked at.
    426438        This method is the device for the behaviour (the conditions under which the MultiTrigger triggers) of any derived class from MultiTrigger.
    427 
    428         In this implementation it collects all objects triggering all sub-triggers nd the MultiTrigger itself and creates a state for each of them.
    429439    @return
    430440        A pointer to a queue of MultiTriggerState pointers is returned, containing all the neccessary information to decide whether these states should indeed become new states of the MultiTrigger.
     
    435445        return NULL;
    436446    }
    437    
    438     void MultiTrigger::activityChanged(BaseObject* originator)
     447
     448    /**
     449    @brief
     450        This method can be called by any class inheriting from MultiTrigger to change it's triggered status for a specified originator.
     451
     452        Compared to the letTrigger mode, which just polls and lets the pollee send it's state changed back, the changeTriggered method lets the trigger advertise its state changes just as they happen so it's much like the interrupt version of letTrigger.
     453    @param originator
     454        The originator which triggered the state change.
     455    */
     456    void MultiTrigger::changeTriggered(BaseObject* originator)
     457    {
     458        MultiTriggerState* state = new MultiTriggerState;
     459        state->bTriggered = (!this->isTriggered(originator) & this->isModeTriggered(originator)) ^ this->bInvertMode_;
     460        state->originator = originator;
     461        this->addState(state);
     462    }
     463
     464    /**
     465    @brief
     466        This method is called by any sub-trigger to advertise changes in it's state to it's parent-trigger.
     467    @param originator
     468        The object that caused the change in activity.
     469    */
     470    void MultiTrigger::subTrigggerActivityChanged(BaseObject* originator)
    439471    {
    440472        MultiTriggerState* state = new MultiTriggerState;
     
    499531    /**
    500532    @brief
    501         Helper method. Creates an event for the given status and originator and fires it.
     533        Helper method. Creates an Event for the given status and originator and fires it.
    502534        Or more precisely creates a MultiTriggerContainer to encompass all neccesary information and creates an Event from that and sends it.
    503535    @param status
    504         The status of the event to be fired. This is equivalent to the activity of the MultiTrigger.
     536        The status of the Event to be fired. This is equivalent to the activity of the MultiTrigger.
    505537    @param originator
    506538        The object that triggered the MultiTrigger to fire this Event.
     
    512544        {
    513545            this->fireEvent(status);
     546            COUT(4) << "MultiTrigger '" <<  this->getName() << "' (&" << this << "): Fired event. status: " << status << "." << std::endl;
    514547            return;
    515548        }
     
    523556    /**
    524557    @brief
     558        Helper method. Broadcasts an Event for every object that is a target.
     559    @param status
     560        The status of the Events to be fired. This is equivalent to the activity of the MultiTrigger.
     561    */
     562    void MultiTrigger::broadcast(bool status)
     563    {
     564        ClassTreeMask& targetMask = this->getTargetMask();
     565       
     566        for(ClassTreeMaskObjectIterator it = targetMask.begin(); it != targetMask.end(); ++it)
     567        {
     568            BaseObject* object = static_cast<BaseObject*>(*it);
     569            this->fire(status, object);
     570        }
     571    }
     572
     573    /**
     574    @brief
    525575        Helper method. Adds a state to the state queue, where the state will wait to become active.
    526576    @param state
  • code/trunk/src/modules/objects/triggers/MultiTrigger.h

    r6859 r6864  
    8282            'simultaniousTriggerers':   The number of simultanious triggerers limits the number of object that are allowed to trigger the MultiTrigger at the same time. Or a little more precisely, the number of distinct objects the MultiTrigger has 'triggered' states for, at each point in time.
    8383            'mode':                     The mode describes how the MultiTrigger acts in relation to all the MultiTriggers, that are appended to it. There are 3 modes: 'and', meaning that the MultiTrigger can only be triggered if all the appended MultiTriggers are active. 'or', meaning that the MultiTrigger can only triggered if at least one of the appendend MultiTriggers is active. And 'xor', meaning that the MultiTrigger can only be triggered if one and only one appended MultiTrigger is active. Notice, that I wrote 'can only be active', that implies, that there is an addtitional condition to the activity of the MultiTrigger and that is the fulfillment of the triggering condition (the MultiTrigger itself doesn't have one, but all derived classes should). Also bear in mind, that the activity of a MultiTrigger is still coupled to the object that triggered it. The default is 'and'.
     84            'broadcast'                 Broadcast is a bool, if true the MutliTrigger is in broadcast-mode, meaining, that all trigger events that are caused by no originator (originator is NULL) are broadcasted as having come from every possible originator, or more precisely as having come from all objects that are specified targets of this MultiTrigger.
    8485            'target':                   The target describes the kind of objects that are allowed to trigger this MultiTrigger. The default is 'Pawn'.
    8586            Also there is the possibility of appending MultiTriggers to the MultiTrigger just by adding them as subobjects in the XML description of your MultiTrigger.
     
    109110            @return The delay.
    110111            */
    111             inline float getDelay() const
     112            inline float getDelay(void) const
    112113                { return this->delay_; }
    113114
     
    122123            @return Returns true if the MultiTriger is in switch-mode.
    123124            */
    124             inline bool getSwitch() const
     125            inline bool getSwitch(void) const
    125126                { return this->bSwitch_; }
    126127
     
    135136            @return Returns true if the MultiTrigger stays active.
    136137            */
    137             inline bool getStayActive() const
     138            inline bool getStayActive(void) const
    138139                { return this->bStayActive_; }
    139140
     
    148149            @return The number of activations. -1 denotes infinity.
    149150            */
    150             inline int getActivations() const
     151            inline int getActivations(void) const
    151152                { return this->remainingActivations_; }
    152153
     
    174175            @return Returns true if the MultiTrigger is set to invert.
    175176            */
    176             inline bool getInvert() const
     177            inline bool getInvert(void) const
    177178                { return this->bInvertMode_; }
    178179
     
    193194
    194195            /**
     196            @brief Set the broadcast-mode of the MultiTrigger.
     197            @param bBroadcast If true the MultiTrigger is set to broadcast;
     198            */
     199            inline void setBroadcast(bool bBroadcast)
     200                { this->bBroadcast_ = bBroadcast; }
     201            /**
     202            @brief Get the broadcast-mode of the MultiTrigger.
     203            @return Returns true if the MultiTrigger is set to broadcast.
     204            */
     205            inline bool getBroadcast(void)
     206                { return this->bBroadcast_; }
     207
     208            /**
    195209            @brief Get whether the input object is a target of the MultiTrigger.
    196210            @param target A pointer to the object.
     
    198212            */
    199213            inline bool isTarget(BaseObject* target)
    200                 { return targetMask_.isIncluded(target->getIdentifier()); }
     214                { if(target == NULL) return true; else return targetMask_.isIncluded(target->getIdentifier()); }
    201215            void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.
    202216            void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger.
     
    208222            virtual std::queue<MultiTriggerState*>* letTrigger(void); //!< This method is called by the MultiTrigger to get information about new trigger events that need to be looked at.
    209223
    210             void activityChanged(BaseObject* originator);
     224            void changeTriggered(BaseObject* originator = NULL); //!< This method can be called by any class inheriting from MultiTrigger to change it's triggered status for a specified originator.
    211225           
    212226            bool isModeTriggered(BaseObject* triggerer = NULL); //!< Checks whetherx the MultiTrigger is triggered concerning it's sub-triggers.
    213227            bool isTriggered(BaseObject* triggerer = NULL); //!< Get whether the MultiTrigger is triggered for a given object.
    214228
    215             void fire(bool status, BaseObject* originator = NULL);  //!< Helper method. Creates an event for the given status and originator and fires it.
     229            void fire(bool status, BaseObject* originator = NULL);  //!< Helper method. Creates an Event for the given status and originator and fires it.
     230            void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target.
    216231
    217232            /**
     
    240255            static const std::string or_s;
    241256            static const std::string xor_s;
     257
     258            void subTrigggerActivityChanged(BaseObject* originator); //!< This method is called by any sub-trigger to advertise changes in it's state to it's parent-trigger.
    242259           
    243260            bool addState(MultiTriggerState* state); //!< Helper method. Adds a state to the state queue, where the state will wait to become active.
     
    266283            MultiTriggerMode::Value mode_; //!< The mode of the MultiTrigger.
    267284
     285            bool bBroadcast_; //!< Bool for the broadcast-mode, if true all triggers go to all possible targets.
     286
    268287            MultiTrigger* parentTrigger_;
    269288            std::set<MultiTrigger*> subTriggers_; //!< The sub-triggers of this MultiTrigger.
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.cc

    r6711 r6864  
    131131        if (GameMode::isMaster())
    132132            if (this->health_ <= 0 && bAlive_)
     133            {
     134                this->fireEvent(); // Event to notify anyone who want's to know about the death.
    133135                this->death();
     136            }
    134137    }
    135138
Note: See TracChangeset for help on using the changeset viewer.