Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 13, 2010, 9:32:08 AM (14 years ago)
Author:
dafrick
Message:

Merged ppspickups1 into trunk.

Location:
code/trunk
Files:
9 edited
2 copied

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/pickup/Pickup.cc

    r6540 r6709  
    3939#include "DroppedPickup.h"
    4040
     41#include "tools/Timer.h"
     42
    4143namespace orxonox
    4244{
    43    
     45
    4446    /*static*/ const std::string Pickup::activationTypeImmediate_s = "immediate";
    4547    /*static*/ const std::string Pickup::activationTypeOnUse_s = "onUse";
    4648    /*static*/ const std::string Pickup::durationTypeOnce_s = "once";
    4749    /*static*/ const std::string Pickup::durationTypeContinuous_s = "continuous";
    48    
     50
    4951    Pickup::Pickup(BaseObject* creator) : BaseObject(creator)
    5052    {
    5153        RegisterObject(Pickup);
    52        
     54
    5355        this->initialize();
    5456    }
    55    
     57
    5658    Pickup::~Pickup()
    5759    {
    58        
    59     }
    60    
     60
     61    }
     62
    6163    /**
    6264    @brief
     
    6870        this->durationType_ = pickupDurationType::once;
    6971    }
    70    
     72
    7173    /**
    7274    @brief
     
    7476    */
    7577    void Pickup::initializeIdentifier(void)
    76     {       
     78    {
    7779        std::string val1 = this->getActivationType();
    7880        std::string type1 = "activationType";
    7981        this->pickupIdentifier_->addParameter(type1, val1);
    80        
     82
    8183        std::string val2 = this->getDurationType();
    8284        std::string type2 = "durationType";
    8385        this->pickupIdentifier_->addParameter(type2, val2);
    8486    }
    85    
     87
    8688    /**
    8789    @brief
     
    9496        XMLPortParam(Pickup, "activationType", setActivationType, getActivationType, xmlelement, mode);
    9597        XMLPortParam(Pickup, "durationType", setDurationType, getDurationType, xmlelement, mode);
    96        
     98
    9799        this->initializeIdentifier();
    98100    }
    99    
     101
    100102    /**
    101103    @brief
     
    116118        }
    117119    }
    118        
     120
    119121    /**
    120122    @brief
     
    135137        }
    136138    }
    137    
     139
    138140    /**
    139141    @brief
     
    157159        }
    158160    }
    159        
     161
    160162    /**
    161163    @brief
     
    179181        }
    180182    }
    181    
     183
    182184    /**
    183185    @brief
     
    188190    {
    189191        SUPER(Pickup, changedPickedUp);
    190        
     192
    191193        //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
    192194        if(this->getCarrier() != NULL && this->isPickedUp() && this->isImmediate())
     
    195197        }
    196198    }
    197    
     199
    198200    /**
    199201    @brief
     
    206208        if(item == NULL)
    207209            item = new Pickup(this);
    208        
     210
    209211        SUPER(Pickup, clone, item);
    210        
     212
    211213        Pickup* pickup = dynamic_cast<Pickup*>(item);
    212214        pickup->setActivationTypeDirect(this->getActivationTypeDirect());
    213215        pickup->setDurationTypeDirect(this->getDurationTypeDirect());
    214        
     216
    215217        pickup->initializeIdentifier();
    216218    }
    217        
     219
    218220    /**
    219221    @brief
     
    231233        return true;
    232234    }
    233    
     235
     236    /**
     237    @brief
     238        Starts the pickup duration timer.
     239        After the specified durationTime has expired the function pickupTimerCallback is called.
     240        pickupTimerCallback can be overloaded and thus the desired functionality can be implemented.
     241    @param durationTime
     242        The duration after which the expires and the callback function is called.
     243    @return
     244        Returns true if the pickup duration timer was started successfully, false if not.
     245    */
     246    bool Pickup::startPickupTimer(float durationTime)
     247    {
     248        if (durationTime<=0)
     249        {
     250            COUT(1) << "Invalid durationTime in pickup." << std::endl;
     251            return false;
     252        }
     253        if (this->durationTimer_.isActive()) //!< Check if Timer is already running
     254        {
     255            COUT(1) << "Pickup durationTimer already in use." << std::endl;
     256            return false;
     257        }
     258        this->durationTimer_.setTimer(durationTime, false, createExecutor(createFunctor(&Pickup::pickupTimerCallback, this)));
     259        return true;
     260    }
    234261}
  • code/trunk/src/modules/pickup/Pickup.h

    r6540 r6709  
    4242#include "interfaces/Pickupable.h"
    4343
     44#include "tools/Timer.h"
     45
    4446namespace orxonox
    4547{
     
    5456        };
    5557    }
    56    
     58
    5759    //! Enum for the duration tyoe.
    5860    namespace pickupDurationType
     
    6466        };
    6567    }
    66    
     68
    6769    /**
    6870    @brief
     
    7476    class _PickupExport Pickup : public Pickupable, public BaseObject
    7577    {
    76        
     78
    7779        protected:
    7880            Pickup(BaseObject* creator); //!< Constructor.
    79        
     81
    8082        public:
    8183            virtual ~Pickup(); //!< Destructor.
    82            
     84
    8385            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
    84            
     86
    8587            /**
    8688            @brief Get the activation type of the pickup.
     
    9597            inline pickupDurationType::Value getDurationTypeDirect(void)
    9698                { return this->durationType_; }
    97            
     99
    98100            const std::string& getActivationType(void); //!< Get the activation type of the pickup.
    99101            const std::string& getDurationType(void); //!< Get the duration type of the pickup.
    100            
     102
    101103            /**
    102104            @brief Get whether the activation type is 'immediate'.
     
    123125            inline bool isContinuous(void)
    124126                { return this->getDurationTypeDirect() == pickupDurationType::continuous; }
    125            
     127
    126128            virtual void changedPickedUp(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around.
    127                                    
     129
    128130            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the Pickup.
    129                
     131
    130132        protected:
    131133            void initializeIdentifier(void);
    132            
     134
    133135            virtual bool createSpawner(void); //!< Facilitates the creation of a PickupSpawner upon dropping of the Pickupable.
    134            
     136
     137            bool startPickupTimer(float durationTime);
     138
     139            virtual void pickupTimerCallback(void) {}
     140
    135141            /**
    136142            @brief Set the activation type of the pickup.
     
    145151            inline void setDurationTypeDirect(pickupDurationType::Value type)
    146152                { this->durationType_ = type; }
    147                
     153
    148154            void setActivationType(const std::string& type); //!< Set the activation type of the pickup.
    149155            void setDurationType(const std::string& type); //!< Set the duration type of the pickup
    150                
     156
    151157        private:
    152158            void initialize(void); //!< Initializes the member variables.
    153159           
     160            //TODO: Problems, when there are more Timers needed? Solutions?
     161            Timer durationTimer_; //!< Timer at the disposal of each Class implementing Pickup.
     162
    154163            pickupActivationType::Value activationType_; //!< The activation type of the Pickup.
    155164            pickupDurationType::Value durationType_; //!< The duration type of the pickup.
    156            
     165
    157166            static const std::string activationTypeImmediate_s;
    158167            static const std::string activationTypeOnUse_s;
    159168            static const std::string durationTypeOnce_s;
    160169            static const std::string durationTypeContinuous_s;
    161        
    162170    };
    163    
     171
    164172}
    165173#endif // _Pickup_H__
  • code/trunk/src/modules/pickup/PickupPrereqs.h

    r6524 r6709  
    7373    class PickupRepresentation;
    7474    class PickupSpawner;
    75    
     75
    7676    //items
    7777    class HealthPickup;
    7878    class MetaPickup;
    79    
     79    class SpeedPickup;
     80
    8081}
    8182
  • code/trunk/src/modules/pickup/items/CMakeLists.txt

    r6524 r6709  
    11ADD_SOURCE_FILES(PICKUP_SRC_FILES
     2
    23  HealthPickup.cc
     4
     5  SpeedPickup.cc
    36  MetaPickup.cc
     7
    48)
  • code/trunk/src/modules/pickup/items/HealthPickup.cc

    • Property svn:eol-style set to native
  • code/trunk/src/modules/pickup/items/HealthPickup.h

    • Property svn:eol-style set to native
  • code/trunk/src/modules/pickup/items/MetaPickup.cc

    • Property svn:eol-style set to native
  • code/trunk/src/modules/pickup/items/MetaPickup.h

    • Property svn:eol-style set to native
Note: See TracChangeset for help on using the changeset viewer.