Orxonox
0.0.5 Codename: Arcturus
|
The PickupManager class manages Pickupables. More...
#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/modules/pickup/PickupManager.h>
Public Member Functions | |
PickupManager () | |
Constructor. More... | |
virtual | ~PickupManager () |
Destructor. More... | |
void | dropPickup (uint32_t pickup) |
Drop the input Pickupable. More... | |
int | getNumPickups (void) |
Get the number of pickups currently picked up by the player. More... | |
PickupRepresentation * | getRepresentation (const std::string &name) |
Get the PickupRepresentation with the given name. More... | |
bool | isValidPickup (uint32_t pickup) const |
Check whether the input Pickupable is valid, meaning that it is in the PickupManager's list and still exists. More... | |
virtual void | pickupChangedPickedUp (Pickupable *pickup, bool pickedUp) override |
Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state. More... | |
virtual void | pickupChangedUsed (Pickupable *pickup, bool used) override |
Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input used state. More... | |
const orxonox::PickupInventoryContainer * | popPickup (void) |
Get the next PickupInventoryContainer in the list. More... | |
bool | registerRepresentation (const std::string &name, PickupRepresentation *representation) |
Registers a PickupRepresentation. More... | |
bool | unregisterRepresentation (const std::string &name) |
Unegisters a PickupRepresentation. More... | |
void | usePickup (uint32_t pickup, bool use) |
Use (or unuse) the input Pickupable. More... | |
Public Member Functions inherited from orxonox::PickupListener | |
PickupListener () | |
Constructor. More... | |
virtual | ~PickupListener () |
Destructor. More... | |
Public Member Functions inherited from orxonox::OrxonoxInterface | |
OrxonoxInterface () | |
Public Member Functions inherited from orxonox::Configurable | |
Configurable () | |
void | setConfigValues () |
Function to collect the SetConfigValue-macro calls. More... | |
Public Member Functions inherited from orxonox::Listable | |
Listable () | |
Constructor: Allocates space in the element list. More... | |
Listable (Context *context) | |
Constructor: Allocates space in the element list and assigns the context. More... | |
virtual | ~Listable () |
Destructor: Removes the object from the object-lists. More... | |
Context * | getContext () const |
void | setContext (Context *context) |
Changes the context. More... | |
void | unregisterObject () |
Removes this object from the object-lists. More... | |
Public Member Functions inherited from orxonox::Identifiable | |
Identifiable () | |
Constructor: Sets the default values. More... | |
virtual | ~Identifiable () |
ORX_FORCEINLINE void * | getDerivedPointer (unsigned int classID) |
Returns a valid pointer of any derived type that is registered in the class hierarchy. More... | |
template<class T > | |
ORX_FORCEINLINE T * | getDerivedPointer (unsigned int classID) |
Version of getDerivedPointer with template. More... | |
template<class T > | |
ORX_FORCEINLINE const T * | getDerivedPointer (unsigned int classID) const |
Const version of getDerivedPointer with template. More... | |
Identifier * | getIdentifier () const |
Returns the Identifier of the object. More... | |
bool | isA (const Identifier *identifier) |
Returns true if the object's class is of the given type or a derivative. More... | |
template<class B > | |
bool | isA (const SubclassIdentifier< B > *identifier) |
Returns true if the object's class is of the given type or a derivative. More... | |
bool | isA (const Identifiable *object) |
Returns true if the object's class is of the given type or a derivative. More... | |
bool | isChildOf (const Identifier *identifier) |
Returns true if the object's class is a child of the given type. More... | |
template<class B > | |
bool | isChildOf (const SubclassIdentifier< B > *identifier) |
Returns true if the object's class is a child of the given type. More... | |
bool | isChildOf (const Identifiable *object) |
Returns true if the object's class is a child of the given type. More... | |
bool | isDirectChildOf (const Identifier *identifier) |
Returns true if the object's class is a direct child of the given type. More... | |
template<class B > | |
bool | isDirectChildOf (const SubclassIdentifier< B > *identifier) |
Returns true if the object's class is a direct child of the given type. More... | |
bool | isDirectChildOf (const Identifiable *object) |
Returns true if the object's class is a direct child of the given type. More... | |
bool | isDirectParentOf (const Identifier *identifier) |
Returns true if the object's class is a direct parent of the given type. More... | |
template<class B > | |
bool | isDirectParentOf (const SubclassIdentifier< B > *identifier) |
Returns true if the object's class is a direct parent of the given type. More... | |
bool | isDirectParentOf (const Identifiable *object) |
Returns true if the object's class is a direct child of the given type. More... | |
bool | isExactlyA (const Identifier *identifier) |
Returns true if the object's class is exactly of the given type. More... | |
template<class B > | |
bool | isExactlyA (const SubclassIdentifier< B > *identifier) |
Returns true if the object's class is exactly of the given type. More... | |
bool | isExactlyA (const Identifiable *object) |
Returns true if the object's class is exactly of the given type. More... | |
bool | isParentOf (const Identifier *identifier) |
Returns true if the object's class is a parent of the given type. More... | |
template<class B > | |
bool | isParentOf (const SubclassIdentifier< B > *identifier) |
Returns true if the object's class is a parent of the given type. More... | |
bool | isParentOf (const Identifiable *object) |
Returns true if the object's class is a parent of the given type. More... | |
Public Member Functions inherited from orxonox::Destroyable | |
Destroyable () | |
Constructor: Sets the default values. More... | |
virtual | ~Destroyable () |
Destructor: Notifies all DestructionListener (for example weak pointers) that this object is being deleted. More... | |
void | destroy () |
Deletes the object if no strong pointers point to this object. More... | |
void | destroyLater () |
Works like destroy() but doesn't destroy the object until the current tick has ended. More... | |
unsigned int | getReferenceCount () const |
Returns the number of strong pointers that point to this object. More... | |
Static Public Member Functions | |
static void | dropPickupNetworked (uint32_t pickup) |
Helper method to drop the input pickup on the server. More... | |
static PickupManager & | getInstance () |
Get the instance of the PickupManager singleton. More... | |
static void | pickupChangedPickedUpNetwork (uint32_t pickup, bool usable, const std::string &representationName, bool pickedUp, uint32_t carrierPawnId) |
Helper method to react to the change in the pickedUp status of a Pickupable. More... | |
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. More... | |
static void | usePickupNetworked (uint32_t pickup, bool use) |
Helper method to use (or unuse) the input Pickupable on the server. More... | |
Static Public Member Functions inherited from orxonox::Singleton< PickupManager > | |
static bool | exists () |
Tells whether the singleton has been created. More... | |
static PickupManager & | getInstance () |
Returns a reference to the singleton instance. More... | |
Static Public Member Functions inherited from orxonox::PickupListener | |
static void | broadcastPickupChangedPickedUp (Pickupable *pickup, bool pickedUp) |
Static method that is used to notify the PickupListener itself of the change in the pickedUp status of a Pickupable. More... | |
static void | broadcastPickupChangedUsed (Pickupable *pickup, bool used) |
Static method that is used to notify the PickupListener itself of the change in the used status of a Pickupable. More... | |
Private Member Functions | |
uint32_t | getPickupIndex (void) |
Get a new index for a Pickupable. More... | |
void | updateGUI (void) |
Updates the PickupInventory GUI. More... | |
Private Attributes | |
PickupRepresentation * | defaultRepresentation_ |
The default PickupRepresentation. More... | |
bool | guiLoaded_ |
Whether the PickupInventory GUI has been loaded, yet. More... | |
std::map< Pickupable *, uint32_t > | indexes_ |
Map linking Pickupable to the number identifying it. More... | |
uint32_t | pickupHighestIndex_ |
The highest pickup index currently in use. (not taking wrap-around into account) More... | |
std::map< uint32_t, PickupInventoryContainer * > | pickupInventoryContainers_ |
Map linking a number identifying a Pickupable to a PickupInventoryContainer, which contains all necessary information about that Pickupable. More... | |
std::map< uint32_t, WeakPtr< Pickupable > > | pickups_ |
Map linking a number identifying a Pickupable to a weak pointer of a Pickupable. More... | |
std::map< uint32_t, PickupInventoryContainer * >::iterator | pickupsIterator_ |
An iterator pointing to the current Pickupable in pickupsList_. More... | |
std::map< std::string, PickupRepresentation * > | representations_ |
Map linking PickupRepresentations and their names. More... | |
Static Private Attributes | |
static const std::string | guiName_s = "PickupInventory" |
The name of the PickupInventory. More... | |
static PickupManager * | singletonPtr_s |
Friends | |
class | Singleton< PickupManager > |
Additional Inherited Members | |
Protected Member Functions inherited from orxonox::Singleton< PickupManager > | |
Singleton () | |
Constructor sets the singleton instance pointer. More... | |
virtual | ~Singleton () |
Destructor resets the singleton instance pointer. More... | |
Protected Member Functions inherited from orxonox::Destroyable | |
virtual void | preDestroy () |
This virtual function is called if destroy() is called and no StrongPtr points to this object. More... | |
The PickupManager class manages Pickupables.
It has in essence two tasks to fulfill. Firstly it must link Pickupables (through their representation-name attribute) to the respective PickupRepresentations. Secondly it manages the PickupInventory. (The PickupInventory is the GUI that displays Pickupables for the covenience of the user.)
Unfortunately under the hood 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:
The pickups module essentially just exists on the Server, since it's all game logic. That means, a PickupSpawner is always triggered on the server, the 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 PickupSpawner, since it needs to be displayed on the Clients as well, and anything that is needed for the PickupInventory, since it exists for each Host seperatly.
Fortunately synchronising the PickupSpawner is already being taken care of by the synchronisation of the StaticEntity (or parents thereof).
This leaves us with the PickupInventory component (and this is really the source of all the complexity).
Firstly there are a number of lists (where by list I really mean any kind of ordered data structure) kept.
There is communication in both directions. From server to client, when the server informs the client that the state of some 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 Pickupable.
orxonox::PickupManager::PickupManager | ( | ) |
Constructor.
Registers the PickupManager and creates the default PickupRepresentation.
|
virtual |
Destructor.
Destroys the default PickupRepresentation and does some cleanup.
void orxonox::PickupManager::dropPickup | ( | uint32_t | pickup | ) |
Drop the input Pickupable.
This method checks whether the input Pickupable still exists and drops it, if so.
pickup | The identifier of the Pickupable to be dropped. |
|
static |
Helper method to drop the input pickup on the server.
Static method that is used by clients to instruct the server to drop the input pickup.
pickup | The identifier of the Pickupable to be dropped. |
|
inlinestatic |
Get the instance of the PickupManager singleton.
int orxonox::PickupManager::getNumPickups | ( | void | ) |
Get the number of pickups currently picked up by the player.
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.
|
private |
Get a new index for a Pickupable.
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.
PickupRepresentation * orxonox::PickupManager::getRepresentation | ( | const std::string & | name | ) |
Get the PickupRepresentation with the given name.
name | The name of the PickupRepresentation. |
|
inline |
Check whether the input Pickupable is valid, meaning that it is in the PickupManager's list and still exists.
pickup | The Pickupable. |
|
overridevirtual |
Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state.
pickup | The Pickupable whose pickedUp status changed. |
pickedUp | The pickedUp status the Pickupable changed to. |
Reimplemented from orxonox::PickupListener.
|
static |
Helper method to react to the change in the pickedUp status of a Pickupable.
Static method that is used by the server to inform the client it concerns about the status change. The parameters that are given are used to update the information (i.e. the PickupInventoryContainer) the concerning PickupManager has about the Pickupable that changed.
pickup | A number identifying the Pickupable that changed its pickedUp status. |
usable | Whether the Pickupable's used status can be changed to used in the PickupInventory. |
representationName | The name of the associated PickupRepresentation |
pickedUp | The pickedUp status the Pickupable changed to. |
carrierPawnId | The objectId identifier (over the network) the Pawn that carries this Pickupable |
|
overridevirtual |
Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input used state.
pickup | The Pickupable whose used status changed. |
used | The used status the Pickupable changed to. |
Reimplemented from orxonox::PickupListener.
|
static |
Helper method to react to the change in the used status of a Pickupable.
Static method that is used by the server to inform the client it concerns about the status change. The parameters that are given are used to update the information (i.e. the PickupInventoryContainer) the concerning PickupManager has about the Pickupable that changed.
pickup | A number identifying the Pickupable that changed its used status. |
inUse | The used status the Pickupable changed to. (i.e. whether the Pickupable is in use or not). |
usable | Whether the Pickupable's used status can be changed used in the PickupInventory. |
unusable | Whether the Pickupable's used status can be changed to unused in the PickupInventory. |
|
inline |
Get the next PickupInventoryContainer in the list.
Use this, after having called getNumPickups() to access all the PickupInventoryContainers individually and in succession.
bool orxonox::PickupManager::registerRepresentation | ( | const std::string & | name, |
PickupRepresentation * | representation | ||
) |
Registers a PickupRepresentation.
name | The representation's name. |
representation | A pointer to the PickupRepresentation. |
bool orxonox::PickupManager::unregisterRepresentation | ( | const std::string & | name | ) |
Unegisters a PickupRepresentation.
name | The representation's name. |
Updates the PickupInventory GUI.
Also loads the PickupInventory GUI if is hasn't been done already.
void orxonox::PickupManager::usePickup | ( | uint32_t | pickup, |
bool | use | ||
) |
Use (or unuse) the input Pickupable.
This method checks whether the input Pickupable still exists and uses (or unuses) it, if so,
pickup | The identifier of the Pickupable to be used (or unused). |
use | If true the input Pickupable is used, if false it is unused. |
|
static |
Helper method to use (or unuse) the input Pickupable on the server.
Static method that is used by clients to instruct the server to use (or unuse) the input pickup.
pickup | The identifier of the Pickupable to be used (or unused). |
use | If true the input Pickupable is used, if false it is unused. |
|
friend |
|
private |
The default PickupRepresentation.
|
private |
Whether the PickupInventory GUI has been loaded, yet.
|
staticprivate |
The name of the PickupInventory.
|
private |
Map linking Pickupable to the number identifying it.
|
private |
The highest pickup index currently in use. (not taking wrap-around into account)
|
private |
Map linking a number identifying a Pickupable to a PickupInventoryContainer, which contains all necessary information about that Pickupable.
|
private |
Map linking a number identifying a Pickupable to a weak pointer of a Pickupable.
|
private |
An iterator pointing to the current Pickupable in pickupsList_.
|
private |
Map linking PickupRepresentations and their names.
|
staticprivate |