CORGI
An open source project by FPL.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
corgi::component_library::CommonServicesComponent Class Reference

This is a unique Component, as no Entities will register with it and it contains no per-entity data. Its use is to provide a central location for other Components to easily access game services and managers (since Components themselves do not have direct access to the game state, but do have access to other Components). More...

#include <common_services.h>

Inherits corgi::Component< CommonServicesData >.

Detailed Description

This is a unique Component, as no Entities will register with it and it contains no per-entity data. Its use is to provide a central location for other Components to easily access game services and managers (since Components themselves do not have direct access to the game state, but do have access to other Components).

Public Member Functions

 CommonServicesComponent ()
 The default constructor to create an empty CommonServicesComponent.
 
virtual ~CommonServicesComponent ()
 Destructor for CommonServicesComponent.
 
void Initialize (fplbase::AssetManager *asset_manager, EntityFactory *entity_factory, breadboard::GraphFactory *graph_factory, fplbase::InputSystem *input_system, fplbase::Renderer *renderer)
 Initializes the CommonServicesComponent with pointers to the various game services and managers. More...
 
fplbase::AssetManager * asset_manager ()
 
breadboard::GraphFactory * graph_factory ()
 
fplbase::InputSystem * input_system ()
 
EntityFactoryentity_factory ()
 
fplbase::Renderer * renderer ()
 
void AddFromRawData (corgi::EntityRef &, const void *)
 This component should never be added to an Entity. It is only provided as an interface for other components to access common game resources. More...
 
bool export_force_defaults () const
 This should be called when Components are exporting their data to a FlatBuffer. It indicates if the FlatBuffer should include default values in the serialized data. More...
 
void set_export_force_defaults (bool b)
 Set a flag to determine if Components, when exporting their data to FlatBuffers, should include default values in the serialized data. More...
 
- Public Member Functions inherited from corgi::Component< CommonServicesData >
 Component ()
 Construct a Component without an EntityManager.
 
virtual ~Component ()
 Destructor for a Component.
 
virtual void AddEntityGenerically (EntityRef &entity)
 Provides an alternate way to add Entities if you do not care about the returned data structure, and if you do not feel like casting the BaseComponent into something more specific. More...
 
CommonServicesData * AddEntity (EntityRef &entity, AllocationLocation alloc_location)
 Adds an Entity to the list that this Component is tracking. More...
 
CommonServicesData * AddEntity (EntityRef &entity)
 Adds an Entity to the list that this Component is tracking. More...
 
virtual void RemoveEntity (EntityRef &entity)
 Removes an Entity from the list of Entities. More...
 
virtual EntityIterator RemoveEntity (EntityIterator iter)
 Removes an Entity from the list of Entities. More...
 
virtual EntityIterator begin ()
 Gets an iterator that will iterate over every Entity associated with the Component, starting from the beginning. More...
 
virtual EntityIterator end ()
 Gets an iterator that points to the end of the list of all entites in the Component. More...
 
virtual void UpdateAllEntities (WorldTime)
 Updates all Entities. This is normally called, once per frame, by the EntityManager.
 
virtual bool HasDataForEntity (const EntityRef &entity)
 Checks if this component contains any data associated with the supplied entity.
 
virtual void * GetComponentDataAsVoid (const EntityRef &entity)
 Gets the data for a given Entity as a void pointer. More...
 
virtual const void * GetComponentDataAsVoid (const EntityRef &entity) const
 Gets the data for a given Entity as a const void pointer. More...
 
CommonServicesData * GetComponentData (size_t data_index)
 Gets the Component data stored at a given index. More...
 
CommonServicesData * GetComponentData (const EntityRef &entity)
 Gets the data for a given Entity. More...
 
const CommonServicesData * GetComponentData (size_t data_index) const
 Gets the Component data stored at a given index. More...
 
const CommonServicesData * GetComponentData (const EntityRef &entity) const
 Gets the data for a given Entity. More...
 
virtual void ClearComponentData ()
 Clears all tracked Component data.
 
ComponentDataType * Data (const EntityRef &entity)
 A utility function for retrieving the Component data for an Entity from a specific Component. More...
 
ComponentDataType * Data (const EntityRef &entity) const
 A utility function for retrieving the Component data for an Entity from a specific Component. More...
 
bool IsRegisteredWithComponent (const EntityRef &entity)
 A utility function for checking if an entity is registered with a particular component. More...
 
ComponentDataType * GetComponent ()
 A utility function for retrieving a reference to a specific Component object, by type. More...
 
virtual void Init ()
 Override this function with code that should be executed when the Component is added to the EntityManager. (This typically happens once, at the beginning of the game before any Entities are added.)
 
