Changeset 8706 for code/trunk/src/modules/portals
- Timestamp:
- Jun 14, 2011, 8:53:28 PM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/modules/portals/CMakeLists.txt
- Property svn:eol-style set to native
-
code/trunk/src/modules/portals/PortalEndPoint.cc
- Property svn:executable deleted
- Property svn:eol-style set to native
r8471 r8706 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Andreas Büchel 24 * Co-authors: 25 * ... 26 * 27 */ 28 1 29 #include "PortalEndPoint.h" 2 30 #include "core/XMLPort.h" … … 4 32 #include "portals/PortalLink.h" 5 33 #include "worldentities/MobileEntity.h" 6 34 #include <ctime> 7 35 8 36 namespace orxonox … … 14 42 std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s; 15 43 16 PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(NULL)44 PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), RadarViewable(creator, static_cast<WorldEntity*>(this)), id_(0), trigger_(NULL), reenterDelay_(0) 17 45 { 18 46 RegisterObject(PortalEndPoint); 47 19 48 this->trigger_ = new DistanceMultiTrigger(this); 20 49 this->trigger_->setName("portal"); 21 50 this->attach(trigger_); 51 52 this->setRadarObjectColour(ColourValue::White); 53 this->setRadarObjectShape(RadarViewable::Dot); 54 this->setRadarVisibility(true); 22 55 } 23 56 24 57 PortalEndPoint::~PortalEndPoint() 25 58 { 26 delete this->trigger_; 59 if(this->isInitialized() && this->trigger_ != NULL) 60 delete this->trigger_; 27 61 } 28 62 … … 33 67 XMLPortParam(PortalEndPoint, "id", setID, getID, xmlelement, mode); 34 68 XMLPortParam(PortalEndPoint, "design", setTemplate, getTemplate, xmlelement, mode); 69 XMLPortParam(PortalEndPoint, "reenterDelay", setReenterDelay, getReenterDelay, xmlelement, mode); 35 70 XMLPortParamExtern(PortalEndPoint, DistanceMultiTrigger, this->trigger_, "distance", setDistance, getDistance, xmlelement, mode); 36 71 XMLPortParamLoadOnly(PortalEndPoint, "target", setTarget, xmlelement, mode).defaultValues("Pawn"); … … 64 99 if(originatingTrigger == 0) 65 100 { 66 COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;67 101 return true; 68 102 } … … 74 108 if(bTriggered) 75 109 { 76 if(this-> recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end()) // only enter the portal if not just jumped out of it110 if(this->letsEnter(entity)) // only enter the portal if not just (this very moment) jumped out of it, or if the reenterDelay expired 77 111 { 78 112 PortalLink::use(entity, this); … … 87 121 } 88 122 123 void PortalEndPoint::changedActivity(void) 124 { 125 SUPER(PortalEndPoint, changedActivity); 126 127 this->setRadarVisibility(this->isActive()); 128 } 129 130 bool PortalEndPoint::letsEnter(MobileEntity* entity) 131 { 132 // not allowed to enter if reenterDelay hasn't expired yet 133 std::map<MobileEntity *, time_t>::const_iterator time = this->jumpOutTimes_.find(entity); 134 if(time != this->jumpOutTimes_.end() && std::difftime(std::time(0),time->second) < this->reenterDelay_) 135 return false; 136 137 // not allowed to enter if jumped out of this portal and not left its activation radius yet 138 std::set<MobileEntity *>::const_iterator recent = this->recentlyJumpedOut_.find(entity); 139 if(recent != this->recentlyJumpedOut_.end()) 140 return false; 141 142 return true; 143 } 144 89 145 void PortalEndPoint::jumpOut(MobileEntity* entity) 90 146 { 147 this->jumpOutTimes_[entity] = std::time(0); 91 148 this->recentlyJumpedOut_.insert(entity); 92 149 150 // adjust 93 151 entity->setPosition(this->getWorldPosition()); 94 152 entity->rotate(this->getWorldOrientation()); 95 153 entity->setVelocity(this->getWorldOrientation() * entity->getVelocity()); 96 entity->setVelocity(entity->getVelocity() * 1.5);97 154 } 98 155 -
code/trunk/src/modules/portals/PortalEndPoint.h
- Property svn:executable deleted
- Property svn:eol-style set to native
r8457 r8706 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Andreas Büchel 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 /** 30 * @file PortalEndPoint.h 31 * @brief Declaration of the PortalEndPoint class. 32 * @ingroup Portals 33 */ 34 1 35 #ifndef _PortalEndPoint_H__ 2 36 #define _PortalEndPoint_H__ … … 9 43 10 44 #include "worldentities/StaticEntity.h" 45 #include "interfaces/RadarViewable.h" 11 46 #include "graphics/Billboard.h" 12 47 #include "objects/triggers/DistanceMultiTrigger.h" 13 48 #include "core/EventIncludes.h" 49 #include <ctime> 14 50 15 51 namespace orxonox 16 52 { 17 class _PortalsExport PortalEndPoint : public StaticEntity 53 /** 54 @brief 55 A PortalEndPoint serves as portal entrance and/or exit. 56 57 @ingroup Portals 58 */ 59 60 class _PortalsExport PortalEndPoint : public StaticEntity, public RadarViewable 18 61 { 19 62 public: 20 63 PortalEndPoint(BaseObject* creator); 21 64 virtual ~PortalEndPoint(); 65 22 66 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 67 virtual void changedActivity(void); 68 23 69 inline void setTarget(const std::string & target) //!< add types which are allowed to activate the PortalEndPoint 24 { 25 this->trigger_->addTarget(target); 26 } 70 { this->trigger_->addTarget(target); } 27 71 28 72 void XMLEventPort(Element& xmlelement, XMLPort::Mode mode); 29 73 static std::map<unsigned int, PortalEndPoint *> idMap_s; //!< Maps the id of each PortalEndPoint to a pointer to that PortalEndPoint 74 inline void setReenterDelay(unsigned int seconds) 75 { this->reenterDelay_ = seconds; } 76 inline unsigned int getReenterDelay() 77 { return this->reenterDelay_; } 30 78 inline void setID(unsigned int id) 31 { 32 this->id_ = id; 33 } 79 { this->id_ = id; } 34 80 35 81 inline unsigned int getID() const 36 { 37 return this->id_; 38 } 82 { return this->id_; } 39 83 40 84 /// \brief Set templateName_ (the name of the design Template) and add that Template to this Object 41 85 inline void setTemplate(const std::string & name) 42 { 43 this->templateName_ = name; 44 this->addTemplate(name); 45 } 86 { this->templateName_ = name; this->addTemplate(name); } 46 87 47 88 /// \brief Get the name of the attached design template 48 89 inline const std::string & getTemplate() 49 { 50 return this->templateName_; 51 } 90 { return this->templateName_; } 52 91 53 92 /*! \brief This function is called each time the DistanceMultiTrigger of this PortalEndPoint changed 54 * \param bTriggered true if the trigger was triggered on, false if the trigger has switched to off 55 * \param trigger the MultiTriggerContainer containing the triggering BaseObject (and trigger_ the portal's MultiDistanceTrigger which we already know) 56 * 57 * if bTriggered is \c true the triggering entity enters this portal (if it is an entrance) 58 * otherwise the triggering entity is removed from the set of entities who recently jumped out of this portal */ 93 \param bTriggered true if the trigger was triggered on, false if the trigger has switched to off 94 \param trigger the MultiTriggerContainer containing the triggering BaseObject (and trigger_ the portal's MultiDistanceTrigger which we already know) 95 */ 59 96 bool execute(bool bTriggered, BaseObject* trigger); 60 97 … … 62 99 * \param entity The Entity which should jump out of this portal */ 63 100 void jumpOut(MobileEntity * entity); 101 102 /** \brief Tells wether a certain Entity is allowed to enter the PortalEndPoint? 103 @return @c true if the entity not just came out of this portal and the reenterDelay has expired for it, @c false otherwise 104 */ 105 bool letsEnter(MobileEntity* entity); 64 106 protected: 65 107 … … 71 113 std::string templateName_; //!< The name of the design template used for this endpoint 72 114 73 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 115 int reenterDelay_; 116 std::map<MobileEntity *, time_t> jumpOutTimes_; //!< Stores the time at which a certain MobileEntity @ref jumpOut "jumped out" of this PortalEndPoint 117 std::set<MobileEntity *> recentlyJumpedOut_; //!< Stores the entities witch recently jumped out of this PortalEndPoint and haven't left the activation radius yet. This is needed in order to prevent them from beeing pulled into the PortalEndPoint they have just come out of. 74 118 }; 75 119 -
code/trunk/src/modules/portals/PortalLink.cc
- Property svn:executable deleted
- Property svn:eol-style set to native
r8457 r8706 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Andreas Büchel 24 * Co-authors: 25 * ... 26 * 27 */ 28 1 29 #include "PortalLink.h" 2 30 #include "core/XMLPort.h" … … 17 45 PortalLink::~PortalLink() 18 46 { 47 19 48 } 20 49 … … 37 66 if(entrance == 0) 38 67 { 39 // TODO COUT40 68 return; 41 69 } 42 70 43 std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoint = PortalLink::links_s.find(entrance);71 std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoints = PortalLink::links_s.find(entrance); 44 72 45 if(endpoint == PortalLink::links_s.end()) // entrance has no corresponding exit73 if(endpoints == PortalLink::links_s.end()) // entrance has no corresponding exit 46 74 return; 47 48 endpoint ->second->jumpOut(entity);75 76 endpoints->second->jumpOut(entity); 49 77 } 50 51 52 78 } -
code/trunk/src/modules/portals/PortalLink.h
- Property svn:executable deleted
- Property svn:eol-style set to native
r8457 r8706 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Andreas Büchel 24 * Co-authors: 25 * ... 26 * 27 */ 28 29 /** 30 @file PortalLink.h 31 @brief Declaration of the PortalLink class 32 @ingroup Portals 33 */ 34 1 35 #ifndef _PortalLink_H__ 2 36 #define _PortalLink_H__ … … 12 46 namespace orxonox 13 47 { 48 /** 49 @brief 50 A PortalLink represents the connection between two @ref orxonox::PortalEndPoint "PortalEndPoints" 51 @ingroup Portals 52 */ 14 53 class _PortalsExport PortalLink : public BaseObject 15 54 { … … 34 73 return this->toID_; 35 74 } 36 static void use(MobileEntity * entity, PortalEndPoint * entrance); // 75 /*! \brief Let an entity enter a certain PortalEndPoint 76 \param entity pointer to the entity which is entering a PortalEndPoint 77 \param entrance pointer to the PortalEndPoint to enter 78 */ 79 static void use(MobileEntity * entity, PortalEndPoint * entrance); //!< let entity enter the PortalEndPoint pointed to by entrance 37 80 protected: 38 81 private: 39 static std::map<PortalEndPoint *, PortalEndPoint *> links_s; 40 unsigned int fromID_; 41 unsigned int toID_; 42 PortalEndPoint* from_; 43 PortalEndPoint* to_; 44 float activationRadius_; 45 bool isNowPortable(WorldEntity * ent); 82 static std::map<PortalEndPoint *, PortalEndPoint *> links_s; //!< maps entrances to exits 83 unsigned int fromID_; //!< id of the entrance of this Link 84 unsigned int toID_; //!< id of the exit of this Link 85 PortalEndPoint* from_; //!< pointer to this Link's entrance 86 PortalEndPoint* to_; //!< pointer to this Link's exit 46 87 }; 47 48 88 } 49 89 -
code/trunk/src/modules/portals/PortalsPrecompiledHeaders.h
- Property svn:eol-style set to native
-
code/trunk/src/modules/portals/PortalsPrereqs.h
- Property svn:eol-style set to native
Note: See TracChangeset
for help on using the changeset viewer.