Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 28, 2010, 5:31:59 PM (14 years ago)
Author:
dafrick
Message:

Some documenting and cleaning up/re-organization in pickups module.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/interfaces/PickupCarrier.h

    r7456 r7494  
    3838#include "OrxonoxPrereqs.h"
    3939
    40 #include <list>
    4140#include <set>
    42 #include "Pickupable.h"
    43 #include "core/Identifier.h"
    44 #include "core/WeakPtr.h"
     41#include <vector>
    4542
    4643#include "core/OrxonoxClass.h"
     
    4946{
    5047
    51     //! Forward-declarations.
     48    // Forward-declarations.
    5249    class PickupManager;
    5350    class Pickup;
     
    6057    /**
    6158    @brief
    62         The PickupCarrier interface provides the means, for any class implementing it, to possess Pickupables.
     59        The PickupCarrier interface provides the means, for any class implementing it, to possess @ref orxonox::Pickupable "Pickupables".
     60
     61        For a class to use the PickupCarrier interface it must implement the follwing three methods:
     62        - <b>getCarrierPosition()</b> The getCarrierPosition() method returns the absolute position (in space) of the PickupCarrier.
     63
     64        Different PickupCarriers are structured hierarchically, a pickup can be picked up by a PickupCarrier that can't really carry that particular pickup but one of its children (or one of their children) can, and thus it gets "handed down" until it is at the right place.
     65        But this structure has to be established first.
     66        - <b>getCarrierChildren()</b> To this end a PickupCarrier needs to implement getCarrierChildren() which returns a list of its direct PickupCarrier children. If you need an example, have a look at @ref orxonox::Pawn "Pawn" and @ref orxonx::Engine "Engine".
     67        - <b>getCarrierParent()</b> This is the method in the other direction. It returns the parent of this PickupCarrier, or NULL if the PickupCarrier is a root node in this hierarchy.
     68
    6369    @author
    6470        Damian 'Mozork' Frick
     
    6672    class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass
    6773    {
    68         //! So that the different Pickupables have full access to their PickupCarrier.
     74        // So that the different Pickupables have full access to their PickupCarrier.
    6975        friend class Pickupable;
    7076        friend class PickupManager;
    71         //! Friends.
     77        // Friends.
    7278        friend class Pickup;
    7379        friend class HealthPickup;
     
    8086            PickupCarrier(); //!< Constructor.
    8187            virtual ~PickupCarrier(); //!< Destructor.
    82             void preDestroy(void);
     88            void preDestroy(void); //!< Is called before the PickupCarrier is effectively destroyed.
    8389
    84             /**
    85             @brief Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable.
    86             @param pickup A pointer to the Pickupable.
    87             @return Returns true if the PickupCarrier or one of its children is a target, false if not.
    88             */
    89             bool isTarget(const Pickupable* pickup)
    90                 {
    91                     if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target.
    92                         return true;
    93 
    94                     //! Go recursively through all children to check whether they are a target.
    95                     std::vector<PickupCarrier*>* children = this->getCarrierChildren();
    96                     for(std::vector<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++)
    97                     {
    98                         if((*it)->isTarget(pickup))
    99                             return true;
    100                     }
    101 
    102                     children->clear();
    103                     delete children;
    104 
    105                     return false;
    106                 }
    107 
    108             /**
    109             @brief Get the carrier that is both a child of the PickupCarrier (or the PickupCarrier itself) and a target of the input Pickupable.
    110             @param pickup A pounter to the Pickupable.
    111             @return Returns a pointer to the PickupCarrier that is the target of the input Pickupable.
    112             */
    113             PickupCarrier* getTarget(const Pickupable* pickup)
    114                 {
    115                     if(!this->isTarget(pickup))
    116                         return NULL;
    117 
    118                     if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target.
    119                         return this;
    120 
    121                     //! Go recursively through all children to check whether they are the target.
    122                     std::vector<PickupCarrier*>* children = this->getCarrierChildren();
    123                     for(std::vector<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
    124                     {
    125                         if(pickup->isTarget(*it))
    126                             return *it;
    127                     }
    128 
    129                     children->clear();
    130                     delete children;
    131 
    132                     return NULL;
    133                 }
     90            bool isTarget(const Pickupable* pickup); //!< Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable.
     91            PickupCarrier* getTarget(const Pickupable* pickup); //!< Get the carrier that is both a child of the PickupCarrier (or the PickupCarrier itself) and a target of the input Pickupable.
    13492
    13593            /**
     
    149107            virtual std::vector<PickupCarrier*>* getCarrierChildren(void) = 0;
    150108            /**
    151             @brief Get the parent of this PickupSpawner
     109            @brief Get the parent of this PickupSpawner.
    152110                   This method needs to be implemented by any direct derivative class of PickupCarrier.
    153111            @return Returns a pointer to the parent.
     
    165123            std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
    166124
    167             /**
    168             @brief Adds a Pickupable to the list of pickups that are carried by this PickupCarrier.
    169             @param pickup A pointer to the pickup to be added.
    170             @return Returns true if successfull, false if the Pickupable was already present.
    171             */
    172             bool addPickup(Pickupable* pickup)
    173                 {
    174                     COUT(4) << "Adding Pickupable (&" << pickup << ") to PickupCarrier (&" << this << ")" << std::endl;
    175                     return this->pickups_.insert(pickup).second;
    176                 }
    177 
    178             /**
    179             @brief Removes a Pickupable from the list of pickups that are carried by thsi PickupCarrier.
    180             @param pickup A pointer to the pickup to be removed.
    181             @return Returns true if successfull, false if the Pickupable was not present in the list.
    182             */
    183             bool removePickup(Pickupable* pickup)
    184                 {
    185                     COUT(4) << "Removing Pickupable (&" << pickup << ") from PickupCarrier (&" << this << ")" << std::endl;
    186                     return this->pickups_.erase(pickup) == 1;
    187                 }
     125            bool addPickup(Pickupable* pickup); //!< Adds a Pickupable to the list of pickups that are carried by this PickupCarrier.
     126            bool removePickup(Pickupable* pickup); //!< Removes a Pickupable from the list of pickups that are carried by this PickupCarrier.
    188127
    189128    };
Note: See TracChangeset for help on using the changeset viewer.