Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8198 for code


Ignore:
Timestamp:
Apr 6, 2011, 11:06:45 PM (14 years ago)
Author:
anbueche
Message:

First steps to use of Triggers and Events

Location:
code/branches/portals/src/orxonox/worldentities
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/portals/src/orxonox/worldentities/PortalEndPoint.cc

    r8177 r8198  
    1111    {
    1212        RegisterObject(PortalEndPoint);
    13         trigger_.setDistance(10);
    14         trigger_.setStayActive(true);
    1513    }
    1614   
     
    2927        if(mode == XMLPort::LoadObject)
    3028        {
    31             idMap_s[this->id_] = this;
     29            PortalEndPoint::idMap_s[this->id_] = this;
    3230        }
    3331    }
     32
     33    void PortalEndPoint::tick(float dt)
     34    {
     35        SUPER(PortalEndPoint, tick);
     36    }
     37
     38    void PortalEndPoint::jumpOut(WorldEntity* entity)
     39    {
     40        this->recentlyJumpedOut_.insert(entity);
     41        entity->setPosition(this->getPosition());
     42    }
     43
     44    bool PortalEndPoint::hasRecentlyJumpedOut(WorldEntity* entity)
     45    {
     46        if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end())
     47        {
     48            return false;
     49        }
     50        else
     51            return true;
     52    }
     53
    3454}
  • code/branches/portals/src/orxonox/worldentities/PortalEndPoint.h

    r8177 r8198  
    88#include "StaticEntity.h"
    99#include "graphics/Billboard.h"
    10 #include "objects/triggers/DistanceMultiTrigger.h"
    11 #include "tools/interfaces/Tickable.h"
     10#include "../../modules/objects/triggers/DistanceMultiTrigger.h"
    1211
    1312namespace orxonox
    1413{
    15     class _OrxonoxExport PortalEndPoint : public StaticEntity
     14    class _OrxonoxExport PortalEndPoint : public DistanceMultiTrigger
    1615    {
    1716        public:
     
    2019            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    2120            //virtual void tick(float dt);
    22             static std::map<unsigned int, PortalEndPoint *> idMap_s;
     21            static std::map<unsigned int, PortalEndPoint *> idMap_s; //!< maps integer id values to portalendpoints
    2322            inline void setID(unsigned int id)
    2423            {
     
    3029                return this->id_;
    3130            }
     31            void jumpOut(WorldEntity * entity); //!< relocate an entity to the position of the endpoint and add it to the set of recentlyPortedOut entities
     32            void tick(float dt);
     33            bool hasRecentlyJumpedOut(WorldEntity * entity); //!< check if a certain entity recently jumped out of this endpoint
    3234        protected:
    3335        private:
    3436            unsigned int id_;
    35             std::set<WorldEntity *> recentlyJumpedOut_;
    36             std::string material_;
     37            std::set<WorldEntity *> recentlyJumpedOut_; //!< Entities which recently jumped out of this EndPoint, hence they shouldn't be pulled in again if the endpoint is the beginning of a link
    3738            Billboard billboard_;
    38             DistanceMultiTrigger trigger_;
    3939    };
    4040
  • code/branches/portals/src/orxonox/worldentities/PortalLink.cc

    r8177 r8198  
    11#include "PortalLink.h"
    22#include "core/XMLPort.h"
     3#include "objects/triggers/MultiTriggerContainer.h"
    34
    45namespace orxonox
     
    2930    }
    3031   
    31     void PortalLink::use(WorldEntity * entity)
    32     {
    33        
    34     }
    3532    void PortalLink::tick(float dt)
    3633    {
    37        
     34        SUPER(PortalLink, tick)
    3835    }
     36   
     37    void PortalLink::processEvent(Event& event)
     38    {
     39        SUPER(PortalLink, processEvent);
     40        if(!event.activate_)
     41        {
     42            return;
     43        }
     44        MultiTriggerContainer * origin = dynamic_cast<MultiTriggerContainer *>(event.originator_);
     45        if(!origin)
     46        {
     47            return;
     48        }
     49        PortalEndPoint * eventFrom = dynamic_cast<PortalEndPoint *>(origin->getOriginator());
     50        WorldEntity * eventEntity = dynamic_cast<WorldEntity *>(origin->getData());
     51        if(eventFrom != this->from_ || !eventEntity || eventFrom->hasRecentlyJumpedOut(eventEntity) == true)
     52        {
     53            return;
     54        }
     55        to_->jumpOut(entity);
     56    }
     57
    3958}
  • code/branches/portals/src/orxonox/worldentities/PortalLink.h

    r8177 r8198  
    66#include "core/BaseObject.h"
    77#include "PortalEndPoint.h"
     8#include "objects/eventsystem/EventListener.h"
    89
    910#include <set>
     
    1112namespace orxonox
    1213{
    13     class _OrxonoxExport PortalLink : public BaseObject
     14    class _OrxonoxExport PortalLink : public EventListener
    1415    {
    1516        public:
     
    3637            }
    3738            void use(WorldEntity * entity);
     39            virtual void processEvent(Event& event);
    3840        protected:
    3941        private:
     
    4446            float activationRadius_;
    4547            std::set<WorldEntity *> recentlyPorted;
     48            ObjectList<WorldEntity>::iterator it_;
    4649            bool isNowPortable(WorldEntity * ent);
    4750    };
Note: See TracChangeset for help on using the changeset viewer.