Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
orxonox::PickupManager Class Reference

The PickupManager class manages Pickupables. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/modules/pickup/PickupManager.h>

Inheritance diagram for orxonox::PickupManager:
orxonox::Singleton< PickupManager > orxonox::PickupListener orxonox::OrxonoxInterface orxonox::Configurable orxonox::Destroyable orxonox::Listable orxonox::Identifiable

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...
 
PickupRepresentationgetRepresentation (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::PickupInventoryContainerpopPickup (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...
 
ContextgetContext () 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 voidgetDerivedPointer (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...
 
IdentifiergetIdentifier () 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 PickupManagergetInstance ()
 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 PickupManagergetInstance ()
 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

PickupRepresentationdefaultRepresentation_
 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 PickupManagersingletonPtr_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...
 

Detailed Description

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.)

Technical details

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.

Author
Damian 'Mozork' Frick

Constructor & Destructor Documentation

orxonox::PickupManager::PickupManager ( )

Constructor.

Registers the PickupManager and creates the default PickupRepresentation.

orxonox::PickupManager::~PickupManager ( )
virtual

Destructor.

Destroys the default PickupRepresentation and does some cleanup.

Member Function Documentation

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.

Parameters
pickupThe identifier of the Pickupable to be dropped.
void orxonox::PickupManager::dropPickupNetworked ( uint32_t  pickup)
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.

Parameters
pickupThe identifier of the Pickupable to be dropped.
static PickupManager& orxonox::PickupManager::getInstance ( )
inlinestatic

Get the instance of the PickupManager singleton.

Returns
Returns 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.

Returns
Returns the number of the players picked up Pickupables.
uint32_t orxonox::PickupManager::getPickupIndex ( void  )
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.

Returns
Returns the new index.
PickupRepresentation * orxonox::PickupManager::getRepresentation ( const std::string &  name)

Get the PickupRepresentation with the given name.

Parameters
nameThe name of the PickupRepresentation.
Returns
Returns a pointer to the PickupRepresentation.
bool orxonox::PickupManager::isValidPickup ( uint32_t  pickup) const
inline

Check whether the input Pickupable is valid, meaning that it is in the PickupManager's list and still exists.

Parameters
pickupThe Pickupable.
Returns
Returns true if the input Pickupable is still valid, false if not.
void orxonox::PickupManager::pickupChangedPickedUp ( Pickupable pickup,
bool  pickedUp 
)
overridevirtual

Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input pickedUp state.

Parameters
pickupThe Pickupable whose pickedUp status changed.
pickedUpThe pickedUp status the Pickupable changed to.

Reimplemented from orxonox::PickupListener.

void orxonox::PickupManager::pickupChangedPickedUpNetwork ( uint32_t  pickup,
bool  usable,
const std::string &  representationName,
bool  pickedUp,
uint32_t  carrierPawnId 
)
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.

Parameters
pickupA number identifying the Pickupable that changed its pickedUp status.
usableWhether the Pickupable's used status can be changed to used in the PickupInventory.
representationNameThe name of the associated PickupRepresentation
pickedUpThe pickedUp status the Pickupable changed to.
carrierPawnIdThe objectId identifier (over the network) the Pawn that carries this Pickupable
void orxonox::PickupManager::pickupChangedUsed ( Pickupable pickup,
bool  used 
)
overridevirtual

Is called by the PickupListener to notify the PickupManager, that the input Pickupable has transited to the input used state.

Parameters
pickupThe Pickupable whose used status changed.
usedThe used status the Pickupable changed to.

Reimplemented from orxonox::PickupListener.

void orxonox::PickupManager::pickupChangedUsedNetwork ( uint32_t  pickup,
bool  inUse,
bool  usable,
bool  unusable 
)
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.

Parameters
pickupA number identifying the Pickupable that changed its used status.
inUseThe used status the Pickupable changed to. (i.e. whether the Pickupable is in use or not).
usableWhether the Pickupable's used status can be changed used in the PickupInventory.
unusableWhether the Pickupable's used status can be changed to unused in the PickupInventory.
const orxonox::PickupInventoryContainer* orxonox::PickupManager::popPickup ( void  )
inline

Get the next PickupInventoryContainer in the list.

Use this, after having called getNumPickups() to access all the PickupInventoryContainers individually and in succession.

Returns
Returns the next PickupInventoryContainer in the list.
bool orxonox::PickupManager::registerRepresentation ( const std::string &  name,
PickupRepresentation representation 
)

Registers a PickupRepresentation.

Parameters
nameThe representation's name.
representationA pointer to the PickupRepresentation.
Returns
Returns true if successful and false if not.
bool orxonox::PickupManager::unregisterRepresentation ( const std::string &  name)

Unegisters a PickupRepresentation.

Parameters
nameThe representation's name.
Returns
Returns true if successful and false if not.
void orxonox::PickupManager::updateGUI ( void  )
inlineprivate

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,

Parameters
pickupThe identifier of the Pickupable to be used (or unused).
useIf true the input Pickupable is used, if false it is unused.
void orxonox::PickupManager::usePickupNetworked ( uint32_t  pickup,
bool  use 
)
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.

Parameters
pickupThe identifier of the Pickupable to be used (or unused).
useIf true the input Pickupable is used, if false it is unused.

Friends And Related Function Documentation

friend class Singleton< PickupManager >
friend

Member Data Documentation

PickupRepresentation* orxonox::PickupManager::defaultRepresentation_
private

The default PickupRepresentation.

bool orxonox::PickupManager::guiLoaded_
private

Whether the PickupInventory GUI has been loaded, yet.

const std::string orxonox::PickupManager::guiName_s = "PickupInventory"
staticprivate

The name of the PickupInventory.

std::map<Pickupable*, uint32_t> orxonox::PickupManager::indexes_
private

Map linking Pickupable to the number identifying it.

uint32_t orxonox::PickupManager::pickupHighestIndex_
private

The highest pickup index currently in use. (not taking wrap-around into account)

std::map<uint32_t, PickupInventoryContainer*> orxonox::PickupManager::pickupInventoryContainers_
private

Map linking a number identifying a Pickupable to a PickupInventoryContainer, which contains all necessary information about that Pickupable.

std::map<uint32_t, WeakPtr<Pickupable> > orxonox::PickupManager::pickups_
private

Map linking a number identifying a Pickupable to a weak pointer of a Pickupable.

std::map<uint32_t, PickupInventoryContainer*>::iterator orxonox::PickupManager::pickupsIterator_
private

An iterator pointing to the current Pickupable in pickupsList_.

std::map<std::string, PickupRepresentation*> orxonox::PickupManager::representations_
private

Map linking PickupRepresentations and their names.

PickupManager* orxonox::PickupManager::singletonPtr_s
staticprivate

The documentation for this class was generated from the following files: