Robot Devastation
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
rd::MentalMap Class Reference

Mental map is a repository for information about the players, targets and weapons. More...

#include <MentalMap.hpp>

Inheritance diagram for rd::MentalMap:
rd::NetworkEventListener

Public Member Functions

bool configure (const int &player_id)
 Store the id of the player corresponding to the user.
 
std::vector< TargetgetTargets () const
 
std::vector< PlayergetPlayers () const
 
Target getTarget (const int &id=-1) const
 
Player getPlayer (const int &id=-1) const
 
Player getMyself () const
 Get the player corresponding to the user.
 
void addWeapon (Weapon weapon)
 
Weapon getCurrentWeapon () const
 
bool shoot ()
 Manage all the actions to be carried out when the user shoots (sound, update players, etc)
 
bool reload ()
 Manage all the actions to be carried out when the user reloads (sound, update weapons, etc)
 
bool updatePlayers (const std::vector< Player > &new_player_vector)
 The current implementation just replaces the players inside the mental map by the new players.
 
bool updateTargets (const std::vector< Target > &new_target_detections)
 Update the targets stored in the mental map. More...
 
bool respawn ()
 Restores the health of current player (and does more stuff if needed)
 
bool addMentalMapEventListener (MentalMapEventListener *listener)
 Adds a MentalMapEventListener to the list of observers to be notified of events.
 
bool removeMentalMapEventListeners ()
 Unregisters all the MentalMapEventListener stored.
 

Static Public Member Functions

static MentalMapgetMentalMap ()
 Get a reference to the MentalMap.
 
static bool destroyMentalMap ()
 Get a reference to the MentalMap.
 

Private Member Functions

 MentalMap ()
 Constructor. More...
 
 MentalMap (const MentalMap &)
 
MentalMapoperator= (const MentalMap &)
 
bool onDataArrived (const std::vector< Player > &players)
 Updates the local information about the players with the new data received by the NetworkManager.
 

Private Attributes

std::map< int, Targettargets
 Storage for the target data. The key of the dictionary is the player id.
 
std::map< int, Playerplayers
 Storage for the players data. The key of the dictionary is the player id.
 
std::vector< Weaponweapons
 Storage for the weapons data.
 
int current_weapon
 Index of the weapon currenly selected.
 
int my_id
 Id of the player corresponding to the user.
 
Playermyself
 Pointer to the player corresponding to the user.
 
AudioManageraudioManager
 Reference to the AudioManager.
 
std::vector< MentalMapEventListener * > listeners
 Observers registered to be notified of data change events.
 

Static Private Attributes

static MentalMapmentalMapInstance = NULL
 Stores the unique instance of the MentalMap.
 

Detailed Description

MentalMap is a singleton text (only one instance of this object can exist, that is is shared by all the users). To use this class, we first get the reference to the MentalMap with getMentalMap() and then we access the MentalMap with that reference.

When the program finishes, the MentalMap can be deallocated using destroyMentalMap().

MentalMap implements the NetworkEventListener observer interface, which allows this class to receive notification of network events to update its local data.

Data change events are broadcasted to the registered listeners, along with the data relevant to the event triggered (i.e. the new targets detected).

Constructor & Destructor Documentation

◆ MentalMap()

rd::MentalMap::MentalMap ( )
private

Constructor for this class is private, since the singleton can only be instantiated once, and the instantiation is done at the getMentalMap() method.

Member Function Documentation

◆ updateTargets()

bool rd::MentalMap::updateTargets ( const std::vector< Target > &  new_target_detections)

If a target previously detected is no longer present in the new detections, decreases the belief value until reaching 0. Then, it deletes that target.


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