Changeset 5935 for code/branches/pickup/src/modules/objects
- Timestamp:
- Oct 13, 2009, 5:05:17 PM (15 years ago)
- Location:
- code/branches/pickup
- Files:
-
- 15 edited
- 4 copied
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pickup
- Property svn:mergeinfo changed
-
code/branches/pickup/src/modules/objects/Attacher.cc
r5781 r5935 53 53 void Attacher::processEvent(Event& event) 54 54 { 55 for (std::list<WorldEntity*>::iterator it = this->objects_.begin(); it != this->objects_.end(); ++it)56 (*it)->fireEvent(event);55 if (this->target_) 56 this->target_->processEvent(event); 57 57 } 58 58 … … 102 102 103 103 for (ObjectList<WorldEntity>::iterator it = ObjectList<WorldEntity>::begin(); it != ObjectList<WorldEntity>::end(); ++it) 104 { 104 105 if (it->getName() == this->targetname_) 106 { 107 this->target_ = *it; 105 108 this->attachToParent(*it); 109 } 110 } 106 111 } 107 112 -
code/branches/pickup/src/modules/objects/ObjectsPrereqs.h
r5781 r5935 28 28 29 29 /** 30 @file 31 @brief Contains all the necessary forward declarations for all classes and structs. 30 @file 31 @brief 32 Shared library macros, enums, constants and forward declarations for the objects module 32 33 */ 33 34 … … 36 37 37 38 #include "OrxonoxConfig.h" 38 39 39 #include "OrxonoxPrereqs.h" 40 40 … … 42 42 // Shared library settings 43 43 //----------------------------------------------------------------------- 44 44 45 #if defined(ORXONOX_PLATFORM_WINDOWS) && !defined(ORXONOX_STATIC_BUILD) 45 46 # ifdef OBJECTS_SHARED_BUILD … … 76 77 77 78 // eventsystem 79 class EventDispatcher; 80 class EventFilter; 78 81 class EventListener; 79 class Event Dispatcher;82 class EventName; 80 83 class EventTarget; 81 84 82 85 // triggers 83 class Trigger;86 class CheckPoint; 84 87 class DistanceTrigger; 85 88 class EventTrigger; 86 class CheckPoint;89 class Trigger; 87 90 } 88 91 -
code/branches/pickup/src/modules/objects/Planet.cc
r5781 r5935 47 47 * @brief Constructor 48 48 */ 49 Planet::Planet(BaseObject* creator) : MovableEntity(creator)49 Planet::Planet(BaseObject* creator) : MovableEntity(creator) 50 50 { 51 51 RegisterObject(Planet); … … 64 64 void Planet::tick(float dt) 65 65 { 66 if (!this->isVisible())66 if (!this->isVisible()) 67 67 return; 68 68 … … 70 70 { 71 71 Camera* activeCamera = CameraManager::getInstance().getActiveCamera(); 72 if (activeCamera)72 if (activeCamera) 73 73 { 74 74 float distance = this->getPosition().distance( activeCamera->getWorldPosition() ); -
code/branches/pickup/src/modules/objects/eventsystem/CMakeLists.txt
r5781 r5935 1 1 ADD_SOURCE_FILES(OBJECTS_SRC_FILES 2 2 EventDispatcher.cc 3 EventFilter.cc 3 4 EventListener.cc 5 EventName.cc 4 6 EventTarget.cc 5 7 ) -
code/branches/pickup/src/modules/objects/eventsystem/EventDispatcher.cc
r5781 r5935 32 32 #include "core/EventIncludes.h" 33 33 #include "core/XMLPort.h" 34 #include "EventTarget.h"35 34 36 35 namespace orxonox … … 46 45 { 47 46 if (this->isInitialized()) 48 for (std::list< EventTarget*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it)49 delete (*it);47 for (std::list<BaseObject*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it) 48 (*it)->destroy(); 50 49 } 51 50 … … 54 53 SUPER(EventDispatcher, XMLPort, xmlelement, mode); 55 54 56 XMLPortObject(EventDispatcher, EventTarget, "targets", addTarget, getTarget, xmlelement, mode); 55 XMLPortObject(EventDispatcher, BaseObject, "targets", addTarget, getTarget, xmlelement, mode); 56 57 // since we need event sources mapped to any state, we have to parse XML by ourselves 58 this->loadAllEventStates(xmlelement, mode, this, Class(EventDispatcher)); 57 59 } 58 60 59 61 void EventDispatcher::processEvent(Event& event) 60 62 { 61 for (std::list< EventTarget*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it)62 (*it)-> fireEvent(event);63 for (std::list<BaseObject*>::iterator it = this->targets_.begin(); it != this->targets_.end(); ++it) 64 (*it)->processEvent(event); 63 65 } 64 66 65 void EventDispatcher::addTarget( EventTarget* target)67 void EventDispatcher::addTarget(BaseObject* target) 66 68 { 67 69 this->targets_.push_back(target); 68 70 } 69 71 70 EventTarget* EventDispatcher::getTarget(unsigned int index) const72 BaseObject* EventDispatcher::getTarget(unsigned int index) const 71 73 { 72 74 unsigned int i = 0; 73 for (std::list< EventTarget*>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); ++it)75 for (std::list<BaseObject*>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); ++it) 74 76 { 75 77 if (i == index) -
code/branches/pickup/src/modules/objects/eventsystem/EventDispatcher.h
r5781 r5935 47 47 virtual void processEvent(Event& event); 48 48 49 void addTarget( EventTarget* target);50 EventTarget* getTarget(unsigned int index) const;49 void addTarget(BaseObject* target); 50 BaseObject* getTarget(unsigned int index) const; 51 51 52 52 private: 53 std::list< EventTarget*> targets_;53 std::list<BaseObject*> targets_; 54 54 }; 55 55 } -
code/branches/pickup/src/modules/objects/eventsystem/EventListener.cc
r5781 r5935 63 63 64 64 this->bActive_ = true; 65 66 this->fireEvent(event.activate_, event.originator_); 67 65 this->fireEvent(event.activate_, event.originator_, event.name_); 68 66 this->bActive_ = false; 69 67 } … … 78 76 for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it) 79 77 if (it->getName() == this->eventName_) 80 this-> registerAsListener(*it);78 this->addEventSource(*it, ""); 81 79 } 82 80 … … 87 85 88 86 if (object->getName() == this->eventName_) 89 this->registerAsListener(object); 90 } 91 92 void EventListener::registerAsListener(BaseObject* object) 93 { 94 object->registerEventListener(this, ""); 87 this->addEventSource(object, ""); 95 88 } 96 89 } -
code/branches/pickup/src/modules/objects/eventsystem/EventListener.h
r5781 r5935 54 54 private: 55 55 virtual void loadedNewXMLName(BaseObject* object); 56 void registerAsListener(BaseObject* object);57 56 58 57 std::string eventName_; -
code/branches/pickup/src/modules/objects/eventsystem/EventTarget.cc
r5781 r5935 29 29 #include "EventTarget.h" 30 30 #include "core/CoreIncludes.h" 31 #include "core/XMLPort.h" 31 32 32 33 namespace orxonox … … 37 38 { 38 39 RegisterObject(EventTarget); 40 41 this->bActive_ = false; 39 42 } 40 43 … … 42 45 { 43 46 } 47 48 void EventTarget::XMLPort(Element& xmlelement, XMLPort::Mode mode) 49 { 50 SUPER(EventTarget, XMLPort, xmlelement, mode); 44 51 45 void EventTarget::changedName() 52 XMLPortParam(EventTarget, "target", setTargetName, getTargetName, xmlelement, mode); 53 54 // since we need event sources mapped to any state, we have to parse XML by ourselves 55 this->loadAllEventStates(xmlelement, mode, this, Class(EventTarget)); 56 } 57 58 void EventTarget::processEvent(Event& event) 46 59 { 47 SUPER(EventTarget, changedName); 60 if (this->bActive_) 61 { 62 COUT(2) << "Warning: Detected Event loop in EventTarget \"" << this->getName() << "\"" << std::endl; 63 return; 64 } 48 65 66 this->bActive_ = true; 67 this->fireEvent(event); 68 this->bActive_ = false; 69 } 70 71 void EventTarget::setTargetName(const std::string& name) 72 { 73 this->target_ = name; 74 49 75 for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it) 50 if (it->getName() == this-> getName())51 this->add AsEvent(*it);76 if (it->getName() == this->target_) 77 this->addEventTarget(*it); 52 78 } 53 79 54 80 void EventTarget::loadedNewXMLName(BaseObject* object) 55 81 { 56 if (this-> getName()== "")82 if (this->target_ == "") 57 83 return; 58 84 59 if (object->getName() == this-> getName())60 this->add AsEvent(object);85 if (object->getName() == this->target_) 86 this->addEventTarget(object); 61 87 } 62 88 63 void EventTarget::add AsEvent(BaseObject* object)89 void EventTarget::addEventTarget(BaseObject* object) 64 90 { 65 91 if (object != static_cast<BaseObject*>(this)) 66 object->addEvent (this, "");92 object->addEventSource(this, ""); 67 93 } 68 94 } -
code/branches/pickup/src/modules/objects/eventsystem/EventTarget.h
r5781 r5935 42 42 EventTarget(BaseObject* creator); 43 43 virtual ~EventTarget(); 44 45 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 46 47 virtual void processEvent(Event& event); 44 48 45 virtual void changedName(); 49 void setTargetName(const std::string& name); 50 inline const std::string& getTargetName() const 51 { return this->target_; } 46 52 47 53 private: 48 54 virtual void loadedNewXMLName(BaseObject* object); 49 void addAsEvent(BaseObject* object); 55 void addEventTarget(BaseObject* object); 56 57 std::string target_; 58 bool bActive_; 50 59 }; 51 60 } -
code/branches/pickup/src/modules/objects/triggers/CheckPoint.cc
r5781 r5935 85 85 DistanceTrigger::triggered(bIsTriggered); 86 86 87 Asteroids* gametype = orxonox_cast<Asteroids*>(this->getGametype() );87 Asteroids* gametype = orxonox_cast<Asteroids*>(this->getGametype().get()); 88 88 if (gametype) 89 89 { -
code/branches/pickup/src/modules/objects/triggers/EventTrigger.cc
r5781 r5935 47 47 } 48 48 49 void EventTrigger:: processEvent(Event& event)49 void EventTrigger::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 50 50 { 51 SUPER(EventTrigger, processEvent, event);51 SUPER(EventTrigger, XMLEventPort, xmlelement, mode); 52 52 53 ORXONOX_SET_EVENT(EventTrigger, "trigger", trigger, event);53 XMLPortEventState(EventTrigger, BaseObject, "trigger", trigger, xmlelement, mode); 54 54 } 55 55 -
code/branches/pickup/src/modules/objects/triggers/EventTrigger.h
r5781 r5935 41 41 virtual ~EventTrigger(); 42 42 43 virtual void processEvent(Event& event);43 virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 44 44 45 45 inline void trigger(bool bTriggered) -
code/branches/pickup/src/modules/objects/triggers/Trigger.cc
r5781 r5935 72 72 } 73 73 74 this->set ObjectMode(0x0);74 this->setSyncMode(0x0); 75 75 } 76 76
Note: See TracChangeset
for help on using the changeset viewer.