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/BaseObject.h

    r5866 r5879  
    3737#define _BaseObject_H__
    3838
    39 #define SetMainState(classname, statename, setfunction, getfunction) \
    40     if (this->getMainStateName() == statename) \
    41     { \
    42         this->functorSetMainState_ = createFunctor(&classname::setfunction, this); \
    43         this->functorGetMainState_ = createFunctor(&classname::getfunction, this); \
    44     }
    45 
    46 
    4739#include "CorePrereqs.h"
    4840
     
    6961            virtual ~BaseObject();
    7062            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     63            virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
    7164
    7265            /** @brief Returns if the object was initialized (passed the object registration). @return True was the object is initialized */
     
    111104
    112105            void setMainState(bool state);
    113             bool getMainState() const;
    114 
    115             void setMainStateName(const std::string& name);
     106
     107            /** @brief Sets the name of the main state (used for event reactions). */
     108            void setMainStateName(const std::string& name)
     109            {
     110                if (this->mainStateName_ != name)
     111                {
     112                    this->mainStateName_ = name;
     113                    this->changedMainStateName();
     114                }
     115            }
     116            /** @brief Returns the name of the main state. */
    116117            inline const std::string& getMainStateName() const { return this->mainStateName_; }
    117             virtual void changedMainState();
     118            /** @brief This function gets called if the main state name of the object changes. */
     119            virtual void changedMainStateName();
    118120
    119121            /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */
     
    176178                { this->eventListeners_.erase(object); }
    177179
    178             void addEventContainer(const std::string& sectionname, EventContainer* container);
    179             EventContainer* getEventContainer(const std::string& sectionname) const;
     180            void addEventState(const std::string& name, EventState* container);
     181            EventState* getEventState(const std::string& name) const;
    180182
    181183            std::string name_;                                 //!< The name of the object
     
    184186            mbool       bVisible_;                             //!< True = the object is visible
    185187            std::string mainStateName_;
    186             Functor*    functorSetMainState_;
    187             Functor*    functorGetMainState_;
     188            Functor*    mainStateFunctor_;
    188189
    189190        private:
    190191            void setXMLName(const std::string& name);
    191192            Template* getTemplate(unsigned int index) const;
     193            void registerEventStates();
    192194
    193195            bool                   bInitialized_;              //!< True if the object was initialized (passed the object registration)
     
    204206            std::set<Template*>    templates_;
    205207           
    206             std::map<BaseObject*, std::string>      eventSources_;      //!< List of objects which send events to this object, mapped to the state which they affect
    207             std::set<BaseObject*>                   eventListeners_;    //!< List of objects which listen to the events of this object
    208             std::map<std::string, EventContainer*>  eventContainers_;
     208            std::map<BaseObject*, std::string>  eventSources_;           //!< List of objects which send events to this object, mapped to the state which they affect
     209            std::set<BaseObject*>               eventListeners_;         //!< List of objects which listen to the events of this object
     210            std::map<std::string, EventState*>  eventStates_;            //!< Maps the name of the event states to their helper objects
     211            bool                                bRegisteredEventStates_; //!< Becomes true after the object registered its event states (with XMLEventPort)
    209212    };
    210213
     
    212215    SUPER_FUNCTION(2, BaseObject, changedActivity, false);
    213216    SUPER_FUNCTION(3, BaseObject, changedVisibility, false);
    214     SUPER_FUNCTION(4, BaseObject, processEvent, false);
    215     SUPER_FUNCTION(6, BaseObject, changedMainState, false);
    216     SUPER_FUNCTION(9, BaseObject, changedName, false);
    217     SUPER_FUNCTION(10, BaseObject, changedGametype, false);
     217    SUPER_FUNCTION(4, BaseObject, XMLEventPort, false);
     218    SUPER_FUNCTION(8, BaseObject, changedName, false);
     219    SUPER_FUNCTION(9, BaseObject, changedGametype, false);
    218220}
    219221
Note: See TracChangeset for help on using the changeset viewer.