Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 5, 2009, 5:02:25 PM (15 years ago)
Author:
landauf
Message:

More changes in the event-system: processEvent() is now locally executed in BaseObject. The event states (like activity, visibility, …) are now defined in XMLEventPort, a function which closely resembles XMLPort. This function is used to define event states and to parse event sources from XML.

Connected the main-state directly with the event-system. After a state was declared as the "main state", the Functor from the corresponding EventState-object is used to call the function. This reduces the redundancy of declaring event-states and main-states separately. Of course only boolean event-states (like activity or visibility) can be used as main-state, while memoryless states (like spawn in ParticleSpawner) and individual states which need the triggering object (like execute in QuestEffectBeacon) won't work.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/core5/src/libraries/core/Event.h

    r5866 r5879  
    3535namespace orxonox
    3636{
     37    /**
     38        @brief The Event struct contains information about a fired Event.
     39    */
    3740    struct _CoreExport Event
    3841    {
    39             Event(bool activate, BaseObject* originator) : activate_(activate), originator_(originator), castedOriginator_(0) {}
     42        Event(bool activate, BaseObject* originator) : activate_(activate), originator_(originator) {}
    4043
    41             bool        activate_;
    42             BaseObject* originator_;
    43             void*       castedOriginator_;
    44             std::string sectionname_;
     44        bool        activate_;   //!< True if this is an activating event (the event source was inactive before and just triggered the event) - false otherwise
     45        std::string statename_;  //!< The name of the state this event affects
     46        BaseObject* originator_; //!< The object which triggered this event
    4547    };
    4648
    47     class _CoreExport EventContainer
     49    /**
     50        @brief The EventState contains information about an event state.
     51       
     52        An event state is a state of an object, which can be changed by events.
     53        Event states are changed through functions. Possible functions headers for set event states are:
     54         - memoryless state: function()
     55         - boolean state:    function(bool state)
     56         - individual state: function(bool state, SomeClass originator)
     57         
     58        Note that SomeClass may be any class deriving from BaseObject. You will not receive events from originators of other classes.
     59        The actual class for SomeClass must be specified as the second argument of the XMLPortEventState macro.
     60       
     61        The this pointer of the affected object is hidden in the functors, because the events are processed in the BaseObject, but some
     62        statefunctions may be from child-classes.
     63    */
     64    class _CoreExport EventState
    4865    {
    4966        public:
    50             EventContainer(const std::string& eventname, Functor* eventfunction, Identifier* subclass) : bActive_(false), eventname_(eventname), eventfunction_(eventfunction), subclass_(subclass), activeEvents_(0) {}
    51             virtual ~EventContainer();
     67            EventState(Functor* statefunction, Identifier* subclass) : bProcessingEvent_(false), activeEvents_(0), statefunction_(statefunction), subclass_(subclass) {}
     68            virtual ~EventState();
    5269
    53             void process(BaseObject* object, const Event& event);
     70            void process(const Event& event, BaseObject* object);
     71           
     72            Functor* getFunctor() const
     73                { return this->statefunction_; }
    5474
    5575        private:
    56             bool bActive_;
    57             std::string eventname_;
    58             Functor* eventfunction_;
    59             Identifier* subclass_;
    60 
    61             int activeEvents_;
     76            bool        bProcessingEvent_;  //!< This becomes true while the container processes an event (used to prevent loops)
     77            int         activeEvents_;      //!< The number of events which affect this state and are currently active
     78            Functor*    statefunction_;     //!< A functor to set the state
     79            Identifier* subclass_;          //!< Originators must be an instance of this class (usually BaseObject, but some statefunctions allow a second argument with an originator of a specific class)
    6280    };
    6381}
Note: See TracChangeset for help on using the changeset viewer.