Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8243


Ignore:
Timestamp:
Apr 14, 2011, 4:33:33 PM (14 years ago)
Author:
anbueche
Message:

portals work pretty good

Location:
code/branches/portals
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/portals/data/levels/portals.oxw

    r8200 r8243  
    2626  >
    2727
     28    <Template name=portalEventTemplate>
     29        <PortalEndPoint>
     30            <events>
     31                <execute>
     32                    <EventListener event="portal" />
     33                </execute>
     34            </events>
     35        </PortalEndPoint>
     36    </Template>
    2837
    29         <PortalEndPoint position="0,0,0" id="1">
    30                 <attached>
    31                         <Billboard material="Examples/Flare" />
    32                 </attached>
    33         </PortalEndPoint>
    34         <PortalEndPoint position="-100,0,0" id="2">
    35                 <attached>
    36                         <Billboard material="Examples/Flare2" />
    37                 </attached>
    38         </PortalEndPoint>
    39         <PortalLink fromID="1" toID="2" />
     38    <Template name=portalDefault>
     39        <PortalEndPoint>
     40            <attached>
     41                <Billboard material="Portals/Default" />
     42            </attached>
     43        </PortalEndPoint>
     44    </Template>
     45
     46    <PortalEndPoint position="0,0,0" id="1" distance="40" target="MobileEntity" design="portalDefault" eventTemplate="portalEventTemplate" />
     47    <PortalEndPoint position="-400,0,0" id="2" distance="40" lookat="0,100,0" target="MobileEntity" design="portalDefault" eventTemplate="portalEventTemplate" />
     48    <PortalLink fromID="1" toID="2" />
     49    <PortalLink fromID="2" toID="1" />
    4050
    4151    <Light type=directional position="0,0,0" direction="0.253, 0.593, -0.765" diffuse="1.0, 0.9, 0.9, 1.0" specular="1.0, 0.9, 0.9, 1.0" />
  • code/branches/portals/src/modules/objects/triggers/MultiTrigger.h

    r7601 r8243  
    146146            inline bool isTarget(BaseObject* target)
    147147                { if(target == NULL) return true; else return targetMask_.isIncluded(target->getIdentifier()); }
     148               
     149            void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.
    148150
    149151        protected:
     
    158160            void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target.
    159161
    160             void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.
    161162            void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger.
    162163
  • code/branches/portals/src/modules/portals/PortalEndPoint.cc

    r8200 r8243  
    11#include "PortalEndPoint.h"
    22#include "core/XMLPort.h"
     3#include "objects/triggers/MultiTriggerContainer.h"
     4#include "portals/PortalLink.h"
     5#include "worldentities/MobileEntity.h"
     6
    37
    48namespace orxonox
     
    812    std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s;
    913
    10     PortalEndPoint::PortalEndPoint(BaseObject* creator) : DistanceMultiTrigger(creator), id_(0)
     14    PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(new DistanceMultiTrigger(this))
    1115    {
    1216        RegisterObject(PortalEndPoint);
     17        this->trigger_->setName("portal");
     18        this->attach(trigger_);
    1319    }
    1420   
    1521    PortalEndPoint::~PortalEndPoint()
    1622    {
    17      
     23   
    1824    }
    1925
     
    2127    {
    2228        SUPER(PortalEndPoint, XMLPort, xmlelement, mode);
     29       
    2330        XMLPortParam(PortalEndPoint, "id", setID, getID, xmlelement, mode);
     31        XMLPortParam(PortalEndPoint, "design", setTemplate, getTemplate, xmlelement, mode);
     32        XMLPortParamExtern(PortalEndPoint, DistanceMultiTrigger, this->trigger_, "distance", setDistance, getDistance, xmlelement, mode);
     33        XMLPortParamLoadOnly(PortalEndPoint, "eventTemplate", setEventTemplate, xmlelement, mode);
     34        XMLPortParamLoadOnly(PortalEndPoint, "target", setTargets, xmlelement, mode).defaultValues("Pawn");
    2435       
    2536        if(mode == XMLPort::LoadObject)
     
    2940    }
    3041
    31     void PortalEndPoint::tick(float dt)
     42    void PortalEndPoint::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
    3243    {
    33         SUPER(PortalEndPoint, tick, dt);
     44        SUPER(PortalEndPoint, XMLEventPort, xmlelement, mode);
     45       
     46        XMLPortEventSink(PortalEndPoint, BaseObject, "execute", execute, xmlelement, mode);
    3447    }
    3548
    36     void PortalEndPoint::jumpOut(WorldEntity* entity)
     49    bool PortalEndPoint::execute(bool bTriggered, BaseObject* trigger)
     50    {
     51        MultiTriggerContainer * cont = orxonox_cast<MultiTriggerContainer *>(trigger);
     52        if(cont == 0)
     53            return true;
     54       
     55        DistanceMultiTrigger * originatingTrigger = orxonox_cast<DistanceMultiTrigger *>(cont->getOriginator());
     56        if(originatingTrigger == 0)
     57        {
     58            COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;
     59            return true;
     60        }
     61       
     62        if(this->getAttachedObjects().find(orxonox_cast<WorldEntity *>(originatingTrigger)) == this->getAttachedObjects().end())  // only necessary if events have the same name
     63            return true;
     64       
     65        MobileEntity * entity = orxonox_cast<MobileEntity *>(cont->getData());
     66        if(entity == 0)
     67            return true;
     68       
     69        if(bTriggered)
     70        {
     71            if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end())  // only enter the portal if not recently jumped out of it
     72            {
     73                PortalLink::use(entity, this);
     74            }
     75        }
     76        else
     77        {
     78            this->recentlyJumpedOut_.erase(entity);
     79        }
     80       
     81        return true;
     82    }
     83
     84    void PortalEndPoint::jumpOut(MobileEntity* entity)
    3785    {
    3886        this->recentlyJumpedOut_.insert(entity);
    39         entity->setPosition(this->getPosition());
     87        entity->setPosition(this->getWorldPosition());
     88        entity->rotate(this->getWorldOrientation());
     89        entity->setVelocity(this->getWorldOrientation() * entity->getVelocity());
    4090    }
    4191
    42     bool PortalEndPoint::hasRecentlyJumpedOut(WorldEntity* entity)
    43     {
    44         if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end())
    45         {
    46             return false;
    47         }
    48         else
    49             return true;
    50     }
    5192
    5293}
  • code/branches/portals/src/modules/portals/PortalEndPoint.h

    r8200 r8243  
    1111#include "graphics/Billboard.h"
    1212#include "objects/triggers/DistanceMultiTrigger.h"
     13#include "core/EventIncludes.h"
    1314
    1415namespace orxonox
    1516{
    16     class _PortalsExport PortalEndPoint : public DistanceMultiTrigger
     17    class _PortalsExport PortalEndPoint : public StaticEntity
    1718    {
    1819        public:
     
    2021            virtual ~PortalEndPoint();
    2122            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    22             //virtual void tick(float dt);
     23            inline void setTargets(const std::string & targets)
     24            {
     25                this->trigger_->addTargets(targets);
     26            }
     27           
     28            void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
    2329            static std::map<unsigned int, PortalEndPoint *> idMap_s; //!< maps integer id values to portalendpoints
    2430            inline void setID(unsigned int id)
     
    3137                return this->id_;
    3238            }
    33             void jumpOut(WorldEntity * entity); //!< relocate an entity to the position of the endpoint and add it to the set of recentlyPortedOut entities
    34             void tick(float dt);
    35             bool hasRecentlyJumpedOut(WorldEntity * entity); //!< check if a certain entity recently jumped out of this endpoint
     39            inline void setTemplate(const std::string & name)
     40            {
     41                this->templateName_ = name;
     42                this->addTemplate(name);
     43            }
     44            inline const std::string & getTemplate()
     45            {
     46                return this->templateName_;
     47            }
     48            bool execute(bool bTriggered, BaseObject* trigger);
     49            void jumpOut(MobileEntity * entity);
    3650        protected:
    3751        private:
    3852            unsigned int id_;
    39             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
     53            DistanceMultiTrigger * trigger_;
     54            std::string templateName_;
     55            void setEventTemplate(const std::string & temp)
     56            {
     57                this->addTemplate(temp);
     58            }
     59            std::set<MobileEntity *> 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
    4060    };
    4161
  • code/branches/portals/src/modules/portals/PortalLink.cc

    r8200 r8243  
    22#include "core/XMLPort.h"
    33#include "objects/triggers/MultiTriggerContainer.h"
     4#include "worldentities/MobileEntity.h"
    45
    56namespace orxonox
    67{
    78    CreateFactory(PortalLink);
     9
     10    std::map<PortalEndPoint *, PortalEndPoint *> PortalLink::links_s;
    811   
    9     PortalLink::PortalLink(BaseObject* creator) : EventListener(creator), fromID_(0), toID_(0), from_(0), to_(0), activationRadius_(20)
     12    PortalLink::PortalLink(BaseObject* creator) : BaseObject(creator), fromID_(0), toID_(0), from_(0), to_(0)
    1013    {
    1114        RegisterObject(PortalLink);
     
    2427        if(mode == XMLPort::LoadObject)
    2528        {
    26             this->from_ = PortalEndPoint::idMap_s[this->fromID_];
    27             this->to_   = PortalEndPoint::idMap_s[this->toID_];
    28             recentlyPorted.clear();
     29            PortalEndPoint * from = PortalEndPoint::idMap_s[this->fromID_];
     30            PortalEndPoint * to   = PortalEndPoint::idMap_s[this->toID_];
     31            PortalLink::links_s[from] = to;
    2932        }
    3033    }
     
    3437        SUPER(PortalLink, tick, dt);
    3538    }
    36    
    37     void PortalLink::processEvent(Event& event)
     39
     40    void PortalLink::use(MobileEntity* entity, PortalEndPoint * entrance)
    3841    {
    39         EventListener::processEvent(event);
    40         if(!event.activate_)
     42        if(entrance == 0)
    4143        {
     44            // TODO COUT
    4245            return;
    4346        }
    44         MultiTriggerContainer * origin = dynamic_cast<MultiTriggerContainer *>(event.originator_);
    45         if(!origin)
    46         {
     47       
     48        std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoint = PortalLink::links_s.find(entrance);
     49       
     50        if(endpoint == PortalLink::links_s.end())  // entrance has no corresponding exit
    4751            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(eventEntity);
     52       
     53        endpoint->second->jumpOut(entity);
    5654    }
    5755
     56
    5857}
  • code/branches/portals/src/modules/portals/PortalLink.h

    r8200 r8243  
    88#include "objects/eventsystem/EventListener.h"
    99
    10 #include <set>
     10#include <map>
    1111
    1212namespace orxonox
    1313{
    14     class _PortalsExport PortalLink : public EventListener
     14    class _PortalsExport PortalLink : public BaseObject
    1515    {
    1616        public:
     
    3636                return this->toID_;
    3737            }
    38             void use(WorldEntity * entity);
    39             virtual void processEvent(Event& event);
     38            static void use(MobileEntity * entity, PortalEndPoint * entrance);
    4039        protected:
    4140        private:
     41            static std::map<PortalEndPoint *, PortalEndPoint *> links_s;
    4242            unsigned int fromID_;
    4343            unsigned int toID_;
     
    4545            PortalEndPoint* to_;
    4646            float activationRadius_;
    47             std::set<WorldEntity *> recentlyPorted;
    48             ObjectList<WorldEntity>::iterator it_;
    4947            bool isNowPortable(WorldEntity * ent);
    5048    };
Note: See TracChangeset for help on using the changeset viewer.