Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 6, 2009, 4:56:42 AM (15 years ago)
Author:
landauf
Message:

Added support for named events (so one object can fire multiple different events).
Added a new class, EventFilter, to filter differently named events and map them to different states.

I've wrapped the event names with a pretty useless macro, but I want to expand this in the future and register possible event names in the Identifier of the corresponding class. This allows us to get the possible event names in a static manner and thus build an editor upon it.

Location:
code/branches/core5/src
Files:
4 added
7 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/BaseObject.cc

    r5887 r5888  
    300300        @brief Fires an event (without a state).
    301301    */
    302     void BaseObject::fireEvent()
    303     {
    304         this->fireEvent(true);
    305         this->fireEvent(false);
     302    void BaseObject::fireEvent(const std::string& name)
     303    {
     304        this->fireEvent(true, name);
     305        this->fireEvent(false, name);
    306306    }
    307307
     
    309309        @brief Fires an event which activates or deactivates a state.
    310310    */
    311     void BaseObject::fireEvent(bool activate)
    312     {
    313         this->fireEvent(activate, this);
     311    void BaseObject::fireEvent(bool activate, const std::string& name)
     312    {
     313        this->fireEvent(activate, this, name);
    314314    }
    315315
     
    317317        @brief Fires an event which activates or deactivates a state with agiven originator (the object which triggered the event).
    318318    */
    319     void BaseObject::fireEvent(bool activate, BaseObject* originator)
    320     {
    321         Event event(activate, originator);
     319    void BaseObject::fireEvent(bool activate, BaseObject* originator, const std::string& name)
     320    {
     321        Event event(activate, originator, name);
    322322
    323323        for (std::set<BaseObject*>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
  • code/branches/core5/src/libraries/core/BaseObject.h

    r5887 r5888  
    161161            BaseObject* getEventListener(unsigned int index) const;
    162162
    163             void fireEvent();
    164             void fireEvent(bool activate);
    165             void fireEvent(bool activate, BaseObject* originator);
     163            void fireEvent(const std::string& name = "");
     164            void fireEvent(bool activate, const std::string& name = "");
     165            void fireEvent(bool activate, BaseObject* originator, const std::string& name = "");
    166166            void fireEvent(Event& event);
    167167
  • code/branches/core5/src/libraries/core/Event.h

    r5879 r5888  
    4040    struct _CoreExport Event
    4141    {
    42         Event(bool activate, BaseObject* originator) : activate_(activate), originator_(originator) {}
     42        Event(bool activate, BaseObject* originator, const std::string& name) : activate_(activate), originator_(originator), name_(name) {}
    4343
    4444        bool        activate_;   //!< True if this is an activating event (the event source was inactive before and just triggered the event) - false otherwise
    4545        std::string statename_;  //!< The name of the state this event affects
    4646        BaseObject* originator_; //!< The object which triggered this event
     47        std::string name_;       //!< The name of this event
    4748    };
    4849
  • code/branches/core5/src/libraries/core/EventIncludes.h

    r5879 r5888  
    6868    static orxonox::ExecutorMember<classname>* xmlgetfunctor##name = (orxonox::ExecutorMember<classname>*)&orxonox::createExecutor(orxonox::createFunctor(&classname::getEventSource), std::string( #classname ) + "::" + "getEventSource" + "(" + statename + ")")->setDefaultValue(1, statename); \
    6969    XMLPortObjectGeneric(xmlport##name, classname, orxonox::BaseObject, statename, xmlsetfunctor##name, xmlgetfunctor##name, xmlelement, mode, false, true)
     70   
     71
     72/**
     73    @brief Defines a new event name for a class. Named events can only have names which were defined with this macro.
     74   
     75    @param classname The name of the class
     76    @param name      The name of the event
     77*/
     78#define CreateEventName(classname, name) \
     79    static std::string eventname##classname##name = #name
     80
     81/**
     82    @brief This macro is needed to fire an event with this name. The event name must previously be declared with @ref CreateEventName.
     83*/   
     84#define EventName(classname, name) \
     85    eventname##classname##name
    7086 
    7187#endif /* _EventIncludes_H__ */
  • code/branches/core5/src/modules/objects/ObjectsPrereqs.h

    r5858 r5888  
    7878    // eventsystem
    7979    class EventDispatcher;
     80    class EventFilter;
    8081    class EventListener;
     82    class EventName;
    8183    class EventTarget;
    8284
  • code/branches/core5/src/modules/objects/eventsystem/CMakeLists.txt

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

    r5866 r5888  
    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    }
Note: See TracChangeset for help on using the changeset viewer.