Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 12, 2009, 8:20:07 PM (15 years ago)
Author:
rgrieder
Message:

Merged core5 branch back to the trunk.
Key features include clean level unloading and an extended XML event system.

Two important notes:
Delete your keybindings.ini files! * or you will still get parser errors when loading the key bindings.
Delete build_dir/lib/modules/libgamestates.module! * or orxonox won't start.
Best thing to do is to delete the build folder ;)

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/libraries/core/BaseObject.h

    r5781 r5929  
    3737#define _BaseObject_H__
    3838
    39 #define SetMainState(classname, statename, setfunction, getfunction) \
    40     if (this->getMainStateName() == statename) \
    41     { \
    42         this->functorSetMainState_ = createFunctor(&classname::setfunction)->setObject(this); \
    43         this->functorGetMainState_ = createFunctor(&classname::getfunction)->setObject(this); \
    44     }
    45 
    46 
    4739#include "CorePrereqs.h"
    4840
     
    5345#include "OrxonoxClass.h"
    5446#include "Super.h"
     47#include "SmartPtr.h"
    5548
    5649namespace orxonox
     
    6861            virtual ~BaseObject();
    6962            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
     63            virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
    7064
    7165            /** @brief Returns if the object was initialized (passed the object registration). @return True was the object is initialized */
     
    110104
    111105            void setMainState(bool state);
    112             bool getMainState() const;
    113 
    114             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. */
    115117            inline const std::string& getMainStateName() const { return this->mainStateName_; }
    116             virtual void changedMainState();
     118            /** @brief This function gets called if the main state name of the object changes. */
     119            virtual void changedMainStateName();
    117120
    118121            /** @brief Sets a pointer to the xml file that loaded this object. @param file The pointer to the XMLFile */
     
    134137            inline BaseObject* getCreator() const { return this->creator_; }
    135138
    136             inline void setScene(Scene* scene) { this->scene_ = scene; }
    137             inline Scene* getScene() const { return this->scene_; }
    138 
    139             inline void setGametype(Gametype* gametype)
     139            inline void setScene(const SmartPtr<Scene>& scene, uint32_t sceneID) { this->scene_ = scene; this->sceneID_=sceneID; }
     140            inline const SmartPtr<Scene>& getScene() const { return this->scene_; }
     141            inline virtual uint32_t getSceneID() const { return this->sceneID_; }
     142
     143            inline void setGametype(const SmartPtr<Gametype>& gametype)
    140144            {
    141145                if (gametype != this->gametype_)
     
    146150                }
    147151            }
    148             inline Gametype* getGametype() const { return this->gametype_; }
     152            inline const SmartPtr<Gametype>& getGametype() const { return this->gametype_; }
    149153            inline Gametype* getOldGametype() const { return this->oldGametype_; }
    150154            virtual void changedGametype() {}
    151155
    152             void fireEvent();
    153             void fireEvent(bool activate);
    154             void fireEvent(bool activate, BaseObject* originator);
     156            void addEventSource(BaseObject* source, const std::string& state);
     157            void removeEventSource(BaseObject* source);
     158            BaseObject* getEventSource(unsigned int index, const std::string& state) const;
     159           
     160            void addEventListener(BaseObject* listener);
     161            BaseObject* getEventListener(unsigned int index) const;
     162
     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 = "");
    155166            void fireEvent(Event& event);
    156167
    157168            virtual void processEvent(Event& event);
    158 
    159             inline void registerEventListener(BaseObject* object, const std::string& sectionname)
    160                 { this->eventListeners_[object] = sectionname; }
    161             inline void unregisterEventListener(BaseObject* object)
    162                 { this->eventListeners_.erase(object); }
    163 
    164             void addEvent(BaseObject* event, const std::string& sectionname);
    165             void removeEvent(BaseObject* event);
    166             BaseObject* getEvent(unsigned int index) const;
    167 
    168             void addEventContainer(const std::string& sectionname, EventContainer* container);
    169             EventContainer* getEventContainer(const std::string& sectionname) const;
    170169
    171170            /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */
     
    173172            /** @brief Returns the indentation of the debug output in the Loader. @return The indentation */
    174173            inline const std::string& getLoaderIndentation() const { return this->loaderIndentation_; }
     174           
     175            static void loadAllEventStates(Element& xmlelement, XMLPort::Mode mode, BaseObject* object, Identifier* identifier);
    175176
    176177        protected:
     178            void addEventState(const std::string& name, EventState* container);
     179            EventState* getEventState(const std::string& name) const;
     180
    177181            std::string name_;                                 //!< The name of the object
    178182            std::string oldName_;                              //!< The old name of the object
     
    180184            mbool       bVisible_;                             //!< True = the object is visible
    181185            std::string mainStateName_;
    182             Functor*    functorSetMainState_;
    183             Functor*    functorGetMainState_;
     186            Functor*    mainStateFunctor_;
    184187
    185188        private:
     189            /** @brief Adds an object which listens to the events of this object. */
     190            inline void registerEventListener(BaseObject* object)
     191                { this->eventListeners_.insert(object); }
     192            /** @brief Removes an event listener from this object. */
     193            inline void unregisterEventListener(BaseObject* object)
     194                { this->eventListeners_.erase(object); }
     195
    186196            void setXMLName(const std::string& name);
    187197            Template* getTemplate(unsigned int index) const;
     198            void registerEventStates();
    188199
    189200            bool                   bInitialized_;              //!< True if the object was initialized (passed the object registration)
     
    194205            Namespace*             namespace_;
    195206            BaseObject*            creator_;
    196             Scene*                 scene_;
    197             Gametype*              gametype_;
     207            SmartPtr<Scene>        scene_;
     208            uint32_t               sceneID_;
     209            SmartPtr<Gametype>     gametype_;
    198210            Gametype*              oldGametype_;
    199211            std::set<Template*>    templates_;
    200             std::map<BaseObject*,  std::string> eventListeners_;
    201             std::list<BaseObject*> events_;
    202             std::map<std::string, EventContainer*> eventContainers_;
     212           
     213            std::map<BaseObject*, std::string>  eventSources_;           //!< List of objects which send events to this object, mapped to the state which they affect
     214            std::set<BaseObject*>               eventListeners_;         //!< List of objects which listen to the events of this object
     215            std::set<BaseObject*>               eventListenersXML_;      //!< List of objects which listen to the events of this object through the "eventlisteners" subsection in XML
     216            std::map<std::string, EventState*>  eventStates_;            //!< Maps the name of the event states to their helper objects
     217            bool                                bRegisteredEventStates_; //!< Becomes true after the object registered its event states (with XMLEventPort)
    203218    };
    204219
     
    206221    SUPER_FUNCTION(2, BaseObject, changedActivity, false);
    207222    SUPER_FUNCTION(3, BaseObject, changedVisibility, false);
    208     SUPER_FUNCTION(4, BaseObject, processEvent, false);
    209     SUPER_FUNCTION(6, BaseObject, changedMainState, false);
    210     SUPER_FUNCTION(9, BaseObject, changedName, false);
    211     SUPER_FUNCTION(10, BaseObject, changedGametype, false);
     223    SUPER_FUNCTION(4, BaseObject, XMLEventPort, false);
     224    SUPER_FUNCTION(8, BaseObject, changedName, false);
     225    SUPER_FUNCTION(9, BaseObject, changedGametype, false);
    212226}
    213227
Note: See TracChangeset for help on using the changeset viewer.