Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 13, 2009, 5:05:17 PM (15 years ago)
Author:
dafrick
Message:

Hopefully merged trunk successfully into pickup branch.

Location:
code/branches/pickup
Files:
8 edited
4 copied

Legend:

Unmodified
Added
Removed
  • code/branches/pickup

  • code/branches/pickup/src/modules/objects/eventsystem/CMakeLists.txt

    r5781 r5935  
    11ADD_SOURCE_FILES(OBJECTS_SRC_FILES
    22  EventDispatcher.cc
     3  EventFilter.cc
    34  EventListener.cc
     5  EventName.cc
    46  EventTarget.cc
    57)
  • code/branches/pickup/src/modules/objects/eventsystem/EventDispatcher.cc

    r5781 r5935  
    3232#include "core/EventIncludes.h"
    3333#include "core/XMLPort.h"
    34 #include "EventTarget.h"
    3534
    3635namespace orxonox
     
    4645    {
    4746        if (this->isInitialized())
    48             for (std::list<EventTarget*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it)
    49                 delete (*it);
     47            for (std::list<BaseObject*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it)
     48                (*it)->destroy();
    5049    }
    5150
     
    5453        SUPER(EventDispatcher, XMLPort, xmlelement, mode);
    5554
    56         XMLPortObject(EventDispatcher, EventTarget, "targets", addTarget, getTarget, xmlelement, mode);
     55        XMLPortObject(EventDispatcher, BaseObject, "targets", addTarget, getTarget, xmlelement, mode);
     56
     57        // since we need event sources mapped to any state, we have to parse XML by ourselves
     58        this->loadAllEventStates(xmlelement, mode, this, Class(EventDispatcher));
    5759    }
    5860
    5961    void EventDispatcher::processEvent(Event& event)
    6062    {
    61         for (std::list<EventTarget*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it)
    62             (*it)->fireEvent(event);
     63        for (std::list<BaseObject*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it)
     64            (*it)->processEvent(event);
    6365    }
    6466
    65     void EventDispatcher::addTarget(EventTarget* target)
     67    void EventDispatcher::addTarget(BaseObject* target)
    6668    {
    6769        this->targets_.push_back(target);
    6870    }
    6971
    70     EventTarget* EventDispatcher::getTarget(unsigned int index) const
     72    BaseObject* EventDispatcher::getTarget(unsigned int index) const
    7173    {
    7274        unsigned int i = 0;
    73         for (std::list<EventTarget*>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); ++it)
     75        for (std::list<BaseObject*>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); ++it)
    7476        {
    7577            if (i == index)
  • code/branches/pickup/src/modules/objects/eventsystem/EventDispatcher.h

    r5781 r5935  
    4747            virtual void processEvent(Event& event);
    4848
    49             void addTarget(EventTarget* target);
    50             EventTarget* getTarget(unsigned int index) const;
     49            void addTarget(BaseObject* target);
     50            BaseObject* getTarget(unsigned int index) const;
    5151
    5252        private:
    53             std::list<EventTarget*> targets_;
     53            std::list<BaseObject*> targets_;
    5454    };
    5555}
  • code/branches/pickup/src/modules/objects/eventsystem/EventListener.cc

    r5781 r5935  
    6363
    6464        this->bActive_ = true;
    65 
    66         this->fireEvent(event.activate_, event.originator_);
    67 
     65        this->fireEvent(event.activate_, event.originator_, event.name_);
    6866        this->bActive_ = false;
    6967    }
     
    7876        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
    7977            if (it->getName() == this->eventName_)
    80                 this->registerAsListener(*it);
     78                this->addEventSource(*it, "");
    8179    }
    8280
     
    8785
    8886        if (object->getName() == this->eventName_)
    89             this->registerAsListener(object);
    90     }
    91 
    92     void EventListener::registerAsListener(BaseObject* object)
    93     {
    94         object->registerEventListener(this, "");
     87            this->addEventSource(object, "");
    9588    }
    9689}
  • code/branches/pickup/src/modules/objects/eventsystem/EventListener.h

    r5781 r5935  
    5454        private:
    5555            virtual void loadedNewXMLName(BaseObject* object);
    56             void registerAsListener(BaseObject* object);
    5756
    5857            std::string eventName_;
  • code/branches/pickup/src/modules/objects/eventsystem/EventTarget.cc

    r5781 r5935  
    2929#include "EventTarget.h"
    3030#include "core/CoreIncludes.h"
     31#include "core/XMLPort.h"
    3132
    3233namespace orxonox
     
    3738    {
    3839        RegisterObject(EventTarget);
     40
     41        this->bActive_ = false;
    3942    }
    4043
     
    4245    {
    4346    }
     47   
     48    void EventTarget::XMLPort(Element& xmlelement, XMLPort::Mode mode)
     49    {
     50        SUPER(EventTarget, XMLPort, xmlelement, mode);
    4451
    45     void EventTarget::changedName()
     52        XMLPortParam(EventTarget, "target", setTargetName, getTargetName, xmlelement, mode);
     53
     54        // since we need event sources mapped to any state, we have to parse XML by ourselves
     55        this->loadAllEventStates(xmlelement, mode, this, Class(EventTarget));
     56    }
     57
     58    void EventTarget::processEvent(Event& event)
    4659    {
    47         SUPER(EventTarget, changedName);
     60        if (this->bActive_)
     61        {
     62            COUT(2) << "Warning: Detected Event loop in EventTarget \"" << this->getName() << "\"" << std::endl;
     63            return;
     64        }
    4865
     66        this->bActive_ = true;
     67        this->fireEvent(event);
     68        this->bActive_ = false;
     69    }
     70
     71    void EventTarget::setTargetName(const std::string& name)
     72    {
     73        this->target_ = name;
     74       
    4975        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
    50             if (it->getName() == this->getName())
    51                 this->addAsEvent(*it);
     76            if (it->getName() == this->target_)
     77                this->addEventTarget(*it);
    5278    }
    5379
    5480    void EventTarget::loadedNewXMLName(BaseObject* object)
    5581    {
    56         if (this->getName() == "")
     82        if (this->target_ == "")
    5783            return;
    5884
    59         if (object->getName() == this->getName())
    60             this->addAsEvent(object);
     85        if (object->getName() == this->target_)
     86            this->addEventTarget(object);
    6187    }
    6288
    63     void EventTarget::addAsEvent(BaseObject* object)
     89    void EventTarget::addEventTarget(BaseObject* object)
    6490    {
    6591        if (object != static_cast<BaseObject*>(this))
    66             object->addEvent(this, "");
     92            object->addEventSource(this, "");
    6793    }
    6894}
  • code/branches/pickup/src/modules/objects/eventsystem/EventTarget.h

    r5781 r5935  
    4242            EventTarget(BaseObject* creator);
    4343            virtual ~EventTarget();
     44           
     45            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     46           
     47            virtual void processEvent(Event& event);
    4448
    45             virtual void changedName();
     49            void setTargetName(const std::string& name);
     50            inline const std::string& getTargetName() const
     51                { return this->target_; }
    4652
    4753        private:
    4854            virtual void loadedNewXMLName(BaseObject* object);
    49             void addAsEvent(BaseObject* object);
     55            void addEventTarget(BaseObject* object);
     56           
     57            std::string target_;
     58            bool bActive_;
    5059    };
    5160}
Note: See TracChangeset for help on using the changeset viewer.