Changeset 8511 for code/branches/portals2/src/modules/portals
- Timestamp:
- May 19, 2011, 4:01:34 PM (14 years ago)
- Location:
- code/branches/portals2/src/modules/portals
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/portals2/src/modules/portals/PortalEndPoint.cc
r8466 r8511 14 14 std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s; 15 15 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) 17 17 { 18 18 RegisterObject(PortalEndPoint); … … 32 32 XMLPortParam(PortalEndPoint, "id", setID, getID, xmlelement, mode); 33 33 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); 35 36 XMLPortParamLoadOnly(PortalEndPoint, "target", setTarget, xmlelement, mode).defaultValues("Pawn"); 36 37 … … 63 64 if(originatingTrigger == 0) 64 65 { 65 COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;66 // COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl; 66 67 return true; 67 68 } … … 73 74 if(bTriggered) 74 75 { 75 if(this-> recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end()) // only enter the portal if not just jumped out of it76 if(this->letsEnter(entity)) // only enter the portal if not just (this very moment) jumped out of it, or if the reenterDelay expired 76 77 { 77 78 PortalLink::use(entity, this); … … 86 87 } 87 88 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 88 104 void PortalEndPoint::jumpOut(MobileEntity* entity) 89 105 { 106 this->jumpOutTimes_[entity] = std::time(0); 90 107 this->recentlyJumpedOut_.insert(entity); 91 108 -
code/branches/portals2/src/modules/portals/PortalEndPoint.h
r8466 r8511 18 18 #include "objects/triggers/DistanceMultiTrigger.h" 19 19 #include "core/EventIncludes.h" 20 #include <ctime> 20 21 21 22 namespace orxonox … … 41 42 void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 42 43 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 } 43 52 inline void setID(unsigned int id) 44 53 { … … 65 74 66 75 /*! \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 */ 72 79 bool execute(bool bTriggered, BaseObject* trigger); 73 80 … … 75 82 * \param entity The Entity which should jump out of this portal */ 76 83 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); 77 89 protected: 78 90 … … 84 96 std::string templateName_; //!< The name of the design template used for this endpoint 85 97 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_; 87 101 }; 88 102 -
code/branches/portals2/src/modules/portals/PortalLink.cc
r8457 r8511 41 41 } 42 42 43 std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoint = PortalLink::links_s.find(entrance);43 std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoints = PortalLink::links_s.find(entrance); 44 44 45 if(endpoint == PortalLink::links_s.end()) // entrance has no corresponding exit45 if(endpoints == PortalLink::links_s.end()) // entrance has no corresponding exit 46 46 return; 47 47 48 endpoint ->second->jumpOut(entity);48 endpoints->second->jumpOut(entity); 49 49 } 50 50
Note: See TracChangeset
for help on using the changeset viewer.