Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6859 for code/trunk


Ignore:
Timestamp:
May 6, 2010, 2:56:39 PM (14 years ago)
Author:
dafrick
Message:

Resolved a bug in MultiTriggerContainer that caused the MultiTriggerContainer not to be identified as a BaseObject. Also some performance optimization in MultiTrigger.

Location:
code/trunk/src
Files:
5 edited

Legend:

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

    r6800 r6859  
    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;
     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 << ")" << "." << std::endl;
    6262       
    6363        // check if the originator is an instance of the requested class
  • code/trunk/src/modules/objects/triggers/MultiTrigger.cc

    r6857 r6859  
    7171        this->bInvertMode_ = false;
    7272        this->mode_ = MultiTriggerMode::EventTriggerAND;
     73
     74        this->parentTrigger_ = NULL;
    7375       
    7476        this->targetMask_.exclude(Class(BaseObject));
     
    165167                }
    166168                else
     169                {
     170                    COUT(1) << "BUH" << std::endl;
    167171                    delete state;
     172                }
    168173               
    169174                queue->pop();
     
    259264                        // Print some debug output if the state has changed.
    260265                        if(bStateChanged)
     266                        {
    261267                            COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") changed state. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << bActive << ", triggered: " << state->bTriggered << "." << std::endl;
     268                            if(this->parentTrigger_ != NULL)
     269                                this->parentTrigger_->activityChanged(state->originator);
     270                        }
    262271
    263272                        // If the MultiTrigger has exceeded its amount of activations and it doesn't stay active, it has to be destroyed,
     
    386395        if (this != trigger && trigger != NULL)
    387396            this->subTriggers_.insert(trigger);
     397        trigger->addParentTrigger(this);
    388398    }
    389399
     
    423433    std::queue<MultiTriggerState*>* MultiTrigger::letTrigger(void)
    424434    {
    425         // Goes through all sub-triggers and gets the objects triggering them.
    426         std::set<BaseObject*>* triggerers = new std::set<BaseObject*>();
    427         std::set<BaseObject*>::iterator objIt;
    428         for(std::set<MultiTrigger*>::iterator it = this->subTriggers_.begin(); it != this->subTriggers_.end(); it ++)
    429         {
    430             std::set<BaseObject*> set = (*it)->getActive();
    431             for(objIt = set.begin(); objIt != set.end(); objIt++)
    432             {
    433                 triggerers->insert(*objIt);
    434             }
    435         }
    436 
    437         // Goes through all the triggerers of this trigger.
    438         for(objIt = this->active_.begin(); objIt != this->active_.end(); objIt++)
    439         {
    440             triggerers->insert(*objIt);
    441         }
    442 
    443         // If no objects are triggering this MultiTrigger or the sub-triggers.
    444         if(triggerers->size() == 0)
    445             return NULL;
    446 
    447         // Create a state for each object triggering this MultiTrigger or any of the sub-triggers and append it to the queue.
    448         std::queue<MultiTriggerState*>* queue = new std::queue<MultiTriggerState*>();
    449         MultiTriggerState* state = NULL;
    450         for(std::set<BaseObject*>::iterator it = triggerers->begin(); it != triggerers->end(); it++)
    451         {
    452             state = new MultiTriggerState;
    453             state->bTriggered = true;
    454             state->originator = *it;
    455             queue->push(state);
    456         }
    457         delete triggerers;
    458 
    459         return queue;
     435        return NULL;
     436    }
     437   
     438    void MultiTrigger::activityChanged(BaseObject* originator)
     439    {
     440        MultiTriggerState* state = new MultiTriggerState;
     441        state->bTriggered = (this->isTriggered(originator) & this->isModeTriggered(originator)) ^ this->bInvertMode_;
     442        state->originator = originator;
     443        this->addState(state);
    460444    }
    461445
  • code/trunk/src/modules/objects/triggers/MultiTrigger.h

    r6857 r6859  
    207207        protected:
    208208            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.
     209
     210            void activityChanged(BaseObject* originator);
    209211           
    210212            bool isModeTriggered(BaseObject* triggerer = NULL); //!< Checks whetherx the MultiTrigger is triggered concerning it's sub-triggers.
     
    213215            void fire(bool status, BaseObject* originator = NULL);  //!< Helper method. Creates an event for the given status and originator and fires it.
    214216
     217            /**
     218            @brief Adds the parent of a MultiTrigger.
     219            @param parent A pointer to the parent MultiTrigger.
     220            */
     221            inline void addParentTrigger(MultiTrigger* parent)
     222                { this->parentTrigger_ = parent; }
     223           
    215224            /**
    216225            @brief Get the target mask used to identify the targets of this MultiTrigger.
     
    257266            MultiTriggerMode::Value mode_; //!< The mode of the MultiTrigger.
    258267
     268            MultiTrigger* parentTrigger_;
    259269            std::set<MultiTrigger*> subTriggers_; //!< The sub-triggers of this MultiTrigger.
    260270           
  • code/trunk/src/modules/objects/triggers/MultiTriggerContainer.cc

    r6856 r6859  
    3838namespace orxonox
    3939{
     40
     41    CreateUnloadableFactory(MultiTriggerContainer);
    4042   
    4143    /**
  • code/trunk/src/modules/questsystem/QuestEffectBeacon.cc

    r6800 r6859  
    7676        XMLPortObject(QuestEffectBeacon, QuestEffect, "effects", addEffect, getEffect, xmlelement, mode);
    7777
    78         XMLPortEventState(QuestEffectBeacon, BaseObject, "execute", execute, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
     78        XMLPortEventSink(QuestEffectBeacon, BaseObject, "execute", execute, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
    7979
    8080        COUT(3) << "New QuestEffectBeacon created." << std::endl;
Note: See TracChangeset for help on using the changeset viewer.