Changeset 8243
- Timestamp:
- Apr 14, 2011, 4:33:33 PM (14 years ago)
- Location:
- code/branches/portals
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/portals/data/levels/portals.oxw
r8200 r8243 26 26 > 27 27 28 <Template name=portalEventTemplate> 29 <PortalEndPoint> 30 <events> 31 <execute> 32 <EventListener event="portal" /> 33 </execute> 34 </events> 35 </PortalEndPoint> 36 </Template> 28 37 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" /> 40 50 41 51 <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 146 146 inline bool isTarget(BaseObject* target) 147 147 { 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. 148 150 149 151 protected: … … 158 160 void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target. 159 161 160 void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.161 162 void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger. 162 163 -
code/branches/portals/src/modules/portals/PortalEndPoint.cc
r8200 r8243 1 1 #include "PortalEndPoint.h" 2 2 #include "core/XMLPort.h" 3 #include "objects/triggers/MultiTriggerContainer.h" 4 #include "portals/PortalLink.h" 5 #include "worldentities/MobileEntity.h" 6 3 7 4 8 namespace orxonox … … 8 12 std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s; 9 13 10 PortalEndPoint::PortalEndPoint(BaseObject* creator) : DistanceMultiTrigger(creator), id_(0)14 PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(new DistanceMultiTrigger(this)) 11 15 { 12 16 RegisterObject(PortalEndPoint); 17 this->trigger_->setName("portal"); 18 this->attach(trigger_); 13 19 } 14 20 15 21 PortalEndPoint::~PortalEndPoint() 16 22 { 17 23 18 24 } 19 25 … … 21 27 { 22 28 SUPER(PortalEndPoint, XMLPort, xmlelement, mode); 29 23 30 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"); 24 35 25 36 if(mode == XMLPort::LoadObject) … … 29 40 } 30 41 31 void PortalEndPoint:: tick(float dt)42 void PortalEndPoint::XMLEventPort(Element& xmlelement, XMLPort::Mode mode) 32 43 { 33 SUPER(PortalEndPoint, tick, dt); 44 SUPER(PortalEndPoint, XMLEventPort, xmlelement, mode); 45 46 XMLPortEventSink(PortalEndPoint, BaseObject, "execute", execute, xmlelement, mode); 34 47 } 35 48 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) 37 85 { 38 86 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()); 40 90 } 41 91 42 bool PortalEndPoint::hasRecentlyJumpedOut(WorldEntity* entity)43 {44 if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end())45 {46 return false;47 }48 else49 return true;50 }51 92 52 93 } -
code/branches/portals/src/modules/portals/PortalEndPoint.h
r8200 r8243 11 11 #include "graphics/Billboard.h" 12 12 #include "objects/triggers/DistanceMultiTrigger.h" 13 #include "core/EventIncludes.h" 13 14 14 15 namespace orxonox 15 16 { 16 class _PortalsExport PortalEndPoint : public DistanceMultiTrigger17 class _PortalsExport PortalEndPoint : public StaticEntity 17 18 { 18 19 public: … … 20 21 virtual ~PortalEndPoint(); 21 22 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); 23 29 static std::map<unsigned int, PortalEndPoint *> idMap_s; //!< maps integer id values to portalendpoints 24 30 inline void setID(unsigned int id) … … 31 37 return this->id_; 32 38 } 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); 36 50 protected: 37 51 private: 38 52 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 40 60 }; 41 61 -
code/branches/portals/src/modules/portals/PortalLink.cc
r8200 r8243 2 2 #include "core/XMLPort.h" 3 3 #include "objects/triggers/MultiTriggerContainer.h" 4 #include "worldentities/MobileEntity.h" 4 5 5 6 namespace orxonox 6 7 { 7 8 CreateFactory(PortalLink); 9 10 std::map<PortalEndPoint *, PortalEndPoint *> PortalLink::links_s; 8 11 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) 10 13 { 11 14 RegisterObject(PortalLink); … … 24 27 if(mode == XMLPort::LoadObject) 25 28 { 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; 29 32 } 30 33 } … … 34 37 SUPER(PortalLink, tick, dt); 35 38 } 36 37 void PortalLink:: processEvent(Event& event)39 40 void PortalLink::use(MobileEntity* entity, PortalEndPoint * entrance) 38 41 { 39 EventListener::processEvent(event); 40 if(!event.activate_) 42 if(entrance == 0) 41 43 { 44 // TODO COUT 42 45 return; 43 46 } 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 47 51 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); 56 54 } 57 55 56 58 57 } -
code/branches/portals/src/modules/portals/PortalLink.h
r8200 r8243 8 8 #include "objects/eventsystem/EventListener.h" 9 9 10 #include < set>10 #include <map> 11 11 12 12 namespace orxonox 13 13 { 14 class _PortalsExport PortalLink : public EventListener14 class _PortalsExport PortalLink : public BaseObject 15 15 { 16 16 public: … … 36 36 return this->toID_; 37 37 } 38 void use(WorldEntity * entity); 39 virtual void processEvent(Event& event); 38 static void use(MobileEntity * entity, PortalEndPoint * entrance); 40 39 protected: 41 40 private: 41 static std::map<PortalEndPoint *, PortalEndPoint *> links_s; 42 42 unsigned int fromID_; 43 43 unsigned int toID_; … … 45 45 PortalEndPoint* to_; 46 46 float activationRadius_; 47 std::set<WorldEntity *> recentlyPorted;48 ObjectList<WorldEntity>::iterator it_;49 47 bool isNowPortable(WorldEntity * ent); 50 48 };
Note: See TracChangeset
for help on using the changeset viewer.