Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.