Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8511


Ignore:
Timestamp:
May 19, 2011, 4:01:34 PM (13 years ago)
Author:
anbueche
Message:

added reenter delay, added comments

Location:
code/branches/portals2
Files:
4 edited

Legend:

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

    r8457 r8511  
    3535    </Template>
    3636
    37     <PortalEndPoint position="0,0,0" id="1" distance="40" target="MobileEntity" design="PortalDefault"/>
    38     <PortalEndPoint position="-100,0,0" id="2" distance="40" target="MobileEntity" design="PortalDefault"/>
     37    <PortalEndPoint position="0,0,0" id="1" distance="40" target="MobileEntity" design="PortalDefault" reenterDelay="0"/>
     38    <PortalEndPoint position="-100,0,0" id="2" distance="40" target="MobileEntity" design="PortalDefault" reenterDelay="0"/>
    3939    <PortalLink fromID="1" toID="2" />
    4040    <PortalLink fromID="2" toID="1" />
  • code/branches/portals2/src/modules/portals/PortalEndPoint.cc

    r8466 r8511  
    1414    std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s;
    1515
    16     PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(new DistanceMultiTrigger(this))
     16    PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(new DistanceMultiTrigger(this)), reenterDelay_(0)
    1717    {
    1818        RegisterObject(PortalEndPoint);
     
    3232        XMLPortParam(PortalEndPoint, "id", setID, getID, xmlelement, mode);
    3333        XMLPortParam(PortalEndPoint, "design", setTemplate, getTemplate, xmlelement, mode);
    34         XMLPortParamExtern(PortalEndPoint, DistanceMultiTrigger, this->trigger_, "distance", setDistance, getDistance, xmlelement, mode).defaultValues("50");
     34        XMLPortParam(PortalEndPoint, "reenterDelay", setReenterDelay, getReenterDelay, xmlelement, mode);
     35        XMLPortParamExtern(PortalEndPoint, DistanceMultiTrigger, this->trigger_, "distance", setDistance, getDistance, xmlelement, mode);
    3536        XMLPortParamLoadOnly(PortalEndPoint, "target", setTarget, xmlelement, mode).defaultValues("Pawn");
    3637       
     
    6364        if(originatingTrigger == 0)
    6465        {
    65             COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;
     66            // COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;
    6667            return true;
    6768        }
     
    7374        if(bTriggered)
    7475        {
    75             if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end())  // only enter the portal if not just jumped out of it
     76            if(this->letsEnter(entity))  // only enter the portal if not just (this very moment) jumped out of it, or if the reenterDelay expired
    7677            {
    7778                PortalLink::use(entity, this);
     
    8687    }
    8788
     89    bool PortalEndPoint::letsEnter(MobileEntity* entity)
     90    {
     91        // not allowed to enter if reenterDelay hasn't expired yet
     92        std::map<MobileEntity *, time_t>::const_iterator time = this->jumpOutTimes_.find(entity);
     93        if(time != this->jumpOutTimes_.end() && std::difftime(std::time(0),time->second) < this->reenterDelay_)
     94            return false;
     95
     96        // not allowed to enter if jumped out of this portal and not left its activation radius yet
     97        std::set<MobileEntity *>::const_iterator recent = this->recentlyJumpedOut_.find(entity);
     98        if(recent != this->recentlyJumpedOut_.end())
     99            return false;
     100       
     101        return true;
     102    }
     103
    88104    void PortalEndPoint::jumpOut(MobileEntity* entity)
    89105    {
     106        this->jumpOutTimes_[entity] = std::time(0);
    90107        this->recentlyJumpedOut_.insert(entity);
    91108       
  • code/branches/portals2/src/modules/portals/PortalEndPoint.h

    r8466 r8511  
    1818#include "objects/triggers/DistanceMultiTrigger.h"
    1919#include "core/EventIncludes.h"
     20#include <ctime>
    2021
    2122namespace orxonox
     
    4142            void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
    4243            static std::map<unsigned int, PortalEndPoint *> idMap_s; //!< Maps the id of each PortalEndPoint to a pointer to that PortalEndPoint
     44            inline void setReenterDelay(unsigned int seconds)
     45            {
     46                this->reenterDelay_ = seconds;
     47            }
     48            inline unsigned int getReenterDelay()
     49            {
     50                return this->reenterDelay_;
     51            }
    4352            inline void setID(unsigned int id)
    4453            {
     
    6574
    6675            /*! \brief This function is called each time the DistanceMultiTrigger of this PortalEndPoint changed
    67              * \param bTriggered true if the trigger was triggered on, false if the trigger has switched to off
    68              * \param trigger the MultiTriggerContainer containing the triggering BaseObject (and trigger_ the portal's MultiDistanceTrigger which we already know)
    69              *
    70              * if bTriggered is \c true the triggering entity enters this portal (if it is an entrance)
    71              * otherwise the triggering entity is removed from the set of entities who recently jumped out of this portal */
     76                \param bTriggered true if the trigger was triggered on, false if the trigger has switched to off
     77                \param trigger the MultiTriggerContainer containing the triggering BaseObject (and trigger_ the portal's MultiDistanceTrigger which we already know)
     78            */
    7279            bool execute(bool bTriggered, BaseObject* trigger);
    7380
     
    7582             * \param entity The Entity which should jump out of this portal */
    7683            void jumpOut(MobileEntity * entity);
     84           
     85            /** \brief Tells wether a certain Entity is allowed to enter the PortalEndPoint?
     86                @return @c true if the entity not just came out of this portal and the reenterDelay has expired for it, @c false otherwise
     87            */
     88            bool letsEnter(MobileEntity* entity);
    7789        protected:
    7890           
     
    8496            std::string templateName_;            //!< The name of the design template used for this endpoint
    8597
    86             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
     98            int reenterDelay_;
     99            std::map<MobileEntity *, time_t> jumpOutTimes_;   //!< Stores the time at which a certain MobileEntity @ref jumpOut "jumped out" of this PortalEndPoint
     100            std::set<MobileEntity *> recentlyJumpedOut_;
    87101    };
    88102
  • code/branches/portals2/src/modules/portals/PortalLink.cc

    r8457 r8511  
    4141        }
    4242       
    43         std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoint = PortalLink::links_s.find(entrance);
     43        std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoints = PortalLink::links_s.find(entrance);
    4444       
    45         if(endpoint == PortalLink::links_s.end())  // entrance has no corresponding exit
     45        if(endpoints == PortalLink::links_s.end())  // entrance has no corresponding exit
    4646            return;
    4747       
    48         endpoint->second->jumpOut(entity);
     48        endpoints->second->jumpOut(entity);
    4949    }
    5050
Note: See TracChangeset for help on using the changeset viewer.