Changeset 2069
- Timestamp:
- Oct 30, 2008, 11:58:31 PM (16 years ago)
- Location:
- code/branches/objecthierarchy/src
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/objecthierarchy/src/core/BaseObject.cc
r2065 r2069 217 217 EventContainer* BaseObject::getEventContainer(const std::string& sectionname) const 218 218 { 219 std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_. begin();219 std::map<std::string, EventContainer*>::const_iterator it = this->eventContainers_.find(sectionname); 220 220 if (it != this->eventContainers_.end()) 221 221 return ((*it).second); -
code/branches/objecthierarchy/src/core/Event.cc
r2065 r2069 38 38 } 39 39 40 void EventContainer::process( BaseObject* object, const Event& event)40 void EventContainer::process(void* object, const Event& event) 41 41 { 42 42 if (this->eventname_ == event.sectionname_) … … 47 47 ++this->activeEvents_; 48 48 else 49 { 49 50 --this->activeEvents_; 50 51 52 if (this->activeEvents_ < 0) 53 this->activeEvents_ = 0; 54 } 55 51 56 if (this->eventfunction_->getParamCount() == 0 && event.activate_) 52 (*this->eventfunction_)( object);57 (*this->eventfunction_)(); 53 58 else if ((this->activeEvents_ == 1 && event.activate_) || (this->activeEvents_ == 0 && !event.activate_)) 54 59 { 55 60 if (this->eventfunction_->getParamCount() == 1) 56 (*this->eventfunction_)( object,this->activeEvents_);61 (*this->eventfunction_)(this->activeEvents_); 57 62 else if (this->eventfunction_->getParamCount() >= 2 && event.castedOriginator_) 58 (*this->eventfunction_)( object,this->activeEvents_, event.castedOriginator_);63 (*this->eventfunction_)(this->activeEvents_, event.castedOriginator_); 59 64 } 60 65 } -
code/branches/objecthierarchy/src/core/Event.h
r2065 r2069 48 48 public: 49 49 EventContainer(const std::string& eventname, Executor* eventfunction, Identifier* subclass) : eventname_(eventname), eventfunction_(eventfunction), subclass_(subclass), activeEvents_(0) {} 50 ~EventContainer();50 virtual ~EventContainer(); 51 51 52 v oid process(BaseObject* object, const Event& event);52 virtual void process(void* object, const Event& event); 53 53 54 54 private: … … 59 59 int activeEvents_; 60 60 }; 61 62 template <class T> 63 class ClassEventContainer : public EventContainer 64 { 65 public: 66 ClassEventContainer(const std::string& eventname, ExecutorMember<T>* eventfunction, Identifier* subclass) : EventContainer(eventname, (Executor*)eventfunction, subclass), eventfunction_(eventfunction) {} 67 68 void process(void* object, const Event& event) 69 { 70 this->eventfunction_->setObject((T*)object); 71 EventContainer::process(object, event); 72 } 73 74 private: 75 ExecutorMember<T>* eventfunction_; 76 }; 61 77 } 62 78 -
code/branches/objecthierarchy/src/core/EventIncludes.h
r2066 r2069 49 49 if (!containername) \ 50 50 { \ 51 containername = new orxonox:: EventContainer(std::string(eventname), executor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \51 containername = new orxonox::ClassEventContainer<classname>(std::string(eventname), executor, orxonox::ClassIdentifier<subclassname>::getIdentifier()); \ 52 52 this->addEventContainer(eventname, containername); \ 53 53 } \ -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/BlinkingBillboard.cc
r2065 r2069 75 75 void BlinkingBillboard::tick(float dt) 76 76 { 77 if (Core::isMaster() )77 if (Core::isMaster() && this->isActive()) 78 78 { 79 79 this->time_ += dt; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc
r2029 r2069 54 54 55 55 XMLPortParam(DistanceTrigger, "distance", setDistance, getDistance, xmlelement, mode).defaultValues(100.0f); 56 XMLPortParamLoadOnly(DistanceTrigger, "target", addTargets, xmlelement, mode) ;56 XMLPortParamLoadOnly(DistanceTrigger, "target", addTargets, xmlelement, mode).defaultValues("ControllableEntity"); 57 57 } 58 58 … … 81 81 { 82 82 Identifier* targetId = ClassByString(targets); 83 targetMask_.include(targetId); 83 if (!targetId) 84 return; 85 86 this->targetMask_.include(targetId); 87 84 88 // trigger shouldn't react on itself or other triggers 85 t argetMask_.exclude(Class(Trigger), true);89 this->targetMask_.exclude(Class(Trigger), true); 86 90 91 // we only want WorldEntities 92 ClassTreeMask WEMask; 93 WEMask.include(Class(WorldEntity)); 94 this->targetMask_ *= WEMask; 87 95 } 88 96 … … 90 98 { 91 99 Identifier* targetId = ClassByString(targets); 92 t argetMask_.exclude(targetId);100 this->targetMask_.exclude(targetId); 93 101 } 94 102 95 103 bool DistanceTrigger::checkDistance() 96 104 { 97 // Iterate through all WorldEntities98 for ( Iterator<WorldEntity> it = ObjectList<WorldEntity>::begin(); it; ++it)105 // Iterate through all objects 106 for (ClassTreeMaskObjectIterator it = this->targetMask_.begin(); it != this->targetMask_.end(); ++it) 99 107 { 100 // check if WorldEntity is a target101 if ( targetMask_.isIncluded(it->getIdentifier()))102 {103 Vector3 distanceVec = it->getNode()->getWorldPosition() - this->getNode()->getWorldPosition(); 104 if (distanceVec.length() < this->distance_)105 return true;106 }108 WorldEntity* entity = dynamic_cast<WorldEntity*>(*it); 109 if (!entity) 110 continue; 111 112 Vector3 distanceVec = entity->getWorldPosition() - this->getWorldPosition(); 113 if (distanceVec.length() < this->distance_) 114 return true; 107 115 } 108 116 return false; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.cc
r2065 r2069 50 50 this->mode_ = TM_EventTriggerAND; 51 51 52 this->bFirstTick_ = true; 52 53 this->bActive_ = false; 53 54 this->bTriggered_ = false; … … 92 93 void Trigger::tick(float dt) 93 94 { 94 95 bool newTriggered = this->isTriggered(); 95 if (this->bFirstTick_) 96 { 97 this->bFirstTick_ = false; 98 this->fireEvent(false); 99 } 100 101 bool newTriggered = this->isTriggered() ^ this->bInvertMode_; 96 102 97 103 // check if new triggering event is really new … … 173 179 // this->bUpdating_ = false; 174 180 175 if (this->bInvertMode_) 176 return !returnval; 177 else 178 return returnval; 181 return returnval; 179 182 } 180 183 return true; -
code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.h
r2029 r2069 35 35 #include "OrxonoxPrereqs.h" 36 36 37 #include "objects/Tickable.h" 37 38 #include "objects/worldentities/PositionableEntity.h" 38 39 #include "tools/BillboardSet.h" … … 47 48 }; 48 49 49 class _OrxonoxExport Trigger : public PositionableEntity 50 class _OrxonoxExport Trigger : public PositionableEntity, public Tickable 50 51 { 51 52 public: … … 111 112 bool bActive_; 112 113 bool bTriggered_; 114 bool bFirstTick_; 113 115 114 116 TriggerMode mode_;
Note: See TracChangeset
for help on using the changeset viewer.