Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 24, 2010, 4:59:23 PM (14 years ago)
Author:
dafrick
Message:

Cleaned up in PickupInventory, to be able to improve it at a later stage.

Location:
code/branches/presentation3/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/presentation3/src/modules/pickup/PickupManager.cc

    r6752 r6965  
    6464       
    6565        this->defaultRepresentation_ = new PickupRepresentation();
     66        this->pickupsIndex_ = 0;
    6667       
    6768        COUT(3) << "PickupManager created." << std::endl;
     
    149150        return it->second;
    150151    }
    151    
    152     PickupCarrier* PickupManager::getPawn(void)
    153     {
     152
     153    int PickupManager::getNumPickups(void)
     154    {
     155        this->pickupsList_.clear();
     156        this->pickupsIndex_ = 0;
     157       
    154158        PlayerInfo* player = GUIManager::getInstance().getPlayer(PickupManager::guiName_s);
     159        PickupCarrier* carrier = NULL;
    155160        if (player != NULL)
    156             return dynamic_cast<PickupCarrier*>(player->getControllableEntity());
     161            carrier = dynamic_cast<PickupCarrier*>(player->getControllableEntity());
    157162        else
    158             return NULL;
    159     }
    160    
    161     int PickupManager::getNumCarrierChildren(PickupCarrier* carrier)
    162     {
    163         if(carrier == NULL)
    164163            return 0;
    165         return carrier->getNumCarrierChildren();
    166     }
    167            
    168     PickupCarrier* PickupManager::getCarrierChild(int index, PickupCarrier* carrier)
    169     {
    170         if(carrier == NULL)
    171             return NULL;
    172         return carrier->getCarrierChild(index);
    173     }
    174    
    175     const std::string& PickupManager::getCarrierName(orxonox::PickupCarrier* carrier)
    176     {
    177         if(carrier == NULL)
    178             return BLANKSTRING;
    179         return carrier->getCarrierName();
    180     }
    181    
    182     PickupRepresentation* PickupManager::getPickupRepresentation(int index, PickupCarrier* carrier)
    183     {
    184         Pickupable* pickup = carrier->getPickup(index);
    185         if(pickup == NULL)
    186             return NULL;
    187        
    188         return this->getRepresentation(pickup->getPickupIdentifier());
    189     }
    190    
    191     int PickupManager::getNumPickups(PickupCarrier* carrier)
    192     {
    193         if(carrier == NULL)
    194             return 0;
    195         return carrier->getNumPickups();
    196     }
    197    
    198     void PickupManager::dropPickup(int index, PickupCarrier* carrier)
    199     {
    200         Pickupable* pickup = carrier->getPickup(index);
    201         if(pickup != NULL)
     164
     165        std::vector<PickupCarrier*>* carriers = this->getAllCarriers(carrier);
     166        for(std::vector<PickupCarrier*>::iterator it = carriers->begin(); it != carriers->end(); it++)
     167        {
     168            std::set<Pickupable*> pickups = (*it)->getPickups();
     169            for(std::set<Pickupable*>::iterator pickup = pickups.begin(); pickup != pickups.end(); pickup++)
     170            {
     171                this->pickupsList_.insert(*pickup);
     172            }
     173        }
     174        delete carriers;
     175
     176        this->pickupsIterator_ = this->pickupsList_.begin();
     177        return this->pickupsList_.size();
     178    }
     179
     180    std::vector<PickupCarrier*>* PickupManager::getAllCarriers(PickupCarrier* carrier)
     181    {
     182        //TODO: More efficiently.
     183        std::vector<PickupCarrier*>* carriers = new std::vector<PickupCarrier*>();
     184        carriers->insert(carriers->end(), carrier);
     185        std::vector<PickupCarrier*>* children = carrier->getCarrierChildren();
     186        for(std::vector<PickupCarrier*>::iterator it = children->begin(); it != children->end(); it++)
     187        {
     188            std::vector<PickupCarrier*>* childrensChildren = this->getAllCarriers(*it);
     189            for(std::vector<PickupCarrier*>::iterator it2 = childrensChildren->begin(); it2 != childrensChildren->end(); it2++)
     190            {
     191                carriers->insert(carriers->end(), *it2);
     192            }
     193            delete childrensChildren;
     194        }
     195        delete children;
     196        return carriers;
     197    }
     198
     199    void PickupManager::dropPickup(orxonox::Pickupable* pickup)
     200    {
     201        if(!pickup->isPickedUp())
     202            return;
     203       
     204        PickupCarrier* carrier = pickup->getCarrier();
     205        if(pickup != NULL && carrier != NULL)
    202206            carrier->drop(pickup);
    203207    }
    204    
    205     void PickupManager::usePickup(int index, PickupCarrier* carrier, bool use)
    206     {
    207         Pickupable* pickup = carrier->getPickup(index);
    208         if(pickup != NULL)
     208
     209    void PickupManager::usePickup(orxonox::Pickupable* pickup, bool use)
     210    {
     211        if(!pickup->isPickedUp())
     212            return;
     213
     214        PickupCarrier* carrier = pickup->getCarrier();
     215        if(pickup != NULL && carrier != NULL)
    209216            pickup->setUsed(use);
    210217    }
  • code/branches/presentation3/src/modules/pickup/PickupManager.h

    r6725 r6965  
    7171           
    7272            // tolua_begin
    73             orxonox::PickupCarrier* getPawn(void);
    74            
    75             int getNumCarrierChildren(orxonox::PickupCarrier* carrier);
    76             orxonox::PickupCarrier* getCarrierChild(int index, orxonox::PickupCarrier* carrier);
    77            
    78             const std::string& getCarrierName(orxonox::PickupCarrier* carrier);
    79            
    80             int getNumPickups(orxonox::PickupCarrier* carrier);
    81             PickupRepresentation* getPickupRepresentation(int index, orxonox::PickupCarrier* carrier);
    82             void dropPickup(int index, orxonox::PickupCarrier* carrier);
    83             void usePickup(int index, orxonox::PickupCarrier* carrier, bool use);
     73            int getNumPickups(void);
     74            orxonox::Pickupable* popPickup(void) { this->pickupsIndex_++; return *(this->pickupsIterator_++); }
     75            int getPickupIndex(void) { return this->pickupsIndex_-1; }
     76            orxonox::PickupRepresentation* getPickupRepresentation(orxonox::Pickupable* pickup) { if(pickup != NULL) return this->getRepresentation(pickup->getPickupIdentifier()); return NULL; }
     77
     78            void dropPickup(orxonox::Pickupable* pickup);
     79            void usePickup(orxonox::Pickupable* pickup, bool use);
    8480            // tolua_end
    8581           
     
    9086            PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation.
    9187            std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations.
     88
     89            std::set<Pickupable*> pickupsList_;
     90            std::set<Pickupable*>::iterator pickupsIterator_;
     91            int pickupsIndex_;
     92
     93            std::vector<PickupCarrier*>* getAllCarriers(PickupCarrier* carrier);
    9294       
    9395    }; // tolua_export
  • code/branches/presentation3/src/orxonox/CMakeLists.txt

    r6928 r6965  
    6060    MoodManager.h
    6161    controllers/HumanController.h
    62     interfaces/PickupCarrier.h
     62    interfaces/Pickupable.h
    6363    sound/SoundManager.h
    6464  DEFINE_SYMBOL
  • code/branches/presentation3/src/orxonox/interfaces/PickupCarrier.h

    r6711 r6965  
    4545#include "core/OrxonoxClass.h"
    4646
    47 namespace orxonox // tolua_export
    48 { // tolua_export
     47namespace orxonox
     48{
    4949
    5050    //! Forward-declarations.
     
    6262        Damian 'Mozork' Frick
    6363    */
    64     class _OrxonoxExport PickupCarrier  // tolua_export
    65         : virtual public OrxonoxClass
    66     { // tolua_export
     64    class _OrxonoxExport PickupCarrier : virtual public OrxonoxClass
     65    {
    6766        //! So that the different Pickupables have full access to their PickupCarrier.
    6867        friend class Pickupable;
     
    259258                }
    260259           
    261     }; // tolua_export
    262 } // tolua_export
     260    };
     261}
    263262
    264263#endif /* _PickupCarrier_H__ */
  • code/branches/presentation3/src/orxonox/interfaces/Pickupable.h

    r6901 r6965  
    4242#include "core/OrxonoxClass.h"
    4343
    44 namespace orxonox
    45 {
     44namespace orxonox // tolua_export
     45{ // tolua_export
    4646   
    4747    /**
     
    5151        Damian 'Mozork' Frick
    5252    */
    53     class _OrxonoxExport Pickupable : virtual public OrxonoxClass
    54     {
     53    class _OrxonoxExport Pickupable  // tolua_export
     54        : virtual public OrxonoxClass
     55    {  // tolua_export
    5556        protected:
    5657            Pickupable(); //!< Default constructor.
     
    6364            @return Returns true if the pickup is currently in use.
    6465            */
    65             inline bool isUsed(void)
    66                 { return this->used_; }
     66            inline bool isUsed(void) { return this->used_; }  // tolua_export
    6767            /**
    6868            @brief  Should be called when the pickup has transited from used to unused or the other way around.
     
    8787            @return Returns true if the Pickupable is currently picked up, false if not.
    8888            */
    89             inline bool isPickedUp(void)
    90                 { return this->pickedUp_; }
     89            inline bool isPickedUp(void) { return this->pickedUp_; }  // tolua_export
    9190            /**
    9291            @brief  Should be called when the pickup has transited from picked up to dropped or the other way around.
     
    142141            std::list<Identifier*> targets_; //!< The possible targets of this pickup.
    143142
    144     };
     143    };  // tolua_export
    145144   
    146145    SUPER_FUNCTION(10, Pickupable, changedUsed, false);
    147146    SUPER_FUNCTION(12, Pickupable, changedCarrier, false);
    148147    SUPER_FUNCTION(13, Pickupable, changedPickedUp, false);
    149 }
     148}  // tolua_export
    150149
    151150#endif /* _Pickupable_H__ */
Note: See TracChangeset for help on using the changeset viewer.