Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Oct 6, 2010, 8:00:40 AM (14 years ago)
Author:
dafrick
Message:

Pickups module is now (from what I can tell after some basic testing) fully functional over the network.
However it's still a little messy, needs some cleanup and documentation.
I introduced a new class, the PickupListener, which allows reacting to pickups becoming used, unused, picked up or dropped.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/modules/pickup/PickupManager.h

    r7456 r7504  
    3939
    4040#include <map>
    41 #include "util/Singleton.h"
     41
    4242#include "core/WeakPtr.h"
     43
    4344#include "pickup/PickupIdentifier.h"
     45
    4446#include "PickupRepresentation.h"
    4547
    46 #include "core/OrxonoxClass.h"
     48#include "util/Singleton.h"
     49#include "interfaces/PickupListener.h"
    4750
    4851namespace orxonox // tolua_export
    4952{ // tolua_export
     53
     54    // tolua_begin
     55    struct PickupInventoryContainer
     56    {
     57        uint64_t pickup;
     58        bool inUse;
     59        bool pickedUp;
     60        bool usable;
     61        bool unusable;
     62        uint32_t representationObjectId;
     63    };
     64    // tolua_end
    5065
    5166    /**
     
    5772    */
    5873    class _PickupExport PickupManager // tolua_export
    59         : public Singleton<PickupManager>, public OrxonoxClass
     74        : public Singleton<PickupManager>, public PickupListener
    6075    { // tolua_export
    6176        friend class Singleton<PickupManager>;
     
    6883
    6984            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);
    7086            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);
    7188            PickupRepresentation* getRepresentation(const PickupIdentifier* identifier); //!< Get the PickupRepresentation representing the Pickupable with the input PickupIdentifier.
    7289
    7390            // tolua_begin
    74             orxonox::PickupRepresentation* getPickupRepresentation(orxonox::Pickupable* pickup); //!< Get the PickupRepresentation of an input Pickupable.
     91            orxonox::PickupRepresentation* getPickupRepresentation(uint64_t pickup); //!< Get the PickupRepresentation of an input Pickupable.
    7592
    7693            int getNumPickups(void); //!< Update the list of picked up Pickupables and get the number of Pickupables in the list.
     
    8097            @return Returns the next Pickupable in the list.
    8198            */
    82             orxonox::Pickupable* popPickup(void) { return (this->pickupsIterator_++)->first; }
     99            orxonox::PickupInventoryContainer* popPickup(void) { return (this->pickupsIterator_++)->second; }
    83100
    84             void dropPickup(orxonox::Pickupable* pickup); //!< Drop the input Pickupable.
    85             void usePickup(orxonox::Pickupable* pickup, bool use); //!< Use (or unuse) the input Pickupable.
    86             bool isValidPickup(orxonox::Pickupable* pickup); //!< Check whether the input Pickupable is valid, meaning that it is in the PickupManager's list and still exists.
     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.
    87104            // tolua_end
     105
     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);
    88113
    89114        private:
    90115            static PickupManager* singletonPtr_s;
    91116            static const std::string guiName_s; //!< The name of the PickupInventory
     117            bool guiLoaded_;
     118            uint64_t pickupIndex_;
    92119
    93120            PickupRepresentation* defaultRepresentation_; //!< The default PickupRepresentation.
    94121            std::map<const PickupIdentifier*, PickupRepresentation*, PickupIdentifierCompare> representations_; //!< Map linking PickupIdentifiers (representing types if Pickupables) and PickupRepresentations.
     122            std::map<uint32_t, PickupRepresentation*> representationsNetworked_;
    95123
    96             std::map<Pickupable*, WeakPtr<Pickupable> > pickupsList_; //!< A list of all the picked up Pickupables.
    97             std::map<Pickupable*, WeakPtr<Pickupable> >::iterator pickupsIterator_; //!< An iterator pointing to the current Pickupable in pickupsList_.
     124            std::map<uint64_t, PickupInventoryContainer*> pickupInventoryContainers_;
     125            std::map<uint64_t, PickupInventoryContainer*>::iterator pickupsIterator_; //!< An iterator pointing to the current Pickupable in pickupsList_.
    98126
    99             std::vector<PickupCarrier*>* getAllCarriers(PickupCarrier* carrier, std::vector<PickupCarrier*>* carriers = NULL); //!< Helper method. Get all the PickupCarriers that carry Pickupables, recursively.
     127            std::map<uint64_t, WeakPtr<Pickupable>*> pickups_;
     128            std::map<Pickupable*, uint64_t> indexes_;
     129
     130            void updateGUI(void);
     131            uint64_t getPickupIndex(void);
    100132
    101133    }; // tolua_export
Note: See TracChangeset for help on using the changeset viewer.