Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 5, 2010, 6:26:54 PM (15 years ago)
Author:
dafrick
Message:

Additional documentation, code niceifying and potential bug fixing. Also: Renamed DroppedItem to DroppedPickup.

File:
1 edited

Legend:

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

    r6474 r6475  
    6565            @return Returns true if the Pickupable was picked up, false if not.
    6666            */
    67             inline bool pickup(Pickupable* pickup)
     67            bool pickup(Pickupable* pickup)
    6868                {
    6969                    bool pickedUp = this->pickups_.insert(pickup).second;
     
    7878            @return Returns true if the Pickupable has been dropped, false if not.
    7979            */
    80             inline bool drop(Pickupable* pickup)
     80            bool drop(Pickupable* pickup)
    8181                {
    8282                   bool dropped = this->pickups_.erase(pickup) == 1;
     
    8484                   {
    8585                       pickup->dropped();
    86                         //TODO: Create Spawner.
    8786                   }
    8887                   return dropped;
    8988                }
    9089               
    91             inline bool isTarget(Pickupable* pickup)
     90            /**
     91            @brief Can be used to check whether the PickupCarrier or a child of his is a target ot the input Pickupable.
     92            @param pickup A pointer to the Pickupable.
     93            @return Returns true if the PickupCarrier or one of its children is a target, false if not.
     94            */
     95            //TODO: Use?
     96            bool isTarget(const Pickupable* pickup)
    9297                {
    93                     if(pickup->isTarget(this))
     98                    if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target.
    9499                        return true;
    95                     const std::list<PickupCarrier*>* children = this->getChildren();
     100                   
     101                    //! Go recursively through all children to check whether they are a target.
     102                    std::list<PickupCarrier*>* children = this->getCarrierChildren();
    96103                    for(std::list<PickupCarrier*>::const_iterator it = children->begin(); it != children->end(); it++)
    97104                    {
     
    100107                    }
    101108                   
     109                    children->clear();
     110                    delete children;
     111                   
    102112                    return false;
    103113                }
     114               
     115            /**
     116            @brief Get the carrier that is both a child of the PickupCarrier (or the PickupCarrier itself) and a target of the input Pickupable.
     117            @param pickup A pounter to the Pickupable.
     118            @return Returns a pointer to the PickupCarrier that is the target of the input Pickupable.
     119            */
     120            PickupCarrier* getTarget(const Pickupable* pickup)
     121                {
     122                    if(!this->isTarget(pickup))
     123                        return NULL;
     124                   
     125                    if(pickup->isTarget(this)) //!< If the PickupCarrier itself is a target.
     126                        return this;
     127                   
     128                    //! Go recursively through all children to check whether they are the target.
     129                    std::list<PickupCarrier*>* children = this->getCarrierChildren();
     130                    for(std::list<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
     131                    {
     132                        if(pickup->isTarget(*it))
     133                            return *it;
     134                    }
     135                   
     136                    children->clear();
     137                    delete children;
     138                   
     139                    return NULL;
     140                }
    104141           
    105         protected:           
    106             //TODO: Good return type?
    107             virtual const std::list<PickupCarrier*>* getChildren(void) = 0;
    108             virtual PickupCarrier* getParent(void) = 0;
     142        protected:       
     143            /**
     144            @brief Get all direct children of this PickupSpawner.
     145                   This method needs to be implemented by any direct derivative class of PickupCarrier.
     146            @return Returns a pointer to a list of all direct children.
     147            */
     148            //TODO: Good return type? Maybe not const and destroyed in isTarget...
     149            virtual std::list<PickupCarrier*>* getCarrierChildren(void) = 0;
     150            /**
     151            @brief Get the parent of this PickupSpawner
     152                   This method needs to be implemented by any direct derivative class of PickupCarrier.
     153            @return Returns a pointer to the parent.
     154            */
     155            virtual PickupCarrier* getCarrierParent(void) = 0;
     156            /**
     157            @brief Get the (absolute) position of the PickupCarrier.
     158                   This method needs to be implemented by any direct derivative class of PickupCarrier.
     159            @return Returns the position as a Vector3.
     160            */
     161            virtual const Vector3& getCarrierPosition(void) = 0;
    109162       
    110163        private:
    111             std::set<Pickupable*> pickups_;
     164            std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
    112165           
    113        
    114166    };
    115    
    116167}
    117168
Note: See TracChangeset for help on using the changeset viewer.