Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6851 for code/trunk


Ignore:
Timestamp:
May 3, 2010, 9:52:45 PM (15 years ago)
Author:
dafrick
Message:

Some bugfixes in MultiTrigger.
All MultiTrigger features should work now, but testing has not been done as rigorously as could be desired.

Location:
code/trunk/src/modules/objects/triggers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/objects/triggers/MultiTrigger.cc

    r6805 r6851  
    7878    }
    7979   
    80     //TODO: Clean up?
     80    //TODO: Document.
    8181    void MultiTrigger::XMLPort(Element& xmlelement, XMLPort::Mode mode)
    8282    {
     
    9494        XMLPortObject(MultiTrigger, MultiTrigger, "", addTrigger, getTrigger, xmlelement, mode);
    9595       
    96         COUT(4) << "MultiTrigger &" << this << " created." << std::endl;
     96        COUT(4) << "MultiTrigger '" << this->getName() << "' (&" << this << ") created." << std::endl;
    9797    }
    9898   
     
    113113       
    114114        std::queue<MultiTriggerState*>* queue  = this->letTrigger();
    115         if(queue != NULL)
    116             COUT(4) << "MultiTrigger &" << this << ": " << queue->size() << " new states to state queue." << std::endl;
    117115       
    118116        if(queue != NULL)
     
    124122                if(state == NULL)
    125123                    break;
    126                    
    127                 this->addState(state->bTriggered & this->isModeTriggered(state->originator), state->originator);
     124
     125                bool bTriggered = (state->bTriggered & this->isModeTriggered(state->originator)) ^ this->bInvertMode_;
     126                if(bTriggered ^ this->isTriggered(state->originator))
     127                    this->addState(bTriggered, state->originator);
    128128                queue->pop();
    129129                delete state;
    130130            }
    131131            delete queue;
    132         }
     132        }       
    133133
    134134        if (this->stateQueue_.size() > 0)
     
    172172                    // Remove the state from the state queue.
    173173                    this->stateQueue_.pop_front();
    174                     COUT(4) << "MultiTrigger &" << this << ": State processed, removing from state queue. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << state->bActive << "|" << this->isActive(state->originator) << ", triggered: " << state->bTriggered << "|" << this->isTriggered(state->originator) << "." << std::endl;
     174                    COUT(4) << "MultiTrigger '" << this->getName() << "' &" << this << ": State processed, removing from state queue. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << state->bActive << "|" << this->isActive(state->originator) << ", triggered: " << state->bTriggered << "|" << this->isTriggered(state->originator) << "." << std::endl;
    175175                    delete state;
    176176                    size -= 1;
     
    180180                    this->stateQueue_.push_back(std::pair<float, MultiTriggerState*>(timeRemaining-dt, state));
    181181                    this->stateQueue_.pop_front();
    182                     COUT(4) << "MultiTrigger &" << this << ": State processed, decreasing time remaining. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << state->bActive << ", triggered: " << state->bTriggered << ", time remaining: " << timeRemaining-dt << "." << std::endl;
     182                    COUT(4) << "MultiTrigger '" << this->getName() << "' &" << this << ": State processed, decreasing time remaining. originator: " << state->originator->getIdentifier()->getName() << " (&" << state->originator << "), active: " << state->bActive << ", triggered: " << state->bTriggered << ", time remaining: " << timeRemaining-dt << "." << std::endl;
    183183                }
    184184            }
     
    218218    std::queue<MultiTriggerState*>* MultiTrigger::letTrigger(void)
    219219    {
     220        // Goes through all trigger children and gets the objects triggering them.
     221        std::set<BaseObject*>* triggerers = new std::set<BaseObject*>();
     222        std::set<BaseObject*>::iterator objIt;
     223        for(std::set<MultiTrigger*>::iterator it = this->children_.begin(); it != this->children_.end(); it ++)
     224        {
     225            std::set<BaseObject*> set = (*it)->getActive();
     226            for(objIt = set.begin(); objIt != set.end(); objIt++)
     227            {
     228                triggerers->insert(*objIt);
     229            }
     230        }
     231
     232        // Goes through all the triggerers of this trigger.
     233        for(objIt = this->active_.begin(); objIt != this->active_.end(); objIt++)
     234        {
     235            triggerers->insert(*objIt);
     236        }
     237
     238        if(triggerers->size() == 0)
     239            return NULL;
     240       
    220241        std::queue<MultiTriggerState*>* queue = new std::queue<MultiTriggerState*>();
    221         MultiTriggerState* state = new MultiTriggerState;
    222         state->bTriggered = true;
    223         state->originator = NULL;
    224         queue->push(state);
     242        MultiTriggerState* state = NULL;
     243        for(std::set<BaseObject*>::iterator it = triggerers->begin(); it != triggerers->end(); it++)
     244        {
     245            state = new MultiTriggerState;
     246            state->bTriggered = true;
     247            state->originator = *it;
     248            queue->push(state);
     249        }
     250        delete triggerers;
     251       
    225252        return queue;
    226253    }
     
    280307            return false;
    281308       
    282         bTriggered ^= this->bInvertMode_;
    283309        // If the state doesn't change.
    284310        if(this->isTriggered() && bTriggered)
     
    289315        // If the MultiTrigger is in switch mode.
    290316        if(this->bSwitch_ && !bTriggered)
    291             return false;
    292        
     317        {
     318            bActive = this->isActive(originator);
     319        }
    293320        // If the state changes to active.
    294         if(this->remainingActivations_ != INF_s && bActive)
     321        else if(this->remainingActivations_ != INF_s && bActive)
    295322        {
    296323            if(this->remainingActivations_ == 0)
     
    300327        else
    301328        {
    302             // If the MultiTrigger should stay active and there are no more remaining activations.
     329            // If the MultiTrigger should stay active if there are no more remaining activations.
     330            //TODO: Find out how this applies to infinitely many activations.
    303331            if(this->bStayActive_ && this->remainingActivations_ == 0)
    304332                return false;
    305333        }
    306334       
    307         COUT(4) << "MultiTrigger &" << this << ": State added to state queue. originator: " << originator->getIdentifier()->getName() << " (&" << originator << "), active: " << bActive << "|" << this->isActive(originator) << ", triggered: " << bTriggered << "|" << this->isTriggered(originator) << "." << std::endl;
     335        COUT(4) << "MultiTrigger &" << this << ": State added to state queue. originator: " << originator->getIdentifier()->getName() << " (&" << originator << "), active: " << bActive << "|" << this->isActive(originator) << ", triggered: " << bTriggered << "|" << this->isTriggered(originator) << ", remaining activations: " << this->remainingActivations_ << "." << std::endl;
    308336       
    309337        // Create state.
  • code/trunk/src/modules/objects/triggers/MultiTrigger.h

    r6800 r6851  
    6060        bool bTriggered;
    6161    };
    62    
     62
     63    /**
     64    @brief
     65        The MultiTrigger class implements a trigger that has a distinct state for each object triggering it.
     66    */
    6367    class _ObjectsExport MultiTrigger : public StaticEntity, public Tickable
    6468    {
     
    140144            bool checkXor(BaseObject* triggerer);
    141145
     146            std::set<BaseObject*>& getActive(void)
     147                { return this->active_; }
     148
    142149            bool bFirstTick_;
    143150
Note: See TracChangeset for help on using the changeset viewer.