virtual void InitEntity (EntityRef &)
 Override this function with code that should be executed when an Entity is added to the Component.
 
virtual RawDataUniquePtr ExportRawData (const EntityRef &) const
 Override this function to return raw data that can be read back later. More...
 
virtual void Cleanup ()
 Override this function with any code that executes when this Component is removed from the EntityManager. (i.e. Usually when the game/state is over and everything is shutting down.)
 
virtual void CleanupEntity (EntityRef &)
 Override this function with any code that needs to be executed when an Entity is removed from this Component.
 
virtual void SetEntityManager (EntityManager *entity_manager)
 Set the EntityManager for this Component. More...
 
virtual void SetComponentIdOnDataType (ComponentId id)
 Sets the Component ID on the data type. More...
 
- Public Member Functions inherited from corgi::ComponentInterface
virtual ~ComponentInterface ()
 A destructor for the Component interface.
 

Additional Inherited Members

- Public Types inherited from corgi::Component< CommonServicesData >
typedef VectorPool
< ComponentData >::Iterator 
EntityIterator
 An iterator to iterate through all of the Entities in the Component.
 
typedef CommonServicesData value_type
 The templated data type stored by this Component.
 
- Public Types inherited from corgi::ComponentInterface
typedef std::unique_ptr
< uint8_t, std::function< void(uint8_t *)> > 
RawDataUniquePtr
 A pointer type for exported raw data.
 
- Static Public Member Functions inherited from corgi::Component< CommonServicesData >
static ComponentId GetComponentId ()
 Get the ID for this Component. More...
 
- Protected Member Functions inherited from corgi::Component< CommonServicesData >
size_t GetComponentDataIndex (const EntityRef &entity) const
 Get the index of the Component data for a given Entity. More...
 
- Protected Attributes inherited from corgi::Component< CommonServicesData >
VectorPool< ComponentData > component_data_
 Storage for all of the data for the Component.
 
EntityManagerentity_manager_
 A pointer to the EntityManager for this Component. This is the main point of contact for Components that need to talk to other things.
 
std::unordered_map
< EntityIdType, ComponentIndex
component_index_lookup_
 A map, for translating unique entity IDs into vectorpool indexes.
 

Member Function Documentation

void corgi::component_library::CommonServicesComponent::AddFromRawData ( corgi::EntityRef ,
const void *   
)
inlinevirtual

This component should never be added to an Entity. It is only provided as an interface for other components to access common game resources.

Warning
Asserts when called.

Implements corgi::ComponentInterface.

fplbase::AssetManager* corgi::component_library::CommonServicesComponent::asset_manager ( )
inline
Returns
Returns a pointer to the AssetManager.
EntityFactory* corgi::component_library::CommonServicesComponent::entity_factory ( )
inline
Returns
Returns a pointer to the EntityFactory.
bool corgi::component_library::CommonServicesComponent::export_force_defaults ( ) const
inline

This should be called when Components are exporting their data to a FlatBuffer. It indicates if the FlatBuffer should include default values in the serialized data.

Returns
Returns true if the FlatBuffer serialized data should include default values. Otherwise returns false, indicating that default values should be excluded from the FlatBuffer serialized data.
breadboard::GraphFactory* corgi::component_library::CommonServicesComponent::graph_factory ( )
inline
Returns
Returns a pointer to the breadboard::GraphFactory.
void corgi::component_library::CommonServicesComponent::Initialize ( fplbase::AssetManager *  asset_manager,
EntityFactory entity_factory,
breadboard::GraphFactory *  graph_factory,
fplbase::InputSystem *  input_system,
fplbase::Renderer *  renderer 
)
inline

Initializes the CommonServicesComponent with pointers to the various game services and managers.

Parameters
[in]asset_managerA pointer to the game's AssetManager.
[in]entity_factoryA pointer to the game's EntityFactory.
[in]graph_factoryA pointer to the game's breadboard::GraphFactory.
[in]input_systemA pointer to the game's input_system.
[in]rendererA pointer to the game's Renderer.
fplbase::InputSystem* corgi::component_library::CommonServicesComponent::input_system ( )
inline
Returns
Returns a pointer to the InputSystem.
fplbase::Renderer* corgi::component_library::CommonServicesComponent::renderer ( )
inline
Returns
Returns a pointer to the Renderer.
void corgi::component_library::CommonServicesComponent::set_export_force_defaults ( bool  b)
inline

Set a flag to determine if Components, when exporting their data to FlatBuffers, should include default values in the serialized data.

Parameters
[in]bA bool indicating if the FlatBuffer serialized data should include default values.

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