Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 26, 2011, 4:35:46 PM (14 years ago)
Author:
dafrick
Message:

Merging portals2 branch into presentation branch.

Location:
code/branches/presentation
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation

  • code/branches/presentation/src/modules/portals/PortalEndPoint.cc

    r8471 r8605  
     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
    129#include "PortalEndPoint.h"
    230#include "core/XMLPort.h"
     
    432#include "portals/PortalLink.h"
    533#include "worldentities/MobileEntity.h"
    6 
     34#include <ctime>
    735
    836namespace orxonox
     
    1442    std::map<unsigned int, PortalEndPoint *> PortalEndPoint::idMap_s;
    1543
    16     PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(NULL)
     44    PortalEndPoint::PortalEndPoint(BaseObject* creator) : StaticEntity(creator), id_(0), trigger_(NULL), reenterDelay_(0)
    1745    {
    1846        RegisterObject(PortalEndPoint);
     47       
    1948        this->trigger_ = new DistanceMultiTrigger(this);
    2049        this->trigger_->setName("portal");
     
    2453    PortalEndPoint::~PortalEndPoint()
    2554    {
    26         delete this->trigger_;
     55        if(this->isInitialized() && this->trigger_ != NULL)
     56            delete this->trigger_;
    2757    }
    2858
     
    3363        XMLPortParam(PortalEndPoint, "id", setID, getID, xmlelement, mode);
    3464        XMLPortParam(PortalEndPoint, "design", setTemplate, getTemplate, xmlelement, mode);
     65        XMLPortParam(PortalEndPoint, "reenterDelay", setReenterDelay, getReenterDelay, xmlelement, mode);
    3566        XMLPortParamExtern(PortalEndPoint, DistanceMultiTrigger, this->trigger_, "distance", setDistance, getDistance, xmlelement, mode);
    3667        XMLPortParamLoadOnly(PortalEndPoint, "target", setTarget, xmlelement, mode).defaultValues("Pawn");
     
    6495        if(originatingTrigger == 0)
    6596        {
    66             COUT(1) << "originator no DistanceMultiTrigger\n" << std::endl;
    6797            return true;
    6898        }
     
    74104        if(bTriggered)
    75105        {
    76             if(this->recentlyJumpedOut_.find(entity) == this->recentlyJumpedOut_.end())  // only enter the portal if not just jumped out of it
     106            if(this->letsEnter(entity))  // only enter the portal if not just (this very moment) jumped out of it, or if the reenterDelay expired
    77107            {
    78108                PortalLink::use(entity, this);
     
    87117    }
    88118
     119    bool PortalEndPoint::letsEnter(MobileEntity* entity)
     120    {
     121        // not allowed to enter if reenterDelay hasn't expired yet
     122        std::map<MobileEntity *, time_t>::const_iterator time = this->jumpOutTimes_.find(entity);
     123        if(time != this->jumpOutTimes_.end() && std::difftime(std::time(0),time->second) < this->reenterDelay_)
     124            return false;
     125
     126        // not allowed to enter if jumped out of this portal and not left its activation radius yet
     127        std::set<MobileEntity *>::const_iterator recent = this->recentlyJumpedOut_.find(entity);
     128        if(recent != this->recentlyJumpedOut_.end())
     129            return false;
     130       
     131        return true;
     132    }
     133
    89134    void PortalEndPoint::jumpOut(MobileEntity* entity)
    90135    {
     136        this->jumpOutTimes_[entity] = std::time(0);
    91137        this->recentlyJumpedOut_.insert(entity);
    92        
     138
     139        // adjust
    93140        entity->setPosition(this->getWorldPosition());
    94141        entity->rotate(this->getWorldOrientation());
    95142        entity->setVelocity(this->getWorldOrientation() * entity->getVelocity());
    96         entity->setVelocity(entity->getVelocity() * 1.5);
    97143    }
    98144
  • code/branches/presentation/src/modules/portals/PortalEndPoint.h

    r8457 r8605  
     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
    135#ifndef _PortalEndPoint_H__
    236#define _PortalEndPoint_H__
     
    1246#include "objects/triggers/DistanceMultiTrigger.h"
    1347#include "core/EventIncludes.h"
     48#include <ctime>
    1449
    1550namespace orxonox
    1651{
     52    /**
     53     @brief
     54     A PortalEndPoint serves as portal entrance and/or exit.
     55     
     56     @ingroup Portals
     57     */
     58   
    1759    class _PortalsExport PortalEndPoint : public StaticEntity
    1860    {
     
    2870            void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
    2971            static std::map<unsigned int, PortalEndPoint *> idMap_s; //!< Maps the id of each PortalEndPoint to a pointer to that PortalEndPoint
     72            inline void setReenterDelay(unsigned int seconds)
     73            {
     74                this->reenterDelay_ = seconds;
     75            }
     76            inline unsigned int getReenterDelay()
     77            {
     78                return this->reenterDelay_;
     79            }
    3080            inline void setID(unsigned int id)
    3181            {
     
    52102
    53103            /*! \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 */
     104                \param bTriggered true if the trigger was triggered on, false if the trigger has switched to off
     105                \param trigger the MultiTriggerContainer containing the triggering BaseObject (and trigger_ the portal's MultiDistanceTrigger which we already know)
     106            */
    59107            bool execute(bool bTriggered, BaseObject* trigger);
    60108
     
    62110             * \param entity The Entity which should jump out of this portal */
    63111            void jumpOut(MobileEntity * entity);
     112           
     113            /** \brief Tells wether a certain Entity is allowed to enter the PortalEndPoint?
     114                @return @c true if the entity not just came out of this portal and the reenterDelay has expired for it, @c false otherwise
     115            */
     116            bool letsEnter(MobileEntity* entity);
    64117        protected:
    65118           
     
    71124            std::string templateName_;            //!< The name of the design template used for this endpoint
    72125
    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
     126            int reenterDelay_;
     127            std::map<MobileEntity *, time_t> jumpOutTimes_;   //!< Stores the time at which a certain MobileEntity @ref jumpOut "jumped out" of this PortalEndPoint
     128            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.
    74129    };
    75130
  • code/branches/presentation/src/modules/portals/PortalLink.cc

    r8457 r8605  
     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
    129#include "PortalLink.h"
    230#include "core/XMLPort.h"
     
    1745    PortalLink::~PortalLink()
    1846    {
     47       
    1948    }
    2049   
     
    3766        if(entrance == 0)
    3867        {
    39             // TODO COUT
    4068            return;
    4169        }
    4270       
    43         std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoint = PortalLink::links_s.find(entrance);
     71        std::map<PortalEndPoint *, PortalEndPoint *>::iterator endpoints = PortalLink::links_s.find(entrance);
    4472       
    45         if(endpoint == PortalLink::links_s.end())  // entrance has no corresponding exit
     73        if(endpoints == PortalLink::links_s.end())  // entrance has no corresponding exit
    4674            return;
    47        
    48         endpoint->second->jumpOut(entity);
     75
     76        endpoints->second->jumpOut(entity);
    4977    }
    50 
    51 
    5278}
  • code/branches/presentation/src/modules/portals/PortalLink.h

    r8457 r8605  
     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
    135#ifndef _PortalLink_H__
    236#define _PortalLink_H__
     
    1246namespace orxonox
    1347{
     48    /**
     49        @brief
     50            A PortalLink represents the connection between two @ref orxonox::PortalEndPoint "PortalEndPoints"
     51        @ingroup Portals
     52     */
    1453    class _PortalsExport PortalLink : public BaseObject
    1554    {
     
    3473                return this->toID_;
    3574            }
    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
    3780        protected:
    3881        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
    4687    };
    47 
    4888}
    4989
Note: See TracChangeset for help on using the changeset viewer.