Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 30, 2008, 2:44:48 AM (16 years ago)
Author:
landauf
Message:

added two more graphical classes, ParticleEmitter and ParticleSpawner

Location:
code/branches/objecthierarchy/src/core
Files:
5 edited

Legend:

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

    r2063 r2065  
    3535#include "tinyxml/tinyxml.h"
    3636#include "CoreIncludes.h"
     37#include "EventIncludes.h"
    3738#include "XMLPort.h"
    3839#include "XMLFile.h"
     
    7980    BaseObject::~BaseObject()
    8081    {
     82        for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
     83            (*it)->eventListeners_.erase(this);
    8184    }
    8285
     
    184187    void BaseObject::addEvent(BaseObject* event, const std::string& sectionname)
    185188    {
    186         this->eventListeners_.insert(std::pair<std::string, BaseObject*>(sectionname, event));
     189        event->eventListeners_[this] = sectionname;
     190        this->events_.push_back(event);
    187191    }
    188192
     
    190194    {
    191195        unsigned int i = 0;
    192         for (std::set<std::pair<std::string, BaseObject*> >::const_iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
     196        for (std::list<BaseObject*>::const_iterator it = this->events_.begin(); it != this->events_.end(); ++it)
    193197        {
    194198            if (i == index)
    195                 return (*it).second;
     199                return (*it);
    196200            ++i;
    197201        }
     
    230234        Event event(activate, this);
    231235
    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        for (std::map<BaseObject*, std::string>::iterator it = this->eventListeners_.begin(); it != this->eventListeners_.end(); ++it)
     237        {
     238            event.sectionname_ = it->second;
     239            it->first->processEvent(event);
    236240        }
    237241    }
  • code/branches/objecthierarchy/src/core/BaseObject.h

    r2063 r2065  
    3636#ifndef _BaseObject_H__
    3737#define _BaseObject_H__
     38
     39#include <map>
    3840
    3941#include "CorePrereqs.h"
     
    145147            Gametype*             oldGametype_;
    146148            std::set<Template*>   templates_;
    147             std::set<std::pair<std::string, BaseObject*> > eventListeners_;
     149            std::map<BaseObject*, std::string> eventListeners_;
     150            std::list<BaseObject*> events_;
    148151            std::map<std::string, EventContainer*> eventContainers_;
    149152    };
  • code/branches/objecthierarchy/src/core/Event.cc

    r2063 r2065  
    2929#include "Event.h"
    3030#include "BaseObject.h"
     31#include "Executor.h"
    3132
    3233namespace orxonox
    3334{
     35    EventContainer::~EventContainer()
     36    {
     37        delete this->eventfunction_;
     38    }
     39
    3440    void EventContainer::process(BaseObject* object, const Event& event)
    3541    {
  • code/branches/objecthierarchy/src/core/Event.h

    r2063 r2065  
    3131
    3232#include "CorePrereqs.h"
    33 #include "Executor.h"
    34 
    35 #define SetEvent(classname, eventname, functionname, event) \
    36     SetEventGeneric(eventcontainer##classname##functionname, classname, eventname, orxonox::createExecutor(orxonox::createFunctor(&classname::functionname), std::string( #classname ) + "::" + #functionname), event, BaseObject)
    37 
    38 #define SetEventTemplate(classname, eventname, functionname, event, ...) \
    39     SetEventGeneric(eventcontainer##classname##functionname, classname, eventname, orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::functionname), std::string( #classname ) + "::" + #functionname), event, BaseObject)
    40 
    41 #define SetSubclassEvent(classname, eventname, functionname, event, subclassname) \
    42     SetEventGeneric(eventcontainer##classname##functionname, classname, eventname, orxonox::createExecutor(orxonox::createFunctor(&classname::functionname), std::string( #classname ) + "::" + #functionname), event, subclassname)
    43 
    44 #define SetSubclassEventTemplate(classname, eventname, functionname, event, subclassname, ...) \
    45     SetEventGeneric(eventcontainer##classname##functionname, classname, eventname, orxonox::createExecutor(orxonox::createFunctor<classname, __VA_ARGS__ >(&classname::functionname), std::string( #classname ) + "::" + #functionname), event, subclassname)
    46 
    47 #define SetEventGeneric(containername, classname, eventname, executor, event, subclassname) \
    48     orxonox::EventContainer* containername = this->getEventContainer(eventname); \
    49     if (!containername) \
    50     { \
    51         containername = new orxonox::EventContainer(std::string(eventname), executor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \
    52         this->addEventContainer(eventname, containername); \
    53     } \
    54     event.castedOriginator_ = dynamic_cast<subclassname*>(event.originator_); \
    55     containername->process(this, event)
    56 
    5733
    5834namespace orxonox
     
    7248        public:
    7349            EventContainer(const std::string& eventname, Executor* eventfunction, Identifier* subclass) : eventname_(eventname), eventfunction_(eventfunction), subclass_(subclass), activeEvents_(0) {}
    74             ~EventContainer()
    75                 { delete this->eventfunction_; }
     50            ~EventContainer();
    7651
    7752            void process(BaseObject* object, const Event& event);
  • code/branches/objecthierarchy/src/core/XMLPort.h

    r2019 r2065  
    480480
    481481                                                BaseObject* newObject = identifier->fabricate((BaseObject*)object);
     482                                                assert(newObject);
    482483                                                newObject->setLoaderIndentation(((BaseObject*)object)->getLoaderIndentation() + "  ");
    483 //                                                newObject->setFile(((BaseObject*)object)->getFile());
    484 //                                                newObject->setNamespace(((BaseObject*)object)->getNamespace());
     484
     485                                                O* castedObject = dynamic_cast<O*>(newObject);
     486                                                assert(castedObject);
    485487
    486488                                                if (this->bLoadBefore_)
     
    495497
    496498                                                COUT(5) << ((BaseObject*)object)->getLoaderIndentation();
    497                                                 (*this->loadexecutor_)(object, newObject);
     499                                                (*this->loadexecutor_)(object, castedObject);
    498500
    499501                                                if (!this->bLoadBefore_)
Note: See TracChangeset for help on using the changeset viewer.