Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2063


Ignore:
Timestamp:
Oct 29, 2008, 6:39:31 PM (15 years ago)
Author:
landauf
Message:

added events but not yet connected with triggers

Location:
code/branches/objecthierarchy/src
Files:
2 added
10 edited

Legend:

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

    r2019 r2063  
    9494
    9595        XMLPortObjectTemplate(BaseObject, Template, "templates", addTemplate, getTemplate, xmlelement, mode, Template*);
     96
     97        Element* events = xmlelement.FirstChildElement("events", false);
     98
     99        if (events)
     100        {
     101            std::list<std::string> eventnames;
     102
     103            if (mode == XMLPort::LoadObject)
     104            {
     105                for (ticpp::Iterator<ticpp::Element> child = events->FirstChildElement(false); child != child.end(); child++)
     106                    eventnames.push_back(child->Value());
     107            }
     108            else if (mode == XMLPort::SaveObject)
     109            {
     110                for (std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->getIdentifier()->getXMLPortEventMapBegin(); it != this->getIdentifier()->getXMLPortEventMapEnd(); ++it)
     111                    eventnames.push_back(it->first);
     112            }
     113
     114            for (std::list<std::string>::iterator it = eventnames.begin(); it != eventnames.end(); ++it)
     115            {
     116                std::string sectionname = (*it);
     117                ExecutorMember<BaseObject>* loadexecutor = createExecutor(createFunctor(&BaseObject::addEvent), std::string( "BaseObject" ) + "::" + "addEvent");
     118                ExecutorMember<BaseObject>* saveexecutor = createExecutor(createFunctor(&BaseObject::getEvent), std::string( "BaseObject" ) + "::" + "getEvent");
     119                loadexecutor->setDefaultValue(1, sectionname);
     120
     121                XMLPortClassObjectContainer<BaseObject, BaseObject>* container = 0;
     122                container = (XMLPortClassObjectContainer<BaseObject, BaseObject>*)(this->getIdentifier()->getXMLPortEventContainer(sectionname));
     123                if (!container)
     124                {
     125                    container = new XMLPortClassObjectContainer<BaseObject, BaseObject>(sectionname, this->getIdentifier(), loadexecutor, saveexecutor, false, true);
     126                    this->getIdentifier()->addXMLPortEventContainer(sectionname, container);
     127                }
     128                container->port(this, *events, mode);
     129            }
     130        }
    96131    }
    97132
     
    146181        return 0;
    147182    }
     183
     184    void BaseObject::addEvent(BaseObject* event, const std::string& sectionname)
     185    {
     186        this->eventListeners_.insert(std::pair<std::string, BaseObject*>(sectionname, event));
     187    }
     188
     189    BaseObject* BaseObject::getEvent(unsigned int index) const
     190    {
     191        unsigned int i = 0;
     192        for (std::set<std::pair<std::string, BaseObject*> >::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
     193        {
     194            if (i == index)
     195                return (*it).second;
     196            ++i;
     197        }
     198        return 0;
     199    }
     200
     201    void BaseObject::addEventContainer(const std::string& sectionname, EventContainer* container)
     202    {
     203        std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.find(sectionname);
     204        if (it != this->eventContainers_.end())
     205        {
     206            COUT(2) << "Warning: Overwriting EventContainer in class " << this->getIdentifier()->getName() << "." << std::endl;
     207            delete (it->second);
     208        }
     209
     210        this->eventContainers_[sectionname] = container;
     211    }
     212
     213    EventContainer* BaseObject::getEventContainer(const std::string& sectionname) const
     214    {
     215        std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.begin();
     216        if (it != this->eventContainers_.end())
     217            return ((*it).second);
     218        else
     219            return 0;
     220    }
     221
     222    void BaseObject::fireEvent()
     223    {
     224        this->fireEvent(true);
     225        this->fireEvent(false);
     226    }
     227
     228    void BaseObject::fireEvent(bool activate)
     229    {
     230        Event event(activate, this);
     231
     232        for (std::set<std::pair<std::string, BaseObject*> >::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
     233        {
     234            event.sectionname_ = (*it).first;
     235            (*it).second->processEvent(event);
     236        }
     237    }
     238
     239    void BaseObject::processEvent(Event& event)
     240    {
     241        SetEvent(BaseObject, "activity", setActive, event);
     242        SetEvent(BaseObject, "visibility", setVisible, event);
     243    }
    148244}
  • code/branches/objecthierarchy/src/core/BaseObject.h

    r2019 r2063  
    4242#include "OrxonoxClass.h"
    4343#include "XMLIncludes.h"
     44#include "Event.h"
    4445
    4546namespace orxonox
     
    110111            virtual inline void changedGametype() {}
    111112
     113            void fireEvent();
     114            void fireEvent(bool activate);
     115
     116            virtual void processEvent(Event& event);
     117
     118            void addEvent(BaseObject* event, const std::string& sectionname);
     119            BaseObject* getEvent(unsigned int index) const;
     120
     121            void addEventContainer(const std::string& sectionname, EventContainer* container);
     122            EventContainer* getEventContainer(const std::string& sectionname) const;
     123
    112124            /** @brief Sets the indentation of the debug output in the Loader. @param indentation The indentation */
    113125            inline void setLoaderIndentation(const std::string& indentation) { this->loaderIndentation_ = indentation; }
     
    124136            Template* getTemplate(unsigned int index) const;
    125137
    126             bool                bInitialized_;         //!< True if the object was initialized (passed the object registration)
    127             const XMLFile*      file_;                 //!< The XMLFile that loaded this object
    128             std::string         loaderIndentation_;    //!< Indentation of the debug output in the Loader
    129             Namespace*          namespace_;
    130             BaseObject*         creator_;
    131             Scene*              scene_;
    132             Gametype*           gametype_;
    133             Gametype*           oldGametype_;
    134             std::set<Template*> templates_;
     138            bool                  bInitialized_;         //!< True if the object was initialized (passed the object registration)
     139            const XMLFile*        file_;                 //!< The XMLFile that loaded this object
     140            std::string           loaderIndentation_;    //!< Indentation of the debug output in the Loader
     141            Namespace*            namespace_;
     142            BaseObject*           creator_;
     143            Scene*                scene_;
     144            Gametype*             gametype_;
     145            Gametype*             oldGametype_;
     146            std::set<Template*>   templates_;
     147            std::set<std::pair<std::string, BaseObject*> > eventListeners_;
     148            std::map<std::string, EventContainer*> eventContainers_;
    135149    };
    136150
     
    138152    SUPER_FUNCTION(2, BaseObject, changedActivity, false);
    139153    SUPER_FUNCTION(3, BaseObject, changedVisibility, false);
     154    SUPER_FUNCTION(4, BaseObject, processEvent, false);
    140155}
    141156
  • code/branches/objecthierarchy/src/core/CMakeLists.txt

    r1989 r2063  
    44  ConfigValueContainer.cc
    55  Core.cc
     6  Event.cc
    67  GameState.cc
    78  Language.cc
  • code/branches/objecthierarchy/src/core/CorePrereqs.h

    r2010 r2063  
    113113  class ConsoleCommand;
    114114  class Core;
     115  struct Event;
     116  class EventContainer;
    115117  class Executor;
    116118  template <class T>
  • code/branches/objecthierarchy/src/core/Identifier.cc

    r2019 r2063  
    421421    XMLPortParamContainer* Identifier::getXMLPortParamContainer(const std::string& paramname)
    422422    {
    423         std::map<std::string, XMLPortParamContainer*>::const_iterator it = xmlportParamContainers_.find(paramname);
    424         if (it != xmlportParamContainers_.end())
     423        std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname);
     424        if (it != this->xmlportParamContainers_.end())
    425425            return ((*it).second);
    426426        else
     
    435435    void Identifier::addXMLPortParamContainer(const std::string& paramname, XMLPortParamContainer* container)
    436436    {
     437        std::map<std::string, XMLPortParamContainer*>::const_iterator it = this->xmlportParamContainers_.find(paramname);
     438        if (it != this->xmlportParamContainers_.end())
     439        {
     440            COUT(2) << "Warning: Overwriting XMLPortParamContainer in class " << this->getName() << "." << std::endl;
     441            delete (it->second);
     442        }
     443
    437444        this->xmlportParamContainers_[paramname] = container;
    438445    }
     
    445452    XMLPortObjectContainer* Identifier::getXMLPortObjectContainer(const std::string& sectionname)
    446453    {
    447         std::map<std::string, XMLPortObjectContainer*>::const_iterator it = xmlportObjectContainers_.find(sectionname);
    448         if (it != xmlportObjectContainers_.end())
     454        std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname);
     455        if (it != this->xmlportObjectContainers_.end())
    449456            return ((*it).second);
    450457        else
     
    459466    void Identifier::addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container)
    460467    {
     468        std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportObjectContainers_.find(sectionname);
     469        if (it != this->xmlportObjectContainers_.end())
     470        {
     471            COUT(2) << "Warning: Overwriting XMLPortObjectContainer in class " << this->getName() << "." << std::endl;
     472            delete (it->second);
     473        }
     474
    461475        this->xmlportObjectContainers_[sectionname] = container;
     476    }
     477
     478    /**
     479        @brief Returns a XMLPortEventContainer that attaches an event to this class.
     480        @param sectionname The name of the section that contains the event
     481        @return The container
     482    */
     483    XMLPortObjectContainer* Identifier::getXMLPortEventContainer(const std::string& eventname)
     484    {
     485        std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportEventContainers_.find(eventname);
     486        if (it != this->xmlportEventContainers_.end())
     487            return ((*it).second);
     488        else
     489            return 0;
     490    }
     491
     492    /**
     493        @brief Adds a new XMLPortEventContainer that attaches an event to this class.
     494        @param sectionname The name of the section that contains the event
     495        @param container The container
     496    */
     497    void Identifier::addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container)
     498    {
     499        std::map<std::string, XMLPortObjectContainer*>::const_iterator it = this->xmlportEventContainers_.find(eventname);
     500        if (it != this->xmlportEventContainers_.end())
     501        {
     502            COUT(2) << "Warning: Overwriting XMLPortEventContainer in class " << this->getName() << "." << std::endl;
     503            delete (it->second);
     504        }
     505
     506        this->xmlportEventContainers_[eventname] = container;
    462507    }
    463508
  • code/branches/objecthierarchy/src/core/Identifier.h

    r2024 r2063  
    210210            inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortObjectMapEnd() const { return this->xmlportObjectContainers_.end(); }
    211211
     212            /** @brief Returns the map that stores all XMLPort events. @return The const_iterator */
     213            inline const std::map<std::string, XMLPortObjectContainer*>& getXMLPortEventMap() const { return this->xmlportEventContainers_; }
     214            /** @brief Returns a const_iterator to the beginning of the map that stores all XMLPort events. @return The const_iterator */
     215            inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapBegin() const { return this->xmlportEventContainers_.begin(); }
     216            /** @brief Returns a const_iterator to the end of the map that stores all XMLPort events. @return The const_iterator */
     217            inline std::map<std::string, XMLPortObjectContainer*>::const_iterator getXMLPortEventMapEnd() const { return this->xmlportEventContainers_.end(); }
     218
    212219            /** @brief Returns true if this class has at least one config value. @return True if this class has at least one config value */
    213220            inline bool hasConfigValues() const { return this->bHasConfigValues_; }
     
    233240            void addXMLPortObjectContainer(const std::string& sectionname, XMLPortObjectContainer* container);
    234241            XMLPortObjectContainer* getXMLPortObjectContainer(const std::string& sectionname);
     242
     243            void addXMLPortEventContainer(const std::string& eventname, XMLPortObjectContainer* container);
     244            XMLPortObjectContainer* getXMLPortEventContainer(const std::string& eventname);
    235245
    236246            ConsoleCommand& addConsoleCommand(ConsoleCommand* command, bool bCreateShortcut);
     
    307317            std::map<std::string, XMLPortParamContainer*> xmlportParamContainers_;     //!< All loadable parameters
    308318            std::map<std::string, XMLPortObjectContainer*> xmlportObjectContainers_;   //!< All attachable objects
     319            std::map<std::string, XMLPortObjectContainer*> xmlportEventContainers_;    //!< All events
    309320    };
    310321
  • code/branches/objecthierarchy/src/core/Super.h

    r1841 r2063  
    7373#include "util/Debug.h"
    7474#include "XMLIncludes.h"
     75#include "Event.h"
    7576
    7677///////////////////////
     
    229230    #define SUPER_changedVisibility(classname, functionname, ...) \
    230231        SUPER_NOARGS(classname, functionname)
     232
     233    #define SUPER_processEvent(classname, functionname, ...) \
     234        SUPER_ARGS(classname, functionname, __VA_ARGS__)
    231235    // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    232236
     
    433437            ()
    434438        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     439
     440        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(4, processEvent, true, Event& event)
     441            (event)
     442        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
    435443        // (2/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    436444
     
    479487    SUPER_INTRUSIVE_DECLARATION(changedActivity);
    480488    SUPER_INTRUSIVE_DECLARATION(changedVisibility);
     489    SUPER_INTRUSIVE_DECLARATION(processEvent);
    481490    // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    482491
  • code/branches/objecthierarchy/src/network/GamestateClient.cc

    r1990 r2063  
    139139    }
    140140    else{
    141       COUT(3) << "acked a gamestate: " << gamestateID << std::endl;
     141      COUT(5) << "acked a gamestate: " << gamestateID << std::endl;
    142142      return true;
    143143    }
     
    160160      delete gs;
    161161      gs=undiffed;
    162       COUT(3) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl;
     162      COUT(5) << "successfully undiffed gamestate id: " << undiffed->getID() << std::endl;
    163163    }
    164164    if(gs->spreadData())
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/BlinkingBillboard.cc

    r2044 r2063  
    4343        this->amplitude_ = 1.0f;
    4444        this->frequency_ = 1.0f;
    45         this->phase_ = 0.0f;
     45        this->phase_ = 0;
    4646        this->time_ = 0;
    4747
     
    5959        XMLPortParam(BlinkingBillboard, "amplitude", setAmplitude, getAmplitude, xmlelement, mode).defaultValues(1.0f);
    6060        XMLPortParam(BlinkingBillboard, "frequency", setFrequency, getFrequency, xmlelement, mode).defaultValues(1.0f);
    61         XMLPortParam(BlinkingBillboard, "phase",     setPhase,     getPhase,     xmlelement, mode).defaultValues(0.0f);
     61        XMLPortParam(BlinkingBillboard, "phase",     setPhase,     getPhase,     xmlelement, mode).defaultValues(Degree(0));
    6262    }
    6363
     
    7272    {
    7373        this->time_ += dt;
    74         this->setScale(this->amplitude_ * sin((6.2831853 + this->phase_) * this->frequency_ * this->time_));
     74        this->setScale(this->amplitude_ * sin((6.2831853 * this->time_ + this->phase_.valueRadians()) * this->frequency_));
    7575    }
    7676}
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/BlinkingBillboard.h

    r2044 r2063  
    5757                { return this->frequency_; }
    5858
    59             inline void setPhase(float phase)
     59            inline void setPhase(const Degree& phase)
    6060                { this->phase_ = phase; }
    61             inline float getPhase() const
     61            inline const Degree& getPhase() const
    6262                { return this->phase_; }
    6363
     
    6565            float amplitude_;
    6666            float frequency_;
    67             float phase_;
     67            Degree phase_;
    6868            long double time_;
    6969    };
Note: See TracChangeset for help on using the changeset viewer.