Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7533


Ignore:
Timestamp:
Oct 13, 2010, 11:35:18 AM (14 years ago)
Author:
dafrick
Message:

Documenting in pickups module.
Cleaning up in PickupManager.
Removed some obsolete functions in HumanController and ControllableEntity, which were remenants of the old pickups module.
Fixed a bug.

Location:
code/trunk
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/data/defaultConfig/keybindings.ini

    r7163 r7533  
    5151KeyKana=
    5252KeyKanji=
    53 KeyL=dropItems
     53KeyL=
    5454KeyLeft="scale -1 moveRightLeft"
    5555KeyLeftAlt=
  • code/trunk/src/modules/pickup/CollectiblePickup.h

    r7494 r7533  
    5050    @author
    5151        Damian 'Mozork' Frick
     52
     53    @ingroup Pickup
    5254    */
    5355    class _PickupExport CollectiblePickup : public Pickupable
  • code/trunk/src/modules/pickup/DroppedPickup.h

    r7493 r7533  
    5151    @author
    5252        Damian 'Mozork' Frick
     53
     54    @ingroup Pickup
    5355    */
    5456    class _PickupExport DroppedPickup : public PickupSpawner
    5557    {
    5658        public:
    57             DroppedPickup(BaseObject* creator); //!< Default constructor.
     59            DroppedPickup(BaseObject* creator);
    5860            DroppedPickup(BaseObject* creator, Pickupable* pickup, PickupCarrier* carrier, float triggerDistance = 10.0); //!< Constructor.
    59             virtual ~DroppedPickup(); //!< Destructor.
     61            virtual ~DroppedPickup();
    6062
    6163        protected:
  • code/trunk/src/modules/pickup/Pickup.cc

    r7494 r7533  
    4444{
    4545
     46    //! Initializing the static strings.
    4647    /*static*/ const std::string Pickup::activationTypeImmediate_s = "immediate";
    4748    /*static*/ const std::string Pickup::activationTypeOnUse_s = "onUse";
  • code/trunk/src/modules/pickup/Pickup.h

    r7494 r7533  
    4848{
    4949
    50     //! Enum for the @ref orxonox::Pickup "Pickup" activation type.
     50    /**
     51    @brief
     52        Enum for the @ref orxonox::Pickup "Pickup" activation type.
     53
     54    @ingroup Pickup
     55    */
    5156    namespace pickupActivationType
    5257    {
     
    5863    }
    5964
    60     //! Enum for the @ref orxonox::Pickup "Pickup" duration type.
     65    /**
     66    @brief
     67        Enum for the @ref orxonox::Pickup "Pickup" duration type.
     68
     69    @ingroup Pickup
     70    */
    6171    namespace pickupDurationType
    6272    {
     
    8494    @author
    8595        Damian 'Mozork' Frick
     96
     97    @ingroup Pickup
    8698    */
    8799    class _PickupExport Pickup : public CollectiblePickup, public BaseObject
  • code/trunk/src/modules/pickup/PickupCollection.cc

    r7494 r7533  
    118118        // Change used for all Pickupables this PickupCollection consists of.
    119119        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    120         {
    121120            (*it)->setUsed(this->isUsed());
    122         }
     121
    123122        this->processingUsed_ = false;
    124123
     
    176175        // Change the pickedUp status for all Pickupables this PickupCollection consists of.
    177176        for(std::vector<CollectiblePickup*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
    178         {
    179177            (*it)->setPickedUp(this->isPickedUp());
    180         }
     178
    181179        this->processingPickedUp_ = false;
    182180
  • code/trunk/src/modules/pickup/PickupCollection.h

    r7494 r7533  
    6565    @author
    6666        Damian 'Mozork' Frick
     67
     68    @ingroup Pickup
    6769    */
    6870    class _PickupExport PickupCollection : public CollectiblePickup, public BaseObject
  • code/trunk/src/modules/pickup/PickupCollectionIdentifier.cc

    r7494 r7533  
    6969        assert(identifier);
    7070
    71         // Slight un-niceity to cast the PickupIdentifier to a PickupCollectionIdentifier.
     71        // Slight un-niceity to cast the const PickupIdentifier to a const PickupCollectionIdentifier, but since we cast to a const, there is no harm done.
    7272        PickupIdentifier* temp = const_cast<PickupIdentifier*>(identifier);
    7373        const PickupCollectionIdentifier* collectionIdentifier = orxonox_cast<PickupCollectionIdentifier*>(temp);
     
    9494        }
    9595
    96         // Means they are equal.
     96        // This means they are equal.
    9797        return 0;
    9898    }
  • code/trunk/src/modules/pickup/PickupCollectionIdentifier.h

    r7494 r7533  
    5151
    5252        @ref orxonox::Pickupable "Pickupables" (resp. @ref orxonox::CollectiblePickup "CollectiblePickups") can be added to the PickupCollectionIdentifier via the addPickup method.
     53
    5354    @author
    5455        Damian 'Mozork' Frick
     56
     57    @ingroup Pickup
    5558    */
    5659    class _PickupExport PickupCollectionIdentifier : public PickupIdentifier
  • code/trunk/src/modules/pickup/PickupManager.cc

    r7531 r7533  
    4242#include "network/Host.h"
    4343#include "network/NetworkFunction.h"
     44
    4445#include "interfaces/PickupCarrier.h"
    4546#include "infos/PlayerInfo.h"
    4647#include "worldentities/pawns/Pawn.h"
     48
    4749#include "CollectiblePickup.h"
    4850#include "PickupRepresentation.h"
     
    5759    ManageScopedSingleton(PickupManager, ScopeID::Root, false);
    5860
     61    // Initialization of the name of the PickupInventory GUI.
    5962    /*static*/ const std::string PickupManager::guiName_s = "PickupInventory";
    6063
     64    // Register static newtork functions that are used to communicate changes to pickups over the network, such that the PickupInventory can display the information about the pickups properly.
    6165    registerStaticNetworkFunction(PickupManager::pickupChangedUsedNetwork);
    6266    registerStaticNetworkFunction(PickupManager::pickupChangedPickedUpNetwork);
     
    6872        Constructor. Registers the PickupManager and creates the default PickupRepresentation.
    6973    */
    70     PickupManager::PickupManager() : guiLoaded_(false), pickupIndex_(0), defaultRepresentation_(NULL)
     74    PickupManager::PickupManager() : guiLoaded_(false), pickupHighestIndex_(0), defaultRepresentation_(NULL)
    7175    {
    7276        RegisterObject(PickupManager);
    7377
     78        //TODO: Only create if isMaster().
    7479        this->defaultRepresentation_ = new PickupRepresentation();
    7580
     
    8085    @brief
    8186        Destructor.
    82         Destroys the default PickupRepresentation.
     87        Destroys the default PickupRepresentation and does some cleanup.
    8388    */
    8489    PickupManager::~PickupManager()
    8590    {
     91        // Destroying the default representation.
    8692        if(this->defaultRepresentation_ != NULL)
    8793            this->defaultRepresentation_->destroy();
    8894
    8995        this->representations_.clear();
    90 
    91         //TODO: Destroy properly...
     96        this->representationsNetworked_.clear();
     97
     98        //TODO: Destroying properly?
     99        //TODO: Shouldnt these list be empty, to avoid problems when switching levels?
     100        // Destroying all the PickupInventoryContainers that are still there.
     101        for(std::map<uint32_t, PickupInventoryContainer*>::iterator it = this->pickupInventoryContainers_.begin(); it != this->pickupInventoryContainers_.end(); it++)
     102            delete it->second;
     103        this->pickupInventoryContainers_.clear();
     104
     105        // Destroying all the WeakPointers that are still there.
     106        for(std::map<uint32_t, WeakPtr<Pickupable>*>::iterator it = this->pickups_.begin(); it != this->pickups_.end(); it++)
     107            delete it->second;
     108        this->pickups_.clear();
     109
     110        this->indexes_.clear();
    92111
    93112        COUT(3) << "PickupManager destroyed." << std::endl;
     
    96115    /**
    97116    @brief
    98         Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
    99         For every type of Pickupable (uniquely idnetified by a PickupIdentifier) there can be one (and just one) PickupRepresentation registered.
     117        Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents, on the server (or in standalone mode).
     118        For every type of Pickupable (uniquely identified by a PickupIdentifier) there can be one (and just one) PickupRepresentation registered.
    100119    @param identifier
    101120        The PickupIdentifier identifying the Pickupable.
     
    110129        assert(representation);
    111130
    112         if(!this->representations_.empty() && this->representations_.find(identifier) != this->representations_.end()) // If the Pickupable already has a Representation registered.
     131        // If the list is not empty and Pickupable already has a Representation registered.
     132        if(!this->representations_.empty() && this->representations_.find(identifier) != this->representations_.end())
    113133            return false;
    114134
     
    119139    }
    120140
    121     bool PickupManager::registerRepresentation(PickupRepresentation* representation)
    122     {
    123         assert(representation);
    124 
    125         if(!this->representationsNetworked_.empty() && this->representationsNetworked_.find(representation->getObjectID()) != this->representationsNetworked_.end()) // If the PickupRepresentation is already registered.
    126             return false;
    127 
    128         this->representationsNetworked_[representation->getObjectID()] = representation;
    129         return true;
    130     }
    131 
    132     /**
    133     @brief
    134         Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
     141    /**
     142    @brief
     143        Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents, on the server (or in standalone mode).
    135144    @param identifier
    136145        The PickupIdentifier identifying the Pickupable.
     
    146155
    147156        std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
    148         if(it == this->representations_.end()) //!< If the Pickupable is not registered in the first place.
     157        if(it == this->representations_.end()) // If the Pickupable is not registered in the first place.
    149158            return false;
    150159
     
    155164    }
    156165
     166    /**
     167    @brief
     168        Registers a PickupRepresentation on the host it was created.
     169    @param representation
     170        A pointer to the PickupRepresentation.
     171    @return
     172        Returns true if successful, false if not.
     173    */
     174    bool PickupManager::registerRepresentation(PickupRepresentation* representation)
     175    {
     176        assert(representation);
     177
     178        // If the list is not empty and PickupRepresentation is already registered.
     179        if(!this->representationsNetworked_.empty() && this->representationsNetworked_.find(representation->getObjectID()) != this->representationsNetworked_.end())
     180            return false;
     181
     182        this->representationsNetworked_[representation->getObjectID()] = representation;
     183        return true;
     184    }
     185
     186    /**
     187    @brief
     188        Unregisters a PickupRepresentation on the host it is being destroyed (which is the same host on which it was created).
     189    @param representation
     190        A pointer to the Pickuprepresentation.
     191    @return
     192        Returns true if successful, false if not.
     193    */
    157194    bool PickupManager::unregisterRepresentation(PickupRepresentation* representation)
    158195    {
     
    160197
    161198        std::map<uint32_t, PickupRepresentation*>::iterator it = this->representationsNetworked_.find(representation->getObjectID());
    162         if(it == this->representationsNetworked_.end()) //!< If the Pickupable is not registered in the first place.
     199        if(it == this->representationsNetworked_.end()) // If the Pickupable is not registered in the first place.
    163200            return false;
    164201
     
    175212        Returns a pointer to the PickupRepresentation.
    176213    */
     214    //TODO: Why not return a const?
    177215    PickupRepresentation* PickupManager::getRepresentation(const PickupIdentifier* identifier)
    178216    {
    179217        std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare>::iterator it = this->representations_.find(identifier);
    180         if(it == this->representations_.end())
     218        if(it == this->representations_.end()) // If there is no PickupRepresentation associated with the input PickupIdentifier.
    181219        {
    182220            COUT(4) << "PickupManager::getRepresentation() returned default representation." << std::endl;
     
    189227    /**
    190228    @brief
    191         Get the PickupRepresentation of an input Pickupable.
    192         This method spares us the hassle to export the PickupIdentifier class to lua.
    193     @param pickup
    194         The Pickupable whose PickupRepresentation should be returned.
    195     @return
    196         Returns the PickupRepresentation of the input Pickupable or NULL if an error occurred.
    197     */
    198     orxonox::PickupRepresentation* PickupManager::getPickupRepresentation(uint64_t pickup)
    199     {
    200         this->representationsNetworked_.clear();
    201         for(ObjectList<PickupRepresentation>::iterator it = ObjectList<PickupRepresentation>::begin(); it != ObjectList<PickupRepresentation>::end(); ++it)
    202             this->representationsNetworked_[it->getObjectID()] = *it;
    203 
    204         std::map<uint64_t, PickupInventoryContainer*>::iterator it = this->pickupInventoryContainers_.find(pickup);
    205         if(it == this->pickupInventoryContainers_.end())
    206             return this->defaultRepresentation_;
    207 
    208         std::map<uint32_t, PickupRepresentation*>::iterator it2 = this->representationsNetworked_.find(it->second->representationObjectId);
    209         if(it2 == this->representationsNetworked_.end())
    210             return this->defaultRepresentation_;
    211 
    212         return it2->second;
    213     }
    214 
    215     /**
    216     @brief
    217         Update the list of picked up Pickupables and get the number of Pickupables in the list.
    218         This method is used in lua to populate the PickupInventory. The intended usage is to call this method to update the list of Pickupables and then use popPickup() to get the individual Pickupables.
    219     @return
    220         Returns the number of the players picked up Pickupables.
    221     */
    222     int PickupManager::getNumPickups(void)
    223     {
    224         this->pickupsIterator_ = this->pickupInventoryContainers_.begin();
    225         return this->pickupInventoryContainers_.size();
    226     }
    227 
    228     /**
    229     @brief
    230         Drop the input Pickupable.
    231         This method checks whether the inout Pickupable still exists and drops it, if so.
    232     @param pickup
    233         The Pickupable to be dropped.
    234     */
    235     void PickupManager::dropPickup(uint64_t pickup)
    236     {
    237         if(GameMode::isMaster() && !this->pickups_.empty())
    238         {
    239             Pickupable* pickupable = this->pickups_.find(pickup)->second->get();
    240             if(pickupable != NULL)
    241                 pickupable->drop();
    242         }
    243         else
    244         {
    245             callStaticNetworkFunction(PickupManager::dropPickupNetworked, 0, pickup);
    246         }
    247     }
    248 
    249     /*static*/ void PickupManager::dropPickupNetworked(uint64_t pickup)
    250     {
    251         if(GameMode::isServer())
    252         {
    253             PickupManager& manager = PickupManager::getInstance();
    254             if(manager.pickups_.empty())
    255                 return;
    256             Pickupable* pickupable = manager.pickups_.find(pickup)->second->get();
    257             if(pickupable != NULL)
    258                 pickupable->drop();
    259         }
    260     }
    261 
    262     /**
    263     @brief
    264         Use (or unuse) the input Pickupable.
    265         This method checks whether the input Pickupable still exists and uses (or unuses) it, if so,
    266     @param pickup
    267         The Pickupable to be used (or unused).
    268     @param use
    269         If true the input Pickupable is used, if false it is unused.
    270     */
    271     void PickupManager::usePickup(uint64_t pickup, bool use)
    272     {
    273         if(GameMode::isMaster() && !this->pickups_.empty())
    274         {
    275             Pickupable* pickupable = this->pickups_.find(pickup)->second->get();
    276             if(pickupable != NULL)
    277                 pickupable->setUsed(use);
    278         }
    279         else
    280         {
    281             callStaticNetworkFunction(PickupManager::usePickupNetworked, 0, pickup, use);
    282         }
    283     }
    284 
    285     /*static*/ void PickupManager::usePickupNetworked(uint64_t pickup, bool use)
    286     {
    287         if(GameMode::isServer())
    288         {
    289             PickupManager& manager = PickupManager::getInstance();
    290             if(manager.pickups_.empty())
    291                 return;
    292             Pickupable* pickupable = manager.pickups_.find(pickup)->second->get();
    293             if(pickupable != NULL)
    294                 pickupable->setUsed(use);
    295         }
    296     }
    297 
    298     /**
    299     @brief
    300         Check whether the input Pickupable is valid, meaning that it is in the PickupManager's list and still exists.
    301     @param pickup
    302         The Pickupable.
    303     @return
    304         Returns true if the input Pickupable is still valid, false if not.
    305     */
    306     bool PickupManager::isValidPickup(uint64_t pickup)
    307     {
    308         return this->pickups_.find(pickup) != this->pickups_.end();
    309     }
    310 
     229        Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input used state.
     230    @param pickup
     231        The Pickupable whose used status changed.
     232    @param used
     233        The used status the Pickupable changed to.
     234    */
    311235    void PickupManager::pickupChangedUsed(Pickupable* pickup, bool used)
    312236    {
     
    317241
    318242        CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(pickup);
    319         // If the Picupable is part of a PickupCollection it isn't displayed in the PickupInventory, just the PickupCollection is.
     243        // If the Pickupable is part of a PickupCollection it isn't displayed in the PickupInventory, just the PickupCollection is.
    320244        if(collectible != NULL && collectible->isInCollection())
    321245            return;
    322246
     247        // Getting clientId of the host this change of the pickup's used status concerns.
    323248        PickupCarrier* carrier = pickup->getCarrier();
    324249        while(carrier->getCarrierParent() != NULL)
     
    332257        unsigned int clientId = info->getClientID();
    333258
    334         std::map<Pickupable*, uint64_t>::iterator it = this->indexes_.find(pickup);
     259        // Get the number identifying the pickup.
     260        std::map<Pickupable*, uint32_t>::iterator it = this->indexes_.find(pickup);
    335261        assert(it != this->indexes_.end());
    336 
    337         uint64_t index = it->second;
     262        uint32_t index = it->second;
     263
     264        // If we're either in standalone mode or this is the host whom the change of the pickup's status concerns.
    338265        if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
    339266        {
    340267            PickupManager::pickupChangedUsedNetwork(index, used, pickup->isUsable(), pickup->isUnusable());
    341268        }
     269        // If the concerned host is somewhere in the network, we call pickupChangedUsedNetwork() on its PickupManager.
    342270        else
    343271        {
     
    346274    }
    347275
    348     /*static*/ void PickupManager::pickupChangedUsedNetwork(uint64_t pickup, bool inUse, bool usable, bool unusable)
    349     {
    350         PickupManager& manager = PickupManager::getInstance();
     276    /**
     277    @brief
     278        Helper method to react to the change in the used status of a Pickupable.
     279        Static method that is used by the server to inform the client it concerns about the status change.
     280        The parameters that are given are used to update the information (i.e. the PickupInventoryContainer) the concerning PickupManager has about the Pickupable that changed.
     281    @param pickup
     282        A number identifying the Pickupable that changed its used status.
     283    @param inUse
     284        The used status the Pickupable changed to. (i.e. whether the Pickupable is in use or not).
     285    @param usable
     286        Whether the Pickupable's used status can be changed used in the PickupInventory.
     287    @param unusable
     288        Whether the Pickupable's used status can be changed to unused in the PickupInventory.
     289    */
     290    /*static*/ void PickupManager::pickupChangedUsedNetwork(uint32_t pickup, bool inUse, bool usable, bool unusable)
     291    {
     292        PickupManager& manager = PickupManager::getInstance(); // Get the PickupManager singleton on this host.
     293        // If the input Pickupable (i.e its identifier) is not present in the list the PickupManager has.
    351294        if(manager.pickupInventoryContainers_.find(pickup) == manager.pickupInventoryContainers_.end())
    352295        {
     
    355298        }
    356299
     300        // Update the Pickupable's container with the information transferred.
    357301        manager.pickupInventoryContainers_[pickup]->inUse = inUse;
    358302        manager.pickupInventoryContainers_[pickup]->usable = usable;
    359303        manager.pickupInventoryContainers_[pickup]->unusable = unusable;
    360304
    361         manager.updateGUI();
    362     }
    363 
     305        manager.updateGUI(); // Tell the PickupInventory that something has changed.
     306    }
     307
     308    /**
     309    @brief
     310        Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state.
     311    @param pickup
     312        The Pickupable whose pickedUp status changed.
     313    @param pickedUp
     314        The pickedUp status the Pickupable changed to.
     315    */
    364316    void PickupManager::pickupChangedPickedUp(Pickupable* pickup, bool pickedUp)
    365317    {
    366318        assert(pickup);
    367319
    368         if(!GameMode::isMaster())
     320        if(!GameMode::isMaster()) // If this is neither standalone nor the server.
    369321            return;
    370322
    371323        CollectiblePickup* collectible = orxonox_cast<CollectiblePickup*>(pickup);
    372         // If the Picupable is part of a PickupCollection it isn't displayed in the PickupInventory, just the PickupCollection is.
     324        // If the Pickupable is part of a PickupCollection it isn't displayed in the PickupInventory, just the PickupCollection is.
    373325        if(collectible != NULL && collectible->isInCollection())
    374326            return;
    375327
     328        // Getting clientId of the host this change of the pickup's pickedUp status concerns.
    376329        PickupCarrier* carrier = pickup->getCarrier();
    377330        while(carrier->getCarrierParent() != NULL)
     
    380333        if(pawn == NULL)
    381334            return;
    382         PlayerInfo* info = pawn->getPlayer();
     335        PlayerInfo* info = pawn->getFormerPlayer();
    383336        if(info == NULL)
    384337            return;
    385338        unsigned int clientId = info->getClientID();
    386339
    387         uint64_t index = 0;
    388         if(pickedUp)
    389         {
    390             index = this->getPickupIndex();
     340        uint32_t index = 0;
     341        if(pickedUp) // If the Pickupable has changed to picked up, it is added to the required lists.
     342        {
     343            index = this->getPickupIndex(); // Ge a new identifier (index) for the Pickupable.
     344            // Add the Pickupable to the indexes_ and pickups_ lists.
    391345            this->indexes_[pickup] = index;
    392346            this->pickups_[index] = new WeakPtr<Pickupable>(pickup);
    393347        }
    394         else
    395         {
    396             std::map<Pickupable*, uint64_t>::iterator it = this->indexes_.find(pickup);
     348        else // If it was dropped, it is removed from the required lists.
     349        {
     350            // Get the indentifier (index) that identifies the input Pickupable.
     351            std::map<Pickupable*, uint32_t>::iterator it = this->indexes_.find(pickup);
    397352            index = it->second;
     353
     354            // Remove the Pickupable form the indexes_ and pickups_ list.
    398355            WeakPtr<Pickupable>* ptr = this->pickups_[index];
    399356            this->indexes_.erase(it);
     
    402359        }
    403360
     361        // If we're either in standalone mode or this is the host whom the change of the pickup's status concerns.
     362        //TODO: Needs to be added to server even if is was not picked up by it?
    404363        if(GameMode::isStandalone() || Host::getPlayerID() == clientId)
    405364        {
     365            // If there is no PickupRepresentation registered the default representation is used.
    406366            if(this->representations_.find(pickup->getPickupIdentifier()) == this->representations_.end())
    407367                PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->defaultRepresentation_->getObjectID(), pickedUp);
     
    409369                PickupManager::pickupChangedPickedUpNetwork(index, pickup->isUsable(), this->representations_[pickup->getPickupIdentifier()]->getObjectID(), pickedUp);
    410370        }
     371        // If the concerned host is somewhere in the network, we call pickupChangedPickedUpNetwork() on its PickupManager.
    411372        else
    412373        {
     374            // If there is no PickupRepresentation registered the default representation is used.
    413375            if(this->representations_.find(pickup->getPickupIdentifier()) == this->representations_.end())
    414376            {
     
    423385    }
    424386
    425     /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint64_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp)
    426     {
    427         PickupManager& manager = PickupManager::getInstance();
     387    /**
     388    @brief
     389        Helper method to react to the change in the pickedUp status of a Pickupable.
     390        Static method that is used by the server to inform the client it concerns about the status change.
     391        The parameters that are given are used to update the information (i.e. the PickupInventoryContainer) the concerning PickupManager has about the Pickupable that changed.
     392    @param pickup
     393        A number identifying the Pickupable that changed its pickedUp status.
     394    @param unusable
     395        Whether the Pickupable's used status can be changed to unused in the PickupInventory.
     396    @param representationObjectId
     397        The objectId identifying (over the network) the PickupRepresentation that represents this Pickupable.
     398    @param pickedUp
     399        The pickedUp status the Pickupable changed to.
     400    */
     401    /*static*/ void PickupManager::pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp)
     402    {
     403        PickupManager& manager = PickupManager::getInstance(); // Get the PickupManager singleton on this host.
     404        // If the Pickupable has been picked up, we create a new PickupInventoryContainer for it.
    428405        if(pickedUp)
    429406        {
     407            // Create a new PickupInventoryContainer for the Pickupable and set all the necessary information.
    430408            PickupInventoryContainer* container = new PickupInventoryContainer;
    431409            container->pickup = pickup;
     
    435413            container->unusable = false;
    436414            container->representationObjectId = representationObjectId;
    437             manager.pickupInventoryContainers_.insert(std::pair<uint64_t, PickupInventoryContainer*>(pickup, container));
    438 
    439             if(GameMode::showsGraphics())
    440             {
    441                 if(!manager.guiLoaded_)
    442                 {
    443                     GUIManager::getInstance().loadGUI(PickupManager::guiName_s);
    444                     manager.guiLoaded_ = true;
    445                 }
    446                 GUIManager::getInstance().getLuaState()->doString(PickupManager::guiName_s + ".update()");
    447             }
    448         }
     415            // Insert the container into the pickupInventoryContainers_ list.
     416            manager.pickupInventoryContainers_.insert(std::pair<uint32_t, PickupInventoryContainer*>(pickup, container));
     417
     418            manager.updateGUI(); // Tell the PickupInventory that something has changed.
     419        }
     420        // If the Pickupable has been dropped, we remove it from the pickupInventoryContainers_ list.
    449421        else
    450422        {
    451             std::map<uint64_t, PickupInventoryContainer*>::iterator it = manager.pickupInventoryContainers_.find(pickup);
     423            std::map<uint32_t, PickupInventoryContainer*>::iterator it = manager.pickupInventoryContainers_.find(pickup);
    452424            if(it != manager.pickupInventoryContainers_.end())
    453425                delete it->second;
    454426            manager.pickupInventoryContainers_.erase(pickup);
    455427
    456             manager.updateGUI();
    457         }
    458     }
    459 
     428            manager.updateGUI(); // Tell the PickupInventory that something has changed.
     429        }
     430    }
     431
     432    /**
     433    @brief
     434        Get the PickupRepresentation of an input Pickupable.
     435        This method spares us the hassle to export the PickupIdentifier class to lua.
     436    @param pickup
     437        The number identifying the Pickupable whose PickupRepresentation should be returned.
     438    @return
     439        Returns the PickupRepresentation of the input Pickupable or NULL if an error occurred.
     440    */
     441    orxonox::PickupRepresentation* PickupManager::getPickupRepresentation(uint32_t pickup)
     442    {
     443        // Clear and rebuild the representationsNetworked_ list.
     444        //TODO: Better solution?
     445        this->representationsNetworked_.clear();
     446        for(ObjectList<PickupRepresentation>::iterator it = ObjectList<PickupRepresentation>::begin(); it != ObjectList<PickupRepresentation>::end(); ++it)
     447            this->representationsNetworked_[it->getObjectID()] = *it;
     448
     449        // Get the container belonging to the input pickup, if not found return the default representation.
     450        std::map<uint32_t, PickupInventoryContainer*>::iterator it = this->pickupInventoryContainers_.find(pickup);
     451        if(it == this->pickupInventoryContainers_.end())
     452            return this->defaultRepresentation_;
     453
     454        // Get the PickupRepresentation of the input pickup (through the objecId of the representation stored in the PickupInventoryContainer belonging to the pickup), if not found return the default representation.
     455        std::map<uint32_t, PickupRepresentation*>::iterator it2 = this->representationsNetworked_.find(it->second->representationObjectId);
     456        if(it2 == this->representationsNetworked_.end())
     457            return this->defaultRepresentation_;
     458
     459        return it2->second;
     460    }
     461
     462    /**
     463    @brief
     464        Get the number of pickups currently picked up by the player.
     465        This method is used in lua to populate the PickupInventory. The intended usage is to call this method to reset the iterator of the list of PickupInventoryContainers and then use popPickup() to get the individual PickupInventoryContainers.
     466    @return
     467        Returns the number of the players picked up Pickupables.
     468    */
     469    int PickupManager::getNumPickups(void)
     470    {
     471        this->pickupsIterator_ = this->pickupInventoryContainers_.begin(); // Reset iterator.
     472
     473        return this->pickupInventoryContainers_.size();
     474    }
     475
     476    /**
     477    @brief
     478        Drop the input Pickupable.
     479        This method checks whether the input Pickupable still exists and drops it, if so.
     480    @param pickup
     481        The identifier of the Pickupable to be dropped.
     482    */
     483    void PickupManager::dropPickup(uint32_t pickup)
     484    {
     485        // If we're either server or standalone and the list of pickups is not empty, we find and drop the input pickup.
     486        if(GameMode::isMaster() && !this->pickups_.empty())
     487        {
     488            Pickupable* pickupable = this->pickups_.find(pickup)->second->get();
     489            if(pickupable != NULL)
     490                pickupable->drop();
     491        }
     492        // If we're neither server nor standalone we drop the pickup by calling dropPickupNetworked() of the PickupManager on the server.
     493        else
     494        {
     495            callStaticNetworkFunction(PickupManager::dropPickupNetworked, 0, pickup);
     496        }
     497    }
     498
     499    /**
     500    @brief
     501        Helper method to drop the input pickup on the server.
     502        Static method that is used by clients to instruct the server to drop the input pickup.
     503    @param pickup
     504        The identifier of the Pickupable to be dropped.
     505    */
     506    /*static*/ void PickupManager::dropPickupNetworked(uint32_t pickup)
     507    {
     508        if(GameMode::isServer()) // Obviously we only want to do this on the server.
     509        {
     510            PickupManager& manager = PickupManager::getInstance();
     511            //TODO: Just call dropPickup() on manager?
     512            if(manager.pickups_.empty())
     513                return;
     514            Pickupable* pickupable = manager.pickups_.find(pickup)->second->get();
     515            if(pickupable != NULL)
     516                pickupable->drop();
     517        }
     518    }
     519
     520    /**
     521    @brief
     522        Use (or unuse) the input Pickupable.
     523        This method checks whether the input Pickupable still exists and uses (or unuses) it, if so,
     524    @param pickup
     525        The identifier of the Pickupable to be used (or unused).
     526    @param use
     527        If true the input Pickupable is used, if false it is unused.
     528    */
     529    void PickupManager::usePickup(uint32_t pickup, bool use)
     530    {
     531        // If we're either server or standalone and the list of pickups is not empty, we find and change the used status of the input pickup.
     532        if(GameMode::isMaster() && !this->pickups_.empty())
     533        {
     534            Pickupable* pickupable = this->pickups_.find(pickup)->second->get();
     535            if(pickupable != NULL)
     536                pickupable->setUsed(use);
     537        }
     538        // If we're neither server nor standalone we change the used status of the pickup by calling usePickupNetworked() of the PickupManager on the server.
     539        else
     540        {
     541            callStaticNetworkFunction(PickupManager::usePickupNetworked, 0, pickup, use);
     542        }
     543    }
     544
     545    /**
     546    @brief
     547        Helper method to use (or unuse) the input Pickupable on the server.
     548        Static method that is used by clients to instruct the server to use (or unuse) the input pickup.
     549    @param pickup
     550        The identifier of the Pickupable to be used (or unused).
     551    @param use
     552        If true the input Pickupable is used, if false it is unused.
     553    */
     554    /*static*/ void PickupManager::usePickupNetworked(uint32_t pickup, bool use)
     555    {
     556        if(GameMode::isServer())
     557        {
     558            PickupManager& manager = PickupManager::getInstance();
     559            //TODO: Just call usePickup() on manager?
     560            if(manager.pickups_.empty())
     561                return;
     562            Pickupable* pickupable = manager.pickups_.find(pickup)->second->get();
     563            if(pickupable != NULL)
     564                pickupable->setUsed(use);
     565        }
     566    }
     567
     568    /**
     569    @brief
     570        Updates the PickupInventory GUI.
     571        Also loads the PickupInventory GUI if is hasn't been done already.
     572    */
    460573    inline void PickupManager::updateGUI(void)
    461574    {
     575        // We only need to update (and load) the GUI if this host shows graphics.
    462576        if(GameMode::showsGraphics())
    463577        {
    464             if(!this->guiLoaded_)
     578            if(!this->guiLoaded_) // If the GUI hasn't been loaded, yet, we load it.
    465579            {
    466580                GUIManager::getInstance().loadGUI(PickupManager::guiName_s);
    467581                this->guiLoaded_ = true;
    468582            }
     583
     584            // Update the GUI.
    469585            GUIManager::getInstance().getLuaState()->doString(PickupManager::guiName_s + ".update()");
    470586        }
    471587    }
    472588
    473     uint64_t PickupManager::getPickupIndex(void)
    474     {
    475         if(this->pickupIndex_ == uint64_t(~0x0)-1)
    476             this->pickupIndex_ = 0;
    477         return this->pickupIndex_++;
     589    /**
     590    @brief
     591        Get a new index for a Pickupable.
     592        This will work as long as the number of Pickupables that are picked up is sufficiently small and as long as they don't exist forever.
     593    @return
     594        Returns the new index.
     595    */
     596    uint32_t PickupManager::getPickupIndex(void)
     597    {
     598        if(this->pickupHighestIndex_ == uint32_t(~0x0)-1) // If we've reached the highest possible number, we wrap around.
     599            this->pickupHighestIndex_ = 0;
     600        return this->pickupHighestIndex_++;
    478601    }
    479602
  • code/trunk/src/modules/pickup/PickupManager.h

    r7504 r7533  
    5353
    5454    // tolua_begin
     55    /**
     56    @brief
     57        Data structure to store collected data for one specific @ref orxonox::Pickupable "Pickupable".
     58        This is used to not have to synchronise @ref orxonox::Pickupable "Pickupable" just to have the needed information for the PickupInventory available on all clients. Instead the information is sent over the network and stored in a PickupInventoryContainer.
     59
     60    @ingroup Pickup
     61    */
    5562    struct PickupInventoryContainer
    5663    {
    57         uint64_t pickup;
    58         bool inUse;
    59         bool pickedUp;
    60         bool usable;
    61         bool unusable;
    62         uint32_t representationObjectId;
     64        uint32_t pickup; //!< An indentifier for the @ref orxonox::Pickupable "Pickupable" that is associated with the information stored here.
     65        bool inUse; //!< Whether the @ref orxonox::Pickupable "Pickupable" is currently in use.
     66        bool pickedUp; //!< Whether the @ref orxonox::Pickupable "Pickupable" is currently picked up.
     67        bool usable; //!< Whether the @ref orxonox::Pickupable "Pickupable" is usable.
     68        bool unusable; //!< Whether the @ref orxonox::Pickupable "Pickupable" is droppable.
     69        uint32_t representationObjectId; //!< The objectId of the @ref orxonox::PickupRepresentation "PickupRepresentation" that represents the @ref orxonox::Pickupable "Pickupable".
    6370    };
    6471    // tolua_end
     
    6673    /**
    6774    @brief
    68         Manages Pickupables.
    69         In essence has two tasks to fulfill. Firstly it must link Pickupables (through their PickupIdentifiers) and their PickupRepresentations. Secondly it manages the PickupInventory.
     75        The PickupManager class manages @ref orxonox::Pickupable "Pickupables".
     76
     77        It has in essence two tasks to fulfill. Firstly it must link @ref orxonox::Pickupable "Pickupables" (through their @ref orxonox::PickupIdentifier "PickupIdentifiers") to their respective @ref orxonox:PickupRepresentation "PickupRepresentations". Secondly it manages the PickupInventory. (The PickupInventory is the GUI that displays @ref roxonox::Pickupable "Pickupables" for the covenience of the user.)
     78
     79        @section PickupManagerTechnicalDetails Technical details
     80        Unfortunately <em>under the hood</em> it isn't just as easy. At least the PickupInventory part isn't. To grasp why this is we need to have a brief look at how the pickups module works over the network:
     81
     82        The pickups module essentially just exists on the @ref orxonox::Server "Server", since it's all game logic. That means, a @ref orxonox::PickupSpawner "PickupSpawner" is always triggered on the server, the @ref orxonox::Pickupable "Pickupable" is then picked up (and maybe used already) on the server. The effects the pickup has are synchronised over the network, if they have to be, but this is the responsibility of the entities that are affected, not the pickups module, and normally this is already implemented. The only two things that need to be communicated over the network are the graphical component of the @ref orxonox::PickupSpawner "PickupSpawner", since it needs to be displayed on the @ref orxonox::Client "Clients" as well, and anything that is needed for the PickupInventory, since it exists for each @ref orxonox::Host "Host" seperatly.
     83
     84        Fortunately synchronising the @ref orxonox::PickupSpawner "PickupSpawner" is already being taken care of by the synchronisation of the @ref orxonox::StaticEntity "StaticEntity" (or parents thereof).
     85
     86        This leaves us with the PickupInventory component (and this is really the source of all the complexity).
     87
     88        Firstly there are a number of lists (where by list I really mean any kind of ordered data structure) kept.
     89        - The @ref orxonox::PickupManager::representations_ "representations_" list links @ref orxonox::PickupRepresentation "PickupRepresentations" with @ref orxonox::PickupIdentifier "PickupIdentifiers" and can be used to get the @ref orxonox::PickupRepresentation "PickupRepresentation" for a given @ref orxonox::Pickupable "Pickupable". It is only populated on the server (or in standalone mode). Each @ref orxonox::PickupRepresentation "PickupRepresentation" that is generated through XML registers itself with the PickupManager and is thereby added to the list.
     90        - The @ref orxonox::PickupManager::representationsNetworked_ "representationsNetworked_" list is the networked (hence the name) equivalent to the @ref orxonox::PickupManager::representations_ "representations_" list. It links an objectId of a @ref orxonox::PickupRepresentation "PickupRepresentation" to a @ref orxonox::PickupRepresentation "PickupRepresentation". This list is maintained on all hosts, each representation registers itself (in its constructor) with the PickupManager. Since the representations are synchronised they are created on each host. The "same" instance on each host is identified by the same objectId and that is why we store the representations with the objectId as key. We can then use this list to get a @ref orxonox::PickupRepresentation "PickupRepresentation" for a specific @ref orxonox::Pickupable "Pickupable" (or more precisely a number identifiying that particular pickup, but we'll see that, when we look at the next list) on a client to be used in the PickupInventory.
     91        - The @ref orxonox::PickupManager::pickupInventoryContainers_ "pickupInventoryContainers_" list links a number identifying a @ref orxonox::Pickupable "Pickupable" to a data structure (the @ref orxonox::PickupInventoryContainer "PickupInventoryContainer"), which contains all necessary information about that @ref orxonox::Pickupable "Pickupable". This list is maintained on all hosts, a new container is inserted when a @ref orxonox::Pickupable "Pickupable" is picked up, but only if it has been picked up by the repsective host. This list is then used by the PickupInventory to access the required information and to get the correct @ref orxonox:.PickupRepresentation "PickupRepresentation".
     92        - The @ref orxonox::PickupManager::pickups_ "pickups_" list links a number identifiying a @ref orxonox::Pickupable "Pickupable" to a (weak pointer to a) @ref orxonox::Pickupable "Pickupable". It is only maintained by the server (or in standalone mode), to be able to use, unuse and drop @ref orxonox::Pickupable "Pickupables" through the PickupInventory. Since @ref orxonox::Pickupable "Pickupables" only exist on the server a client that wants to change a pickups status has so send a request over the network (with the number identifying the pickup) to the server and then the server facilitates the change, using this list to map from the identifyer to the actual @ref orxonox::Pickupable "Pickupable".
     93        - The @ref orxonox::PickupManager::indexes_ "indexes_" list links a @ref orxonox::Pickupable "Pickupable" to the number identifying it. This is only maintained on the server (or in standalone mode), and is used for the inverse mapping of the previous list, which means the server uses it identify pickups on clients when it communicates changes in pickups to clients.
     94
     95        There is communication in both directions. From server to client, when the server informs the client that the state of some @ref orxonox::Pickupable "Pickupable" has changed, during which all necessary information to create or update the PickupInventoryContainer for that pickup on the client is sent as well. Or from client to server, when the client wants the server to change the state of some @ref orxonox::Pickupable "Pickupable".
     96
    7097    @author
    7198        Damian 'Mozork' Frick
     99
     100    @ingroup Pickup
    72101    */
    73102    class _PickupExport PickupManager // tolua_export
     
    77106
    78107        public:
    79             PickupManager();
    80             virtual ~PickupManager();
     108            PickupManager(); //!< Constructor.
     109            virtual ~PickupManager(); //!< Destructor.
    81110
     111            /**
     112            @brief Get the instance of the PickupManager singleton.
     113            @return Returns the instance of the PickupManager singleton.
     114            */
    82115            static PickupManager& getInstance() { return Singleton<PickupManager>::getInstance(); } // tolua_export
    83116
    84117            bool registerRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Registers a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
    85             bool registerRepresentation(PickupRepresentation* representation);
    86118            bool unregisterRepresentation(const PickupIdentifier* identifier, PickupRepresentation* representation); //!< Unegisters a PickupRepresentation together with the PickupIdentifier of the Pickupable the PickupRepresentation represents.
    87             bool unregisterRepresentation(PickupRepresentation* representation);
     119
     120            bool registerRepresentation(PickupRepresentation* representation); //!< Registers a PickupRepresentation on the host it was created.
     121            bool unregisterRepresentation(PickupRepresentation* representation); //!< Unregisters a PickupRepresentation on the host it is being destroyed.
     122
    88123            PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
    89124
     125            virtual void pickupChangedUsed(Pickupable* pickup, bool used); //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input used state.
     126            static void pickupChangedUsedNetwork(uint32_t pickup, bool inUse, bool usable, bool unusable); //!< Helper method to react to the change in the used status of a Pickupable.
     127            virtual void pickupChangedPickedUp(Pickupable* pickup, bool pickedUp); //!< Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state.
     128            static void pickupChangedPickedUpNetwork(uint32_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp); //!< Helper method to react to the change in the pickedUp status of a Pickupable.
     129
     130        // Methods to be used by the PickupInventory.
     131        public:
    90132            // tolua_begin
    91             orxonox::PickupRepresentation* getPickupRepresentation(uint64_t pickup); //!< Get the PickupRepresentation of an input Pickupable.
     133            orxonox::PickupRepresentation* getPickupRepresentation(uint32_t pickup); //!< Get the PickupRepresentation of an input indentifier for Pickupable.
    92134
    93             int getNumPickups(void); //!< Update the list of picked up Pickupables and get the number of Pickupables in the list.
     135            int getNumPickups(void); //!< Get the number of pickups currently picked up by the player.
    94136            /**
    95             @brief Get the next Pickupable in the list.
    96                    Use this, after having called getNumPickups() to access all the Pickupables individually and in succession.
    97             @return Returns the next Pickupable in the list.
     137            @brief Get the next PickupInventoryContainer in the list.
     138                   Use this, after having called getNumPickups() to access all the PickupInventoryContainers individually and in succession.
     139            @return Returns the next PickupInventoryContainer in the list.
    98140            */
    99             orxonox::PickupInventoryContainer* popPickup(void) { return (this->pickupsIterator_++)->second; }
     141            orxonox::PickupInventoryContainer* popPickup(void)
     142                { return (this->pickupsIterator_++)->second; }
    100143
    101             void dropPickup(uint64_t pickup); //!< Drop the input Pickupable.
    102             void usePickup(uint64_t pickup, bool use); //!< Use (or unuse) the input Pickupable.
    103             bool isValidPickup(uint64_t pickup); //!< Check whether the input Pickupable is valid, meaning that it is in the PickupManager's list and still exists.
     144            void dropPickup(uint32_t pickup); //!< Drop the input Pickupable.
     145            void usePickup(uint32_t pickup, bool use); //!< Use (or unuse) the input Pickupable.
     146             /**
     147            @brief Check whether the input Pickupable is valid, meaning that it is in the PickupManager's list and still exists.
     148            @param pickup The Pickupable.
     149            @return Returns true if the input Pickupable is still valid, false if not.
     150            */
     151            bool isValidPickup(uint32_t pickup)
     152                { return this->pickups_.find(pickup) != this->pickups_.end(); }
    104153            // tolua_end
    105154
    106             static void dropPickupNetworked(uint64_t pickup);
    107             static void usePickupNetworked(uint64_t pickup, bool use);
    108 
    109             virtual void pickupChangedUsed(Pickupable* pickup, bool used);
    110             static void pickupChangedUsedNetwork(uint64_t pickup, bool inUse, bool usable, bool unusable);
    111             virtual void pickupChangedPickedUp(Pickupable* pickup, bool pickedUp);
    112             static void pickupChangedPickedUpNetwork(uint64_t pickup, bool usable, uint32_t representationObjectId, bool pickedUp);
     155            static void dropPickupNetworked(uint32_t pickup); //!< Helper method to drop the input pickup on the server.
     156            static void usePickupNetworked(uint32_t pickup, bool use); //!< Helper method to use (or unuse) the input Pickupable on the server.
    113157
    114158        private:
    115159            static PickupManager* singletonPtr_s;
    116160            static const std::string guiName_s; //!< The name of the PickupInventory
    117             bool guiLoaded_;
    118             uint64_t pickupIndex_;
     161            bool guiLoaded_; //!< Whether the PickupInventory GUI has been loaded, yet.
     162            uint32_t pickupHighestIndex_; //!< The highest pickup index currently in use. (not taking wrap-around into account)
    119163
    120164            PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation.
    121             std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations.
    122             std::map<uint32_t, PickupRepresentation*> representationsNetworked_;
    123165
    124             std::map<uint64_t, PickupInventoryContainer*> pickupInventoryContainers_;
    125             std::map<uint64_t, PickupInventoryContainer*>::iterator pickupsIterator_; //!< An iterator pointing to the current Pickupable in pickupsList_.
     166            std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking @ref oroxnox::PickupIdentifier "PickupIdentifiers" (representing types of @ref orxonox::Pickupable "Pickupables") and @ref orxonox::PickupRepresentation "PickupRepresentations".
     167            std::map<uint32_t, PickupRepresentation*> representationsNetworked_; //!< Map linking the @ref orxonox::PickupRepresentation "PickupRepresentation's" objectId to the @ref orxonox::PickupRepresentation "PickupRepresentation" itself. It is used for networking purposes.
    126168
    127             std::map<uint64_t, WeakPtr<Pickupable>*> pickups_;
    128             std::map<Pickupable*, uint64_t> indexes_;
     169            std::map<uint32_t, PickupInventoryContainer*> pickupInventoryContainers_; //!< Map linking a number identifying a @ref orxonox::Pickupable "Pickupable" to a @ref orxonox::PickupInventoryContainer "PickupInventoryContainer", which contains all necessary information about that @ref orxonox::Pickupable "Pickupable".
     170            std::map<uint32_t, PickupInventoryContainer*>::iterator pickupsIterator_; //!< An iterator pointing to the current Pickupable in pickupsList_.
    129171
    130             void updateGUI(void);
    131             uint64_t getPickupIndex(void);
     172            std::map<uint32_t, WeakPtr<Pickupable>*> pickups_; //!< Map linking a number identifying a @ref orxonox::Pickupable "Pickupable" to a weak pointer of a @ref orxonox::Pickupable "Pickupable".
     173            std::map<Pickupable*, uint32_t> indexes_;//!< Map linking @ref orxonox::Pickupable "Pickupable" to the number identifying it.
     174
     175            void updateGUI(void); //!< Updates the PickupInventory GUI.
     176            uint32_t getPickupIndex(void); //!< Get a new index for a Pickupable.
    132177
    133178    }; // tolua_export
  • code/trunk/src/modules/pickup/PickupRepresentation.cc

    r7504 r7533  
    8383        if(this->isInitialized())
    8484        {
     85            //TODO: Also (network) unregister for master.
    8586            if(GameMode::isMaster() && this->pickup_ != NULL)
    8687            {
  • code/trunk/src/modules/pickup/items/MetaPickup.cc

    r7163 r7533  
    125125                if(this->getMetaTypeDirect() == pickupMetaType::destroyCarrier)
    126126                {
     127                    this->Pickupable::destroy(); //TODO: Needed?
    127128                    Pawn* pawn = orxonox_cast<Pawn*>(carrier);
    128129                    pawn->kill();
  • code/trunk/src/modules/pickup/items/MetaPickup.h

    r7493 r7533  
    108108            static const std::string metaTypeDestroyCarrier_s;
    109109
    110 
    111110    };
    112111
  • code/trunk/src/orxonox/controllers/HumanController.cc

    r7284 r7533  
    5656    SetConsoleCommand("HumanController", "addBots",                &HumanController::addBots       ).addShortcut().defaultValues(1);
    5757    SetConsoleCommand("HumanController", "killBots",               &HumanController::killBots      ).addShortcut().defaultValues(0);
    58     SetConsoleCommand("HumanController", "dropItems",              &HumanController::dropItems     ).addShortcut();
    59     SetConsoleCommand("HumanController", "useItem",                &HumanController::useItem       ).addShortcut();
    6058    SetConsoleCommand("HumanController", "cycleNavigationFocus",   &HumanController::cycleNavigationFocus).addShortcut();
    6159    SetConsoleCommand("HumanController", "releaseNavigationFocus", &HumanController::releaseNavigationFocus).addShortcut();
     
    202200    }
    203201
    204     void HumanController::useItem()
    205     {
    206         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    207             HumanController::localController_s->controllableEntity_->useItem();
    208     }
    209 
    210202    void HumanController::addBots(unsigned int amount)
    211203    {
     
    218210        if (HumanController::localController_s && HumanController::localController_s->controllableEntity_ && HumanController::localController_s->controllableEntity_->getGametype())
    219211            HumanController::localController_s->controllableEntity_->getGametype()->killBots(amount);
    220     }
    221 
    222     void HumanController::dropItems()
    223     {
    224         if (HumanController::localController_s && HumanController::localController_s->controllableEntity_)
    225             HumanController::localController_s->controllableEntity_->dropItems();
    226212    }
    227213
  • code/trunk/src/orxonox/controllers/HumanController.h

    r6417 r7533  
    6868            static void switchCamera();
    6969            static void mouseLook();
    70             static void dropItems();
    71             static void useItem();
    7270            static void cycleNavigationFocus();
    7371            static void releaseNavigationFocus();
  • code/trunk/src/orxonox/worldentities/ControllableEntity.cc

    r7502 r7533  
    281281
    282282        this->player_ = player;
     283        this->formerPlayer_ = player;
    283284        this->playerID_ = player->getObjectID();
    284285        this->bHasLocalController_ = player->isLocalPlayer();
  • code/trunk/src/orxonox/worldentities/ControllableEntity.h

    r7163 r7533  
    5555            inline PlayerInfo* getPlayer() const
    5656                { return this->player_; }
     57            /**
     58            @brief Get the player even after the ControllableEntity has stopped being the players ControllableEntity.
     59            @return Returns the most recent PlayerInfo.
     60            */
     61            inline PlayerInfo* getFormerPlayer() const
     62                { return this->formerPlayer_; }
    5763
    5864            inline void setDestroyWhenPlayerLeft(bool bDestroy)
     
    8995            virtual void boost() {}
    9096            virtual void greet() {}
    91             virtual void useItem() {}
    92             virtual void dropItems() {}
    9397            virtual void switchCamera();
    9498            virtual void mouseLook();
     
    204208
    205209            PlayerInfo* player_;
     210            PlayerInfo* formerPlayer_;
    206211            unsigned int playerID_;
    207212
  • code/trunk/src/orxonox/worldentities/pawns/Pawn.cc

    r7163 r7533  
    248248            this->setDestroyWhenPlayerLeft(false);
    249249
    250             this->dropItems();
    251 
    252250            if (this->getGametype())
    253251                this->getGametype()->pawnKilled(this, this->lastHitOriginator_);
Note: See TracChangeset for help on using the changeset viewer.