Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6521


Ignore:
Timestamp:
Mar 15, 2010, 7:33:11 AM (15 years ago)
Author:
dafrick
Message:

Added changedPickedUp method to Pickupable to solve a problem in PickupCollection, which, for the most part, works now.

Location:
code/branches/pickup3/src
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • code/branches/pickup3/src/libraries/core/Super.h

    r6466 r6521  
    277277        SUPER_NOARGS(classname, functionname)
    278278       
     279    #define SUPER_changedPickedUp(classname, functionname, ...) \
     280        SUPER_NOARGS(classname, functionname)
     281       
    279282    // (1/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    280283
     
    537540       
    538541        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(12, changedCarrier, false)
     542            ()
     543        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     544       
     545        SUPER_FUNCTION_GLOBAL_DECLARATION_PART1(13, changedPickedUp, false)
    539546            ()
    540547        SUPER_FUNCTION_GLOBAL_DECLARATION_PART2;
     
    596603    SUPER_INTRUSIVE_DECLARATION(clone);
    597604    SUPER_INTRUSIVE_DECLARATION(changedCarrier);
     605    SUPER_INTRUSIVE_DECLARATION(changedPickedUp);
    598606    // (3/3) --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <-- --> HERE <--
    599607
  • code/branches/pickup3/src/modules/pickup/Pickup.cc

    r6515 r6521  
    182182    @brief
    183183        Should be called when the pickup has transited from picked up to dropped or the other way around.
    184         Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method.
    185     */
    186     void Pickup::changedCarrier(void)
    187     {
    188         SUPER(Pickup, changedCarrier);
     184        Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method.
     185    */
     186    void Pickup::changedPickedUp(void)
     187    {
     188        SUPER(Pickup, changedPickedUp);
    189189       
    190190        //! Sets the Pickup to used if the Pickup has activation type 'immediate' and gets picked up.
  • code/branches/pickup3/src/modules/pickup/Pickup.h

    r6497 r6521  
    117117                { return this->getDurationTypeDirect() == pickupDurationType::continuous; }
    118118           
    119             virtual void changedCarrier(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around.
     119            virtual void changedPickedUp(void); //!< Should be called when the pickup has transited from picked up to dropped or the other way around.
    120120                                   
    121121            virtual void clone(OrxonoxClass*& item); //!< Creates a duplicate of the Pickup.
  • code/branches/pickup3/src/modules/pickup/PickupCollection.cc

    r6519 r6521  
    138138    }
    139139   
    140     //TODO: Steal description from Pickupable.
    141140    void PickupCollection::changedUsed(void)
    142141    {
     
    150149    }
    151150   
    152     void PickupCollection::changedCarrier()
     151    void PickupCollection::changedCarrier(void)
    153152    {
    154153        SUPER(PickupCollection, changedCarrier);
    155154       
     155        //! Change used for all Pickupables this PickupCollection consists of.
     156        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     157        {
     158            (*it)->setCarrier(this->getCarrier());
     159        }
     160    }
     161   
     162    void PickupCollection::changedPickedUp()
     163    {
     164        SUPER(PickupCollection, changedPickedUp);
     165       
    156166        //! Change the carrier for all Pickupables this PickupCollection consists of.
    157167        for(std::vector<Pickupable*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    158168        {
    159             (*it)->setCarrier(this->getCarrier());
    160         }
    161     }
    162    
    163     //TODO: Steal description from Pickupable.
     169            (*it)->setPickedUp(this->isPickedUp());
     170        }
     171    }
     172   
    164173    void PickupCollection::clone(OrxonoxClass*& item)
    165174    {
  • code/branches/pickup3/src/modules/pickup/PickupCollection.h

    r6519 r6521  
    5858
    5959            virtual void changedUsed(void);
    60            
    6160            virtual void changedCarrier(void);
     61            virtual void changedPickedUp(void);
    6262           
    6363            virtual void clone(OrxonoxClass*& item);
  • code/branches/pickup3/src/orxonox/interfaces/PickupCarrier.h

    r6518 r6521  
    4646namespace orxonox
    4747{
    48    
     48
    4949    class Pickup;
    5050    class HealthPickup;
     
    175175            virtual const Vector3& getCarrierPosition(void) = 0;
    176176                           
    177             //TODO: Remove.
     177            /**
     178            @brief Get all Pickupables this PickupCarrier has.
     179            @return  Returns the set of all Pickupables this PickupCarrier has.
     180            */
    178181            std::set<Pickupable*>& getPickups(void)
    179182                { return this->pickups_; }
  • code/branches/pickup3/src/orxonox/interfaces/Pickupable.cc

    r6512 r6521  
    172172       
    173173        COUT(4) << "Pickupable (&" << this << ") got picked up by a PickupCarrier (&" << carrier << ")." << std::endl;
     174        this->setCarrier(carrier);
    174175        this->setPickedUp(true);
    175         this->setCarrier(carrier);
     176        return true;
     177    }
     178   
     179    /**
     180    @brief
     181        Helper method to set the Pickupable to either picked up or not picked up.
     182    @param pickedUp
     183        The value this->pickedUp_ should be set to.
     184    @return
     185        Returns true if the pickedUp status was changed, false if not.
     186    */
     187    bool Pickupable::setPickedUp(bool pickedUp)
     188    {
     189        if(this->pickedUp_ == pickedUp)
     190            return false;
     191       
     192        COUT(4) << "Pickupable (&" << this << ") set to pickedUp " << pickedUp << "." << std::endl;
     193       
     194        this->pickedUp_ = pickedUp;
     195        this->changedPickedUp();
     196        return true;
     197    }
     198       
     199    /**
     200    @brief
     201        Sets the carrier of the pickup.
     202    @param carrier
     203        Sets the input PickupCarrier as the carrier of the pickup.
     204    */
     205    inline bool Pickupable::setCarrier(PickupCarrier* carrier)
     206    {
     207        if(this->carrier_ == carrier)
     208            return false;
     209       
     210        COUT(4) << "Pickupable (&" << this << ") changed Carrier (& " << carrier << ")." << std::endl;
     211       
     212        this->carrier_ = carrier;
     213        this->changedCarrier();
    176214        return true;
    177215    }
     
    205243    }
    206244   
    207        
    208     /**
    209     @brief
    210         Sets the carrier of the pickup.
    211     @param carrier
    212         Sets the input PickupCarrier as the carrier of the pickup.
    213     @return
    214         Returns true if the carrier was changed, false if not.
    215     */
    216     bool Pickupable::setCarrier(PickupCarrier* carrier)
    217     {
    218         if(this->getCarrier() == carrier)
    219             return false;
    220        
    221         this->carrier_ = carrier;
    222         this->changedCarrier();
    223         return true;
    224     }
    225    
    226245    /**
    227246    @brief
     
    230249        Returns the clone of this pickup as a pointer to a Pickupable.
    231250    */
    232     //TODO: Does this work?
    233251    Pickupable* Pickupable::clone(void)
    234252    {
  • code/branches/pickup3/src/orxonox/interfaces/Pickupable.h

    r6519 r6521  
    7070            */
    7171            virtual void changedUsed(void) {}
    72             bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input.
     72           
     73            /**
     74            @brief Get the carrier of the pickup.
     75            @return Returns a pointer to the carrier of the pickup.
     76            */
     77            inline PickupCarrier* getCarrier(void)
     78                { return this->carrier_; }
     79            /**
     80            @brief Should be called when the pickup has changed its PickupCarrier.
     81                   Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method.
     82            */
     83            virtual void changedCarrier(void) {}
    7384           
    7485            /**
     
    7889            inline bool isPickedUp(void)
    7990                { return this->pickedUp_; }
     91            /**
     92            @brief  Should be called when the pickup has transited from picked up to dropped or the other way around.
     93                    Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedPickedUp); to their changedPickedUp method.
     94            */
     95            virtual void changedPickedUp(void) {}   
     96           
    8097            //TODO: Better private, or protected?
    8198            bool pickedUp(PickupCarrier* carrier); //!< Sets the Pickupable to picked up.
     
    86103            bool addTarget(PickupCarrier* target); //!< Add a PickupCarrier as target of this pickup.
    87104            bool addTarget(Identifier* identifier); //!< Add a class, representetd by the input Identifier, as target of this pickup.
    88            
    89             /**
    90             @brief Get the carrier of the pickup.
    91             @return Returns a pointer to the carrier of the pickup.
    92             */
    93             inline PickupCarrier* getCarrier(void)
    94                 { return this->carrier_; }
    95             /**
    96             @brief  Should be called when the pickup has transited from picked up to dropped or the other way around.
    97                     Any Class overwriting this method must call its SUPER function by adding SUPER(Classname, changedCarrier); to their changedCarrier method.
    98             */
    99             virtual void changedCarrier(void) {}
    100             //TODO: Maybe private?
    101             bool setCarrier(PickupCarrier* carrier); //!< Sets the carrier of the pickup.
    102105           
    103106            Pickupable* clone(void); //!< Creates a duplicate of the Pickupable.
     
    113116            virtual void destroy(void)
    114117                { delete this; }
     118               
     119            //TODO: Make them work as protected.
     120            bool setUsed(bool used); //!< Sets the Pickupable to used or unused, depending on the input.
     121            bool setPickedUp(bool pickedUp); //!< Helper method to set the Pickupable to either picked up or not picked up.
     122            bool setCarrier(PickupCarrier* carrier); //!< Sets the carrier of the pickup.
    115123           
    116124        protected:
     
    134142           
    135143        private:
    136             /**
    137             @brief Helper method to set the Pickupable to either picked up or not picked up.
    138             @param pickedUp The value this->pickedUp_ should be set to.
    139             */
    140             inline void setPickedUp(bool pickedUp)
    141                 { this->pickedUp_ = pickedUp; }
    142144           
    143145            bool used_; //!< Whether the pickup is currently in use or not.
     
    151153    SUPER_FUNCTION(10, Pickupable, changedUsed, false);
    152154    SUPER_FUNCTION(12, Pickupable, changedCarrier, false);
     155    SUPER_FUNCTION(13, Pickupable, changedPickedUp, false);
    153156}
    154157
Note: See TracChangeset for help on using the changeset viewer.