Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5890


Ignore:
Timestamp:
Oct 6, 2009, 5:29:39 AM (15 years ago)
Author:
landauf
Message:

Using target= instead of name= to define the target-object in EventTarget. This avoids possible loops if more than one EventTarget point to the same object, because the other EventTarget becomes a target itself, passing the event back and forth.

Location:
code/branches/core5
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/data/levels/events.oxw

    r5883 r5890  
    9696    <Billboard name="bb3" position="100,150,0" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 />
    9797    <Billboard name="bb3" position="100,150,100" material="Examples/Flare" colour="1.0, 1.0, 1.0" visible=0 />
    98     <EventTarget name="bb3">
     98    <EventTarget target="bb3">
    9999      <events>
    100100        <visibility>
     
    144144    <EventDispatcher>
    145145      <targets>
    146         <EventTarget name="bb5" />
     146        <EventTarget target="bb5" />
    147147      </targets>
    148148      <events>
  • code/branches/core5/data/levels/old/physicstest2.oxw

    r5700 r5890  
    243243    <!--EventDispatcher>
    244244      <targets>
    245         <EventTarget name=fireright />
    246         <EventTarget name=firecenter />
    247         <EventTarget name=fireleft />
     245        <EventTarget target=fireright />
     246        <EventTarget target=firecenter />
     247        <EventTarget target=fireleft />
    248248      </targets>
    249249      <events>
  • code/branches/core5/data/levels/old/princessaeryn.oxw

    r5700 r5890  
    264264            <EventDispatcher>
    265265                <targets>
    266                     <EventTarget name=trail />
     266                    <EventTarget target=trail />
    267267                </targets>
    268268                <events>
  • code/branches/core5/data/levels/old/sample4.oxw

    r5700 r5890  
    123123    <EventDispatcher>
    124124      <targets>
    125         <EventTarget name=fireright />
    126         <EventTarget name=firecenter />
    127         <EventTarget name=fireleft />
     125        <EventTarget target=fireright />
     126        <EventTarget target=firecenter />
     127        <EventTarget target=fireleft />
    128128      </targets>
    129129      <events>
  • code/branches/core5/data/levels/presentation.oxw

    r5695 r5890  
    151151    <EventDispatcher>
    152152      <targets>
    153         <EventTarget name=fireright />
    154         <EventTarget name=firecenter />
    155         <EventTarget name=fireleft />
     153        <EventTarget target=fireright />
     154        <EventTarget target=firecenter />
     155        <EventTarget target=fireleft />
    156156      </targets>
    157157      <events>
  • code/branches/core5/data/levels/presentation09b.oxw

    r5738 r5890  
    111111    <EventDispatcher>
    112112      <targets>
    113         <EventTarget name=pirates />
     113        <EventTarget target=pirates />
    114114      </targets>
    115115      <events>
     
    163163    <EventDispatcher>
    164164      <targets>
    165         <EventTarget name=attacker />
     165        <EventTarget target=attacker />
    166166      </targets>
    167167      <events>
  • code/branches/core5/data/levels/princessaeryn.oxw

    r5803 r5890  
    227227            <EventDispatcher>
    228228                <targets>
    229                     <EventTarget name=trail />
     229                    <EventTarget target=trail />
    230230                </targets>
    231231                <events>
  • code/branches/core5/src/modules/objects/eventsystem/EventTarget.cc

    r5887 r5890  
    3838    {
    3939        RegisterObject(EventTarget);
     40
     41        this->bActive_ = false;
    4042    }
    4143
     
    4850        SUPER(EventTarget, XMLPort, xmlelement, mode);
    4951
     52        XMLPortParam(EventTarget, "target", setTargetName, getTargetName, xmlelement, mode);
     53
    5054        // since we need event sources mapped to any state, we have to parse XML by ourselves
    5155        this->loadAllEventStates(xmlelement, mode, this, Class(EventTarget));
     
    5458    void EventTarget::processEvent(Event& event)
    5559    {
     60        if (this->bActive_)
     61        {
     62            COUT(2) << "Warning: Detected Event loop in EventTarget \"" << this->getName() << "\"" << std::endl;
     63            return;
     64        }
     65
     66        this->bActive_ = true;
    5667        this->fireEvent(event);
     68        this->bActive_ = false;
    5769    }
    5870
    59     void EventTarget::changedName()
     71    void EventTarget::setTargetName(const std::string& name)
    6072    {
    61         SUPER(EventTarget, changedName);
    62 
     73        this->target_ = name;
     74       
    6375        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
    64             if (it->getName() == this->getName())
     76            if (it->getName() == this->target_)
    6577                this->addEventTarget(*it);
    6678    }
     
    6880    void EventTarget::loadedNewXMLName(BaseObject* object)
    6981    {
    70         if (this->getName() == "")
     82        if (this->target_ == "")
    7183            return;
    7284
    73         if (object->getName() == this->getName())
     85        if (object->getName() == this->target_)
    7486            this->addEventTarget(object);
    7587    }
  • code/branches/core5/src/modules/objects/eventsystem/EventTarget.h

    r5887 r5890  
    4747            virtual void processEvent(Event& event);
    4848
    49             virtual void changedName();
     49            void setTargetName(const std::string& name);
     50            inline const std::string& getTargetName() const
     51                { return this->target_; }
    5052
    5153        private:
    5254            virtual void loadedNewXMLName(BaseObject* object);
    5355            void addEventTarget(BaseObject* object);
     56           
     57            std::string target_;
     58            bool bActive_;
    5459    };
    5560}
Note: See TracChangeset for help on using the changeset viewer.