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

Implementations of DefaultEntityFactory can be found in default_entity_factory.inc. More...

#include <default_entity_factory.h>

Inherits corgi::component_library::EntityFactory.

Detailed Description

Implementations of DefaultEntityFactory can be found in default_entity_factory.inc.

Public Member Functions

virtual ~DefaultEntityFactory ()
 Destructor for DefaultEntityFactory.
 
virtual bool ReadEntityList (const void *entity_list, std::vector< const void * > *entity_defs)
 Handles reading an Entity list and extracting the individual Entity data definitions. More...
 
virtual bool ReadEntityDefinition (const void *entity_definition, std::vector< const void * > *component_defs)
 Handles reading an Entity definition and extracting the individual Component data definitions. More...
 
virtual bool CreatePrototypeRequest (const char *prototype_name, std::vector< uint8_t > *request)
 Creates an Entity list that contains a single Entity definition, which contains a single Component definition (a MetaDef with prototype set to the requested prototype name). More...
 
virtual bool CreateEntityDefinition (const std::vector< const void * > &component_data, std::vector< uint8_t > *entity_definition)
 Handles building a single Entity definition flatbuffer from a list of an Entity's Component definitions. More...
 
virtual bool CreateEntityList (const std::vector< const void * > &entity_defs, std::vector< uint8_t > *entity_list)
 Handles building an Entity list flatbuffer from a collection of individual Entity flatbuffers. More...
 
- Public Member Functions inherited from corgi::component_library::EntityFactory
 EntityFactory ()
 The default constructor for an empty EntityFactory.
 
bool AddEntityLibrary (const char *entity_library_file)
 Add a file from which you can load Entity prototype definitions. More...
 
bool WillBeKeptInMemory (const void *pointer)
 Check if the given pointer points to something that will be kept in memory for the lifetime of the EntityFactory. More...
 
virtual int LoadEntitiesFromFile (const char *filename, corgi::EntityManager *entity_manager)
 Load Entities from a given Entity list file. More...
 
int LoadEntityListFromMemory (const void *raw_entity_list, corgi::EntityManager *entity_manager, std::vector< corgi::EntityRef > *entities_loaded)
 Loads a list of Entities from an in-memory buffer. More...
 
void OverrideCachedFile (const char *filename, std::unique_ptr< std::string > new_data)
 Override a cached file with data from memory that will persist until exit. More...
 
corgi::EntityRef CreateEntityFromData (const void *data, corgi::EntityManager *entity_manager)
 Initialize an Entity from an Entity definition. More...
 
virtual corgi::EntityRef CreateEntityFromPrototype (const char *prototype_name, corgi::EntityManager *entity_manager)
 Initialize an entity from a given prototype. More...
 
void SetComponentType (corgi::ComponentId component_id, unsigned int data_type, const char *table_name)
 When you register each Component with the Entity system, it will get a component ID. This factory needs to know the Component ID assigned for each Component data type (the data_type() in the flatbuffer union). More...
 
corgi::ComponentId DataTypeToComponentId (unsigned int data_type)
 Get the Component Id for a given data type specifier. More...
 
unsigned int ComponentIdToDataType (corgi::ComponentId component_id)
 Get the data type specifier for a Component, given a Component ID. More...
 
const char * ComponentIdToTableName (corgi::ComponentId component_id)
 Get the table name for a Component, given a Component ID. More...
 
virtual bool SerializeEntity (corgi::EntityRef &entity, corgi::EntityManager *entity_manager, std::vector< uint8_t > *entity_serialized_output)
 Serialize an Entity into whatever binary type you are using for them. More...
 
virtual bool SerializeEntityList (const std::vector< std::vector< uint8_t >> &entity_definitions, std::vector< uint8_t > *entity_list_serialized)
 After you call SerializeEntity on a few Entities, you may call this method to put them into a proper list. More...
 
corgi::ComponentId max_component_id ()
 Get the maximum component ID. More...
 
bool debug_entity_creation () const
 Check if debug logging is enabled. More...
 
void set_debug_entity_creation (bool b)
 Enable debug logging during Entity creation. More...
 
virtual void LoadEntityData (const void *def, corgi::EntityManager *entity_manager, corgi::EntityRef &entity, bool is_prototype)
 Creates an Entity from the Entity definition, recursively building up from the prototypes. More...
 
void SetFlatbufferSchema (const char *binary_schema_filename)
 This factory and its subclasses need to know how to parse the Entity FlatBuffers using reflection. More...
 
const std::string & flatbuffer_binary_schema_data () const
 Get the FlatBuffer binary schema that you loaded with SetFlatbufferSchema(). More...
 
const std::unordered_map
< std::string, const void * > & 
prototype_data () const
 Get the map with all the current prototypes. More...
 
- Public Member Functions inherited from corgi::EntityFactoryInterface
virtual ~EntityFactoryInterface ()
 A destructor of the entity factory interface.
 

Additional Inherited Members

- Static Public Attributes inherited from corgi::component_library::EntityFactory
static const unsigned int kDataTypeNone = 0
 This is equivalent to the *_NONE value of the FlatBuffer union enum.
 
static const int kErrorLoadingEntities = -1
 The return value for LoadEntitiesFromFile and LoadEntityListFromMemory if the methods are unable to read the Entity list.
 

Member Function Documentation

virtual bool corgi::component_library::DefaultEntityFactory::CreateEntityDefinition ( const std::vector< const void * > &  component_data,
std::vector< uint8_t > *  entity_definition 
)
virtual

Handles building a single Entity definition flatbuffer from a list of an Entity's Component definitions.

Parameters
[in]component_dataA const reference to a std::vector that contains the list of the Entity's Component definitions, which can be indexed by Component ID.
[out]entity_definitionA vector of bytes to capture the output of the Entity definition FlatBuffer data.
Returns
Returns true if the Entity definition was successfully created. Otherwise, it returns false.

Implements corgi::component_library::EntityFactory.

virtual bool corgi::component_library::DefaultEntityFactory::CreateEntityList ( const std::vector< const void * > &  entity_defs,
std::vector< uint8_t > *  entity_list 
)
virtual

Handles building an Entity list flatbuffer from a collection of individual Entity flatbuffers.

Parameters
[in]entity_defsA const reference to a std::vector that contains all the Entity flatbuffers.
[out]entity_listA vector of bytes to capture the output of the Entity list FlatBuffer data.
Returns
Returns true if the Entity list was successfully created. Otherwise, it returns false.

Implements corgi::component_library::EntityFactory.

virtual bool corgi::component_library::DefaultEntityFactory::CreatePrototypeRequest ( const char *  prototype_name,
std::vector< uint8_t > *  request 
)
virtual

Creates an Entity list that contains a single Entity definition, which contains a single Component definition (a MetaDef with prototype set to the requested prototype name).

Parameters
[in]prototype_nameA C-string name of the prototype, which is used to set the prototype field in the MetaComponent.
[out]requestA vector of bytes to capture the output of the prototype request FlatBuffer data.
Returns
Returns true if the request was created successfully. Otherwise it returns false.

Implements corgi::component_library::EntityFactory.

virtual bool corgi::component_library::DefaultEntityFactory::ReadEntityDefinition ( const void *  entity_definition,
std::vector< const void * > *  component_defs 
)
virtual

Handles reading an Entity definition and extracting the individual Component data definitions.

Parameters
[in]entity_definitionA const void pointer to the Entity definition whose Component data definitions should be extracted.
[out]component_defsA vector that captures the output of the extracted Component data definitions.
Returns
Returns true if the entity_definition was parsed successfully. Otherwise it returns false.

Implements corgi::component_library::EntityFactory.

virtual bool corgi::component_library::DefaultEntityFactory::ReadEntityList ( const void *  entity_list,
std::vector< const void * > *  entity_defs 
)
virtual

Handles reading an Entity list and extracting the individual Entity data definitions.

Parameters
[in]entity_listA const void pointer to the start of the list of Entities.
[out]entity_defsA vector that captures the output of the extracted Entity data definitions.
Returns
returns true if the list was parsed successfully. Otherwise it returns false.

Implements corgi::component_library::EntityFactory.


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