Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 8, 2010, 8:53:52 PM (15 years ago)
Author:
dafrick
Message:

Significant structural changes to the pickup module. Lots of bugs found and fixed.
Introduced a new class CollectiblePickup (which is now the only kind a PickupCollection can consist of) to solve some issues cleanly.
MetaPickup received additional functionality. It can now also be set to either destroy all the pickups of a PickupCarrier or destroy the PickupCarrier itself. (This was done mainly for testing purposes)
I've done some extensive testing on the pickups, so they should really work now.

File:
1 edited

Legend:

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

    r7150 r7162  
    7979            PickupCarrier(); //!< Constructor.
    8080            virtual ~PickupCarrier(); //!< Destructor.
     81            void preDestroy(void);
    8182
    8283            /**
     
    138139            virtual const Vector3& getCarrierPosition(void) = 0;
    139140
    140             /**
    141             @brief Get the name of this PickupCarrier.
    142             @return Returns the name as a string.
    143             */
    144             const std::string& getCarrierName(void) { return this->carrierName_; } // tolua_export
    145 
    146141        protected:
    147142            /**
     
    160155
    161156            /**
     157            @brief Get all Pickupables this PickupCarrier has.
     158            @return  Returns the set of all Pickupables this PickupCarrier has.
     159            */
     160            std::set<Pickupable*>& getPickups(void)
     161                { return this->pickups_; }
     162
     163        private:
     164            std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
     165
     166            /**
    162167            @brief Adds a Pickupable to the list of pickups that are carried by this PickupCarrier.
    163168            @param pickup A pointer to the pickup to be added.
     
    165170            */
    166171            bool addPickup(Pickupable* pickup)
    167                 { return this->pickups_.insert(pickup).second; }
     172                {
     173                    COUT(4) << "Adding Pickupable (&" << pickup << ") to PickupCarrier (&" << this << ")" << std::endl;
     174                    return this->pickups_.insert(pickup).second;
     175                }
    168176
    169177            /**
     
    173181            */
    174182            bool removePickup(Pickupable* pickup)
    175                 { return this->pickups_.erase(pickup) == 1; }
    176 
    177             /**
    178             @brief Get all Pickupables this PickupCarrier has.
    179             @return  Returns the set of all Pickupables this PickupCarrier has.
    180             */
    181             std::set<Pickupable*>& getPickups(void)
    182                 { return this->pickups_; }
    183 
    184             /**
    185             @brief Set the name of this PickupCarrier.
    186                    The name needs to be set in the constructor of every class inheriting from PickupCarrier, by calling setCarrierName().
    187             @param name The name to be set.
    188             */
    189             void setCarrierName(const std::string& name)
    190                 { this->carrierName_ = name; }
    191 
    192         private:
    193             std::set<Pickupable*> pickups_; //!< The list of Pickupables carried by this PickupCarrier.
    194             std::string carrierName_; //!< The name of the PickupCarrier, as displayed in the PickupInventory.
    195 
    196             /**
    197             @brief Get the number of carrier children this PickupCarrier has.
    198             @return Returns the number of carrier children.
    199             */
    200             unsigned int getNumCarrierChildren(void)
    201183                {
    202                     std::vector<PickupCarrier*>* list = this->getCarrierChildren();
    203                     unsigned int size = list->size();
    204                     delete list;
    205                     return size;
    206                 }
    207 
    208             /**
    209             @brief Get the index-th child of this PickupCarrier.
    210             @param index The index of the child to return.
    211             @return Returns the index-th child.
    212             */
    213             PickupCarrier* getCarrierChild(unsigned int index)
    214                 {
    215                     std::vector<PickupCarrier*>* list = this->getCarrierChildren();
    216                     if(list->size() < index)
    217                         return NULL;
    218                     PickupCarrier* carrier = (*list)[index];
    219                     delete list;
    220                     return carrier;
    221                 }
    222 
    223             /**
    224             @brief Get the number of Pickupables this PickupCarrier carries.
    225             @return returns the number of pickups.
    226             */
    227             unsigned int getNumPickups(void)
    228                 { return this->pickups_.size(); }
    229 
    230             /**
    231             @brief Get the index-th Pickupable of this PickupCarrier.
    232             @param index The index of the Pickupable to return.
    233             @return Returns the index-th pickup.
    234             */
    235             Pickupable* getPickup(unsigned int index)
    236                 {
    237                     std::set<Pickupable*>::iterator it;
    238                     for(it = this->pickups_.begin(); index != 0 && it != this->pickups_.end(); it++)
    239                         index--;
    240                     if(it == this->pickups_.end())
    241                         return NULL;
    242                     return *it;
     184                    COUT(4) << "Removing Pickupable (&" << pickup << ") from PickupCarrier (&" << this << ")" << std::endl;
     185                    return this->pickups_.erase(pickup) == 1;
    243186                }
    244187
Note: See TracChangeset for help on using the changeset viewer.