Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 30, 2008, 11:58:31 PM (16 years ago)
Author:
landauf
Message:

fixed a bug in the event system
fixed a bug in Trigger and tweaked some features

Location:
code/branches/objecthierarchy/src
Files:
8 edited

Legend:

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

    r2065 r2069  
    217217    EventContainer* BaseObject::getEventContainer(const std::string& sectionname) const
    218218    {
    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);
    220220        if (it != this->eventContainers_.end())
    221221            return ((*it).second);
  • code/branches/objecthierarchy/src/core/Event.cc

    r2065 r2069  
    3838    }
    3939
    40     void EventContainer::process(BaseObject* object, const Event& event)
     40    void EventContainer::process(void* object, const Event& event)
    4141    {
    4242        if (this->eventname_ == event.sectionname_)
     
    4747                    ++this->activeEvents_;
    4848                else
     49                {
    4950                    --this->activeEvents_;
    5051
     52                    if (this->activeEvents_ < 0)
     53                        this->activeEvents_ = 0;
     54                }
     55
    5156                if (this->eventfunction_->getParamCount() == 0 && event.activate_)
    52                     (*this->eventfunction_)(object);
     57                    (*this->eventfunction_)();
    5358                else if ((this->activeEvents_ == 1 && event.activate_) || (this->activeEvents_ == 0 && !event.activate_))
    5459                {
    5560                    if (this->eventfunction_->getParamCount() == 1)
    56                         (*this->eventfunction_)(object, this->activeEvents_);
     61                        (*this->eventfunction_)(this->activeEvents_);
    5762                    else if (this->eventfunction_->getParamCount() >= 2 && event.castedOriginator_)
    58                         (*this->eventfunction_)(object, this->activeEvents_, event.castedOriginator_);
     63                        (*this->eventfunction_)(this->activeEvents_, event.castedOriginator_);
    5964                }
    6065            }
  • code/branches/objecthierarchy/src/core/Event.h

    r2065 r2069  
    4848        public:
    4949            EventContainer(const std::string& eventname, Executor* eventfunction, Identifier* subclass) : eventname_(eventname), eventfunction_(eventfunction), subclass_(subclass), activeEvents_(0) {}
    50             ~EventContainer();
     50            virtual ~EventContainer();
    5151
    52             void process(BaseObject* object, const Event& event);
     52            virtual void process(void* object, const Event& event);
    5353
    5454        private:
     
    5959            int activeEvents_;
    6060    };
     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    };
    6177}
    6278
  • code/branches/objecthierarchy/src/core/EventIncludes.h

    r2066 r2069  
    4949    if (!containername) \
    5050    { \
    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()); \
    5252        this->addEventContainer(eventname, containername); \
    5353    } \
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/BlinkingBillboard.cc

    r2065 r2069  
    7575    void BlinkingBillboard::tick(float dt)
    7676    {
    77         if (Core::isMaster())
     77        if (Core::isMaster() && this->isActive())
    7878        {
    7979            this->time_ += dt;
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/DistanceTrigger.cc

    r2029 r2069  
    5454
    5555    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");
    5757  }
    5858
     
    8181  {
    8282    Identifier* targetId = ClassByString(targets);
    83     targetMask_.include(targetId);
     83    if (!targetId)
     84        return;
     85
     86    this->targetMask_.include(targetId);
     87
    8488    // trigger shouldn't react on itself or other triggers
    85     targetMask_.exclude(Class(Trigger), true);
     89    this->targetMask_.exclude(Class(Trigger), true);
    8690
     91    // we only want WorldEntities
     92    ClassTreeMask WEMask;
     93    WEMask.include(Class(WorldEntity));
     94    this->targetMask_ *= WEMask;
    8795  }
    8896
     
    9098  {
    9199    Identifier* targetId = ClassByString(targets);
    92     targetMask_.exclude(targetId);
     100    this->targetMask_.exclude(targetId);
    93101  }
    94102
    95103  bool DistanceTrigger::checkDistance()
    96104  {
    97     // Iterate through all WorldEntities
    98     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)
    99107    {
    100       // check if WorldEntity is a target
    101       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;
    107115    }
    108116    return false;
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.cc

    r2065 r2069  
    5050    this->mode_ = TM_EventTriggerAND;
    5151
     52    this->bFirstTick_ = true;
    5253    this->bActive_ = false;
    5354    this->bTriggered_ = false;
     
    9293  void Trigger::tick(float dt)
    9394  {
    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_;
    96102
    97103    // check if new triggering event is really new
     
    173179//      this->bUpdating_ = false;
    174180
    175       if (this->bInvertMode_)
    176         return !returnval;
    177       else
    178         return returnval;
     181      return returnval;
    179182    }
    180183    return true;
  • code/branches/objecthierarchy/src/orxonox/objects/worldentities/triggers/Trigger.h

    r2029 r2069  
    3535#include "OrxonoxPrereqs.h"
    3636
     37#include "objects/Tickable.h"
    3738#include "objects/worldentities/PositionableEntity.h"
    3839#include "tools/BillboardSet.h"
     
    4748  };
    4849
    49   class _OrxonoxExport Trigger : public PositionableEntity
     50  class _OrxonoxExport Trigger : public PositionableEntity, public Tickable
    5051  {
    5152    public:
     
    111112      bool bActive_;
    112113      bool bTriggered_;
     114      bool bFirstTick_;
    113115
    114116      TriggerMode mode_;
Note: See TracChangeset for help on using the changeset viewer.