[Orxonox-commit 3557] r8243 - in code/branches/portals: data/levels src/modules/objects/triggers src/modules/portals
anbueche at orxonox.net
anbueche at orxonox.net
Thu Apr 14 16:33:34 CEST 2011
Author: anbueche
Date: 2011-04-14 16:33:33 +0200 (Thu, 14 Apr 2011)
New Revision: 8243
Modified:
code/branches/portals/data/levels/portals.oxw
code/branches/portals/src/modules/objects/triggers/MultiTrigger.h
code/branches/portals/src/modules/portals/PortalEndPoint.cc
code/branches/portals/src/modules/portals/PortalEndPoint.h
code/branches/portals/src/modules/portals/PortalLink.cc
code/branches/portals/src/modules/portals/PortalLink.h
Log:
portals work pretty good
Modified: code/branches/portals/data/levels/portals.oxw
===================================================================
--- code/branches/portals/data/levels/portals.oxw 2011-04-14 13:45:24 UTC (rev 8242)
+++ code/branches/portals/data/levels/portals.oxw 2011-04-14 14:33:33 UTC (rev 8243)
@@ -25,19 +25,29 @@
skybox = "Orxonox/skypanoramagen1"
>
+ <Template name=portalEventTemplate>
+ <PortalEndPoint>
+ <events>
+ <execute>
+ <EventListener event="portal" />
+ </execute>
+ </events>
+ </PortalEndPoint>
+ </Template>
- <PortalEndPoint position="0,0,0" id="1">
- <attached>
- <Billboard material="Examples/Flare" />
- </attached>
- </PortalEndPoint>
- <PortalEndPoint position="-100,0,0" id="2">
- <attached>
- <Billboard material="Examples/Flare2" />
- </attached>
- </PortalEndPoint>
- <PortalLink fromID="1" toID="2" />
+ <Template name=portalDefault>
+ <PortalEndPoint>
+ <attached>
+ <Billboard material="Portals/Default" />
+ </attached>
+ </PortalEndPoint>
+ </Template>
+ <PortalEndPoint position="0,0,0" id="1" distance="40" target="MobileEntity" design="portalDefault" eventTemplate="portalEventTemplate" />
+ <PortalEndPoint position="-400,0,0" id="2" distance="40" lookat="0,100,0" target="MobileEntity" design="portalDefault" eventTemplate="portalEventTemplate" />
+ <PortalLink fromID="1" toID="2" />
+ <PortalLink fromID="2" toID="1" />
+
<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" />
<SpawnPoint position="200,0,0" lookat="0,0,0" spawnclass=SpaceShip pawndesign=spaceshipassff />
Modified: code/branches/portals/src/modules/objects/triggers/MultiTrigger.h
===================================================================
--- code/branches/portals/src/modules/objects/triggers/MultiTrigger.h 2011-04-14 13:45:24 UTC (rev 8242)
+++ code/branches/portals/src/modules/objects/triggers/MultiTrigger.h 2011-04-14 14:33:33 UTC (rev 8243)
@@ -145,6 +145,8 @@
*/
inline bool isTarget(BaseObject* target)
{ if(target == NULL) return true; else return targetMask_.isIncluded(target->getIdentifier()); }
+
+ void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.
protected:
virtual std::queue<MultiTriggerState*>* letTrigger(void); //!< This method is called by the MultiTrigger to get information about new trigger events that need to be looked at.
@@ -157,7 +159,6 @@
void fire(bool status, BaseObject* originator = NULL); //!< Helper method. Creates an Event for the given status and originator and fires it.
void broadcast(bool status); //!< Helper method. Broadcasts an Event for every object that is a target.
- void addTargets(const std::string& targets); //!< Add some target to the MultiTrigger.
void removeTargets(const std::string& targets); //!< Remove some target from the MultiTrigger.
/**
Modified: code/branches/portals/src/modules/portals/PortalEndPoint.cc
===================================================================
--- code/branches/portals/src/modules/portals/PortalEndPoint.cc 2011-04-14 13:45:24 UTC (rev 8242)
+++ code/branches/portals/src/modules/portals/PortalEndPoint.cc 2011-04-14 14:33:33 UTC (rev 8243)
@@ -1,26 +1,37 @@
#include "PortalEndPoint.h"
#include "core/XMLPort.h"
+#include "objects/triggers/MultiTriggerContainer.h"
+#include "portals/PortalLink.h"
+#include "worldentities/MobileEntity.h"
+
namespace orxonox
{
CreateFactory(PortalEndPoint);
std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s;
- PortalEndPoint::PortalEndPoint(BaseObject* creator) : DistanceMultiTrigger(creator), id_(0)
+ PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(new DistanceMultiTrigger(this))
{
RegisterObject(PortalEndPoint);
+ this->trigger_->setName("portal");
+ this->attach(trigger_);
}
PortalEndPoint::~PortalEndPoint()
{
-
+
}
void PortalEndPoint::XMLPort(Element& xmlelement, XMLPort::Mode mode)
{
SUPER(PortalEndPoint, XMLPort, xmlelement, mode);
+
XMLPortParam(PortalEndPoint, "id", setID, getID, xmlelement, mode);
+ XMLPortParam(PortalEndPoint, "design", setTemplate, getTemplate, xmlelement, mode);
+ XMLPortParamExtern(PortalEndPoint, DistanceMultiTrigger, this->trigger_, "distance", setDistance, getDistance, xmlelement, mode);
+ XMLPortParamLoadOnly(PortalEndPoint, "eventTemplate", setEventTemplate, xmlelement, mode);
+ XMLPortParamLoadOnly(PortalEndPoint, "target", setTargets, xmlelement, mode).defaultValues("Pawn");
if(mode == XMLPort::LoadObject)
{
@@ -28,25 +39,55 @@
}
}
- void PortalEndPoint::tick(float dt)
+ void PortalEndPoint::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
{
- SUPER(PortalEndPoint, tick, dt);
+ SUPER(PortalEndPoint, XMLEventPort, xmlelement, mode);
+
+ XMLPortEventSink(PortalEndPoint, BaseObject, "execute", execute, xmlelement, mode);
}
- void PortalEndPoint::jumpOut(WorldEntity* entity)
+ bool PortalEndPoint::execute(bool bTriggered, BaseObject* trigger)
{
- this->recentlyJumpedOut_.insert(entity);
- entity->setPosition(this->getPosition());
- }
-
- bool PortalEndPoint::hasRecentlyJumpedOut(WorldEntity* entity)
- {
- if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end())
+ MultiTriggerContainer * cont = orxonox_cast<MultiTriggerContainer *>(trigger);
+ if(cont == 0)
+ return true;
+
+ DistanceMultiTrigger * originatingTrigger = orxonox_cast<DistanceMultiTrigger *>(cont->getOriginator());
+ if(originatingTrigger == 0)
{
- return false;
+ COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;
+ return true;
}
+
+ if(this->getAttachedObjects().find(orxonox_cast<WorldEntity *>(originatingTrigger)) == this->getAttachedObjects().end()) // only necessary if events have the same name
+ return true;
+
+ MobileEntity * entity = orxonox_cast<MobileEntity *>(cont->getData());
+ if(entity == 0)
+ return true;
+
+ if(bTriggered)
+ {
+ if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end()) // only enter the portal if not recently jumped out of it
+ {
+ PortalLink::use(entity, this);
+ }
+ }
else
- return true;
+ {
+ this->recentlyJumpedOut_.erase(entity);
+ }
+
+ return true;
}
+ void PortalEndPoint::jumpOut(MobileEntity* entity)
+ {
+ this->recentlyJumpedOut_.insert(entity);
+ entity->setPosition(this->getWorldPosition());
+ entity->rotate(this->getWorldOrientation());
+ entity->setVelocity(this->getWorldOrientation() * entity->getVelocity());
+ }
+
+
}
Modified: code/branches/portals/src/modules/portals/PortalEndPoint.h
===================================================================
--- code/branches/portals/src/modules/portals/PortalEndPoint.h 2011-04-14 13:45:24 UTC (rev 8242)
+++ code/branches/portals/src/modules/portals/PortalEndPoint.h 2011-04-14 14:33:33 UTC (rev 8243)
@@ -10,16 +10,22 @@
#include "worldentities/StaticEntity.h"
#include "graphics/Billboard.h"
#include "objects/triggers/DistanceMultiTrigger.h"
+#include "core/EventIncludes.h"
namespace orxonox
{
- class _PortalsExport PortalEndPoint : public DistanceMultiTrigger
+ class _PortalsExport PortalEndPoint : public StaticEntity
{
public:
PortalEndPoint(BaseObject* creator);
virtual ~PortalEndPoint();
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
- //virtual void tick(float dt);
+ inline void setTargets(const std::string & targets)
+ {
+ this->trigger_->addTargets(targets);
+ }
+
+ void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
static std::map<unsigned int, PortalEndPoint *> idMap_s; //!< maps integer id values to portalendpoints
inline void setID(unsigned int id)
{
@@ -30,13 +36,27 @@
{
return this->id_;
}
- void jumpOut(WorldEntity * entity); //!< relocate an entity to the position of the endpoint and add it to the set of recentlyPortedOut entities
- void tick(float dt);
- bool hasRecentlyJumpedOut(WorldEntity * entity); //!< check if a certain entity recently jumped out of this endpoint
+ inline void setTemplate(const std::string & name)
+ {
+ this->templateName_ = name;
+ this->addTemplate(name);
+ }
+ inline const std::string & getTemplate()
+ {
+ return this->templateName_;
+ }
+ bool execute(bool bTriggered, BaseObject* trigger);
+ void jumpOut(MobileEntity * entity);
protected:
private:
unsigned int id_;
- 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
+ DistanceMultiTrigger * trigger_;
+ std::string templateName_;
+ void setEventTemplate(const std::string & temp)
+ {
+ this->addTemplate(temp);
+ }
+ 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
};
}
Modified: code/branches/portals/src/modules/portals/PortalLink.cc
===================================================================
--- code/branches/portals/src/modules/portals/PortalLink.cc 2011-04-14 13:45:24 UTC (rev 8242)
+++ code/branches/portals/src/modules/portals/PortalLink.cc 2011-04-14 14:33:33 UTC (rev 8243)
@@ -1,12 +1,15 @@
#include "PortalLink.h"
#include "core/XMLPort.h"
#include "objects/triggers/MultiTriggerContainer.h"
+#include "worldentities/MobileEntity.h"
namespace orxonox
{
CreateFactory(PortalLink);
+
+ std::map<PortalEndPoint *, PortalEndPoint *> PortalLink::links_s;
- PortalLink::PortalLink(BaseObject* creator) : EventListener(creator), fromID_(0), toID_(0), from_(0), to_(0), activationRadius_(20)
+ PortalLink::PortalLink(BaseObject* creator) : BaseObject(creator), fromID_(0), toID_(0), from_(0), to_(0)
{
RegisterObject(PortalLink);
}
@@ -23,9 +26,9 @@
if(mode == XMLPort::LoadObject)
{
- this->from_ = PortalEndPoint::idMap_s[this->fromID_];
- this->to_ = PortalEndPoint::idMap_s[this->toID_];
- recentlyPorted.clear();
+ PortalEndPoint * from = PortalEndPoint::idMap_s[this->fromID_];
+ PortalEndPoint * to = PortalEndPoint::idMap_s[this->toID_];
+ PortalLink::links_s[from] = to;
}
}
@@ -33,26 +36,22 @@
{
SUPER(PortalLink, tick, dt);
}
-
- void PortalLink::processEvent(Event& event)
+
+ void PortalLink::use(MobileEntity* entity, PortalEndPoint * entrance)
{
- EventListener::processEvent(event);
- if(!event.activate_)
+ if(entrance == 0)
{
+ // TODO COUT
return;
}
- MultiTriggerContainer * origin = dynamic_cast<MultiTriggerContainer *>(event.originator_);
- if(!origin)
- {
+
+ std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoint = PortalLink::links_s.find(entrance);
+
+ if(endpoint == PortalLink::links_s.end()) // entrance has no corresponding exit
return;
- }
- PortalEndPoint * eventFrom = dynamic_cast<PortalEndPoint *>(origin->getOriginator());
- WorldEntity * eventEntity = dynamic_cast<WorldEntity *>(origin->getData());
- if(eventFrom != this->from_ || !eventEntity || eventFrom->hasRecentlyJumpedOut(eventEntity) == true)
- {
- return;
- }
- to_->jumpOut(eventEntity);
+
+ endpoint->second->jumpOut(entity);
}
+
}
Modified: code/branches/portals/src/modules/portals/PortalLink.h
===================================================================
--- code/branches/portals/src/modules/portals/PortalLink.h 2011-04-14 13:45:24 UTC (rev 8242)
+++ code/branches/portals/src/modules/portals/PortalLink.h 2011-04-14 14:33:33 UTC (rev 8243)
@@ -7,11 +7,11 @@
#include "PortalEndPoint.h"
#include "objects/eventsystem/EventListener.h"
-#include <set>
+#include <map>
namespace orxonox
{
- class _PortalsExport PortalLink : public EventListener
+ class _PortalsExport PortalLink : public BaseObject
{
public:
PortalLink(BaseObject* creator);
@@ -35,17 +35,15 @@
{
return this->toID_;
}
- void use(WorldEntity * entity);
- virtual void processEvent(Event& event);
+ static void use(MobileEntity * entity, PortalEndPoint * entrance);
protected:
private:
+ static std::map<PortalEndPoint *, PortalEndPoint *> links_s;
unsigned int fromID_;
unsigned int toID_;
PortalEndPoint* from_;
PortalEndPoint* to_;
float activationRadius_;
- std::set<WorldEntity *> recentlyPorted;
- ObjectList<WorldEntity>::iterator it_;
bool isNowPortable(WorldEntity * ent);
};
More information about the Orxonox-commit
mailing list