[Orxonox-commit 3835] r8511 - in code/branches/portals2: data/levels src/modules/portals

anbueche at orxonox.net anbueche at orxonox.net
Thu May 19 16:01:35 CEST 2011


Author: anbueche
Date: 2011-05-19 16:01:34 +0200 (Thu, 19 May 2011)
New Revision: 8511

Modified:
   code/branches/portals2/data/levels/portals.oxw
   code/branches/portals2/src/modules/portals/PortalEndPoint.cc
   code/branches/portals2/src/modules/portals/PortalEndPoint.h
   code/branches/portals2/src/modules/portals/PortalLink.cc
Log:
added reenter delay, added comments

Modified: code/branches/portals2/data/levels/portals.oxw
===================================================================
--- code/branches/portals2/data/levels/portals.oxw	2011-05-19 12:54:02 UTC (rev 8510)
+++ code/branches/portals2/data/levels/portals.oxw	2011-05-19 14:01:34 UTC (rev 8511)
@@ -34,8 +34,8 @@
         </PortalEndPoint>
     </Template>
 
-    <PortalEndPoint position="0,0,0" id="1" distance="40" target="MobileEntity" design="PortalDefault"/>
-    <PortalEndPoint position="-100,0,0" id="2" distance="40" target="MobileEntity" design="PortalDefault"/>
+    <PortalEndPoint position="0,0,0" id="1" distance="40" target="MobileEntity" design="PortalDefault" reenterDelay="0"/>
+    <PortalEndPoint position="-100,0,0" id="2" distance="40" target="MobileEntity" design="PortalDefault" reenterDelay="0"/>
     <PortalLink fromID="1" toID="2" />
     <PortalLink fromID="2" toID="1" />
 

Modified: code/branches/portals2/src/modules/portals/PortalEndPoint.cc
===================================================================
--- code/branches/portals2/src/modules/portals/PortalEndPoint.cc	2011-05-19 12:54:02 UTC (rev 8510)
+++ code/branches/portals2/src/modules/portals/PortalEndPoint.cc	2011-05-19 14:01:34 UTC (rev 8511)
@@ -13,7 +13,7 @@
 
     std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s;
 
-    PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(new DistanceMultiTrigger(this))
+    PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(new DistanceMultiTrigger(this)), reenterDelay_(0)
     {
         RegisterObject(PortalEndPoint);
         this->trigger_->setName("portal");
@@ -31,7 +31,8 @@
         
         XMLPortParam(PortalEndPoint, "id", setID, getID, xmlelement, mode);
         XMLPortParam(PortalEndPoint, "design", setTemplate, getTemplate, xmlelement, mode);
-        XMLPortParamExtern(PortalEndPoint, DistanceMultiTrigger, this->trigger_, "distance", setDistance, getDistance, xmlelement, mode).defaultValues("50");
+        XMLPortParam(PortalEndPoint, "reenterDelay", setReenterDelay, getReenterDelay, xmlelement, mode);
+        XMLPortParamExtern(PortalEndPoint, DistanceMultiTrigger, this->trigger_, "distance", setDistance, getDistance, xmlelement, mode);
         XMLPortParamLoadOnly(PortalEndPoint, "target", setTarget, xmlelement, mode).defaultValues("Pawn");
         
         // Add the DistanceMultiTrigger as event source.
@@ -62,7 +63,7 @@
         DistanceMultiTrigger * originatingTrigger = orxonox_cast<DistanceMultiTrigger *>(cont->getOriginator());
         if(originatingTrigger == 0)
         {
-            COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;
+            // COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;
             return true;
         }
         
@@ -72,7 +73,7 @@
         
         if(bTriggered)
         {
-            if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end())  // only enter the portal if not just jumped out of it
+            if(this->letsEnter(entity))  // only enter the portal if not just (this very moment) jumped out of it, or if the reenterDelay expired
             {
                 PortalLink::use(entity, this);
             }
@@ -85,8 +86,24 @@
         return true;
     }
 
+    bool PortalEndPoint::letsEnter(MobileEntity* entity)
+    {
+        // not allowed to enter if reenterDelay hasn't expired yet
+        std::map<MobileEntity *, time_t>::const_iterator time = this->jumpOutTimes_.find(entity);
+        if(time != this->jumpOutTimes_.end() && std::difftime(std::time(0),time->second) < this->reenterDelay_)
+            return false;
+
+        // not allowed to enter if jumped out of this portal and not left its activation radius yet
+        std::set<MobileEntity *>::const_iterator recent = this->recentlyJumpedOut_.find(entity);
+        if(recent != this->recentlyJumpedOut_.end())
+            return false;
+        
+        return true;
+    }
+
     void PortalEndPoint::jumpOut(MobileEntity* entity)
     {
+        this->jumpOutTimes_[entity] = std::time(0);
         this->recentlyJumpedOut_.insert(entity);
         
         entity->setPosition(this->getWorldPosition());

Modified: code/branches/portals2/src/modules/portals/PortalEndPoint.h
===================================================================
--- code/branches/portals2/src/modules/portals/PortalEndPoint.h	2011-05-19 12:54:02 UTC (rev 8510)
+++ code/branches/portals2/src/modules/portals/PortalEndPoint.h	2011-05-19 14:01:34 UTC (rev 8511)
@@ -17,6 +17,7 @@
 #include "graphics/Billboard.h"
 #include "objects/triggers/DistanceMultiTrigger.h"
 #include "core/EventIncludes.h"
+#include <ctime>
 
 namespace orxonox
 {
@@ -40,6 +41,14 @@
             
             void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
             static std::map<unsigned int, PortalEndPoint *> idMap_s; //!< Maps the id of each PortalEndPoint to a pointer to that PortalEndPoint
+            inline void setReenterDelay(unsigned int seconds)
+            {
+                this->reenterDelay_ = seconds;
+            }
+            inline unsigned int getReenterDelay()
+            {
+                return this->reenterDelay_;
+            }
             inline void setID(unsigned int id)
             {
                 this->id_ = id;
@@ -64,16 +73,19 @@
             }
 
             /*! \brief This function is called each time the DistanceMultiTrigger of this PortalEndPoint changed
-             * \param bTriggered true if the trigger was triggered on, false if the trigger has switched to off
-             * \param trigger the MultiTriggerContainer containing the triggering BaseObject (and trigger_ the portal's MultiDistanceTrigger which we already know)
-             * 
-             * if bTriggered is \c true the triggering entity enters this portal (if it is an entrance)
-             * otherwise the triggering entity is removed from the set of entities who recently jumped out of this portal */
+                \param bTriggered true if the trigger was triggered on, false if the trigger has switched to off
+                \param trigger the MultiTriggerContainer containing the triggering BaseObject (and trigger_ the portal's MultiDistanceTrigger which we already know)
+            */
             bool execute(bool bTriggered, BaseObject* trigger);
 
             /*! \brief Let an Entity jump out of this portal no matter where it was before
              * \param entity The Entity which should jump out of this portal */
             void jumpOut(MobileEntity * entity);
+            
+            /** \brief Tells wether a certain Entity is allowed to enter the PortalEndPoint?
+                @return @c true if the entity not just came out of this portal and the reenterDelay has expired for it, @c false otherwise
+            */
+            bool letsEnter(MobileEntity* entity);
         protected:
             
         private:
@@ -83,7 +95,9 @@
             DistanceMultiTrigger * trigger_;      //!< the DistanceMultiTrigger which notices near entities of the defined type
             std::string templateName_;            //!< The name of the design template used for this endpoint
 
-            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
+            int reenterDelay_;
+            std::map<MobileEntity *, time_t> jumpOutTimes_;   //!< Stores the time at which a certain MobileEntity @ref jumpOut "jumped out" of this PortalEndPoint
+            std::set<MobileEntity *> recentlyJumpedOut_;
     };
 
 }

Modified: code/branches/portals2/src/modules/portals/PortalLink.cc
===================================================================
--- code/branches/portals2/src/modules/portals/PortalLink.cc	2011-05-19 12:54:02 UTC (rev 8510)
+++ code/branches/portals2/src/modules/portals/PortalLink.cc	2011-05-19 14:01:34 UTC (rev 8511)
@@ -40,12 +40,12 @@
             return;
         }
         
-        std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoint = PortalLink::links_s.find(entrance);
+        std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoints = PortalLink::links_s.find(entrance);
         
-        if(endpoint == PortalLink::links_s.end())  // entrance has no corresponding exit
+        if(endpoints == PortalLink::links_s.end())  // entrance has no corresponding exit
             return;
         
-        endpoint->second->jumpOut(entity);
+        endpoints->second->jumpOut(entity);
     }
 
 




More information about the Orxonox-commit mailing list