|
CORGI
An open source project by
FPL.
|
An EntityFactory builds Entities based on prototypes, using FlatBuffers to specify the raw data for Entities. More...
#include <entity_factory.h>
Inherits corgi::EntityFactoryInterface.
Inherited by corgi::component_library::DefaultEntityFactory.
An EntityFactory builds Entities based on prototypes, using FlatBuffers to specify the raw data for Entities.
Public Member Functions | |
| 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 bool | ReadEntityList (const void *entity_list, std::vector< const void * > *entity_defs)=0 |
| 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)=0 |
| 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)=0 |
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)=0 |
| 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)=0 |
| Handles building an Entity list flatbuffer from a collection of individual Entity flatbuffers. 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. | |
Static Public Attributes | |
| 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. | |
| bool corgi::component_library::EntityFactory::AddEntityLibrary | ( | const char * | entity_library_file | ) |
|
inline |
|
inline |
|
pure virtual |
Handles building a single Entity definition flatbuffer from a list of an Entity's Component definitions.
| [in] | component_data | A 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_definition | A vector to capture the output of the Entity definition. |
true if the Entity definition was successfully created. Otherwise, it returns false. Implemented in corgi::component_library::DefaultEntityFactory.
|
virtual |
Initialize an Entity from an Entity definition.
LoadRawEntityList for each Entity definition.| [in] | data | A void pointer to the data to create an Entity from. |
| [in,out] | entity_manager | An EntityManager pointer to the EntityManager that should load the Entity from the data. |
Implements corgi::EntityFactoryInterface.
|
virtual |
Initialize an entity from a given prototype.
| [in] | prototype_name | A C-string containing the name of the prototype to initialize the Entity with. |
| [in,out] | entity_manager | An EntityManager pointer to the EntityManager that should create the initialized Entity. |
|
pure virtual |
Handles building an Entity list flatbuffer from a collection of individual Entity flatbuffers.
| [in] | entity_defs | A const reference to a std::vector that contains all the Entity flatbuffers. |
| [out] | entity_list | A vector to capture the output of the Entity list. |
true if the Entity list was successfully created. Otherwise, it returns false. Implemented in corgi::component_library::DefaultEntityFactory.
|
pure 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).
| [in] | prototype_name | A C-string name of the prototype, which is used to set the prototype field in the MetaComponent. |
| [out] | request | A vector to capture the output of the prototype request. |
true if the request was created successfully. Otherwise it returns false. Implemented in corgi::component_library::DefaultEntityFactory.
|
inline |
|
inline |
Check if debug logging is enabled.
true if debug logging is enabled. Otherwise, it returns false.
|
inline |
Get the FlatBuffer binary schema that you loaded with SetFlatbufferSchema().
|
virtual |
Load Entities from a given Entity list file.
| [in] | filename | A UTF-8 C-string representing the filename of the Entity list file to load the Entities from. |
| [in,out] | entity_manager | An EntityManager pointer to the EntityManager that should load all the Entities from filename. |
kErrorLoadingEntities if there was en error.
|
virtual |
Creates an Entity from the Entity definition, recursively building up from the prototypes.
| [in] | def | A const void pointer to the Entity definition that will be used to build the prototypes. |
| [in,out] | entity_manager | A pointer to the EntityManager that the Entity will be created with. |
| [out] | entity | A reference to the Entity that is being created. |
| [in] | is_prototype | A bool determining if this is a prototype. |
| int corgi::component_library::EntityFactory::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.
LoadEntitiesFromFile to do a lot of the work actually loading the Entities.| [in] | raw_entity_list | A void pointer to the Entity list. |
| [in,out] | entity_manager | An EntityManager pointer to the EntityManager that should load all the Entities from memory. |
| [out] | entities_loaded | An optional parameter to obtain the list of the loaded Entities. Pass in a pointer to a std::vector of EntityRefs to capture this output. Otherwise, pass in NULL to ignore this parameter. |
kErrorLoadingEntities if there was an error.
|
inline |
Get the maximum component ID.
| void corgi::component_library::EntityFactory::OverrideCachedFile | ( | const char * | filename, |
| std::unique_ptr< std::string > | new_data | ||
| ) |
Override a cached file with data from memory that will persist until exit.
| [in] | filename | A UTF-8 C-string representing the filename of the cached file whose data should be overridden. |
| [in] | new_data | A std::unique_ptr that points to a std::string of data to override the cached file with. |
|
inline |
Get the map with all the current prototypes.
|
pure virtual |
Handles reading an Entity definition and extracting the individual Component data definitions.
In your output, you should index component_defs by component ID, and any Components not specified by this Entity's definition should be set to nullptr.
| [in] | entity_definition | A const void pointer to the Entity definition whose Component data definitions should be extracted. |
| [out] | component_defs | A vector that captures the output of the extracted Component data definitions. |
true if the entity_definition was parsed successfully. Otherwise it returns false. Implemented in corgi::component_library::DefaultEntityFactory.
|
pure virtual |
Handles reading an Entity list and extracting the individual Entity data definitions.
| [in] | entity_list | A const void pointer to the start of the list of Entities. |
| [out] | entity_defs | A vector that captures the output of the extracted entity data definitions. |
true if the list was parsed successfully. Otherwise it returns false. Implemented in corgi::component_library::DefaultEntityFactory.
|
virtual |
Serialize an Entity into whatever binary type you are using for them.
CreateEntityDefinition(), which you implement, to do the work.| [in] | entity | The Entity that should be serialized. |
| [in] | entity_manager | The EntityManager responsible for the Entity that should be serialized. |
| [out] | entity_serialized_output | A vector to capture the output of the Entity definition. |
true if the Entity definition was successfully created. Otherwise, it returns false.
|
virtual |
After you call SerializeEntity on a few Entities, you may call this method to put them into a proper list.
CreateEntityList(), which you implement.| [in] | entity_definitions | A reference to a vector list of Entity definitions (vector<uint8_t>) that should be put into a proper Entity list. |
| [out] | entity_list_serialized | A vector to capture the output of the Entity list. |
true if the Entity list was successfully created. Otherwise, it returns false.
|
inline |
Enable debug logging during Entity creation.
| [in] | b | A bool determining if logging should be enabled. |
| void corgi::component_library::EntityFactory::SetComponentType | ( | corgi::ComponentId | component_id, |
| unsigned int | data_type, | ||
| const char * | table_name | ||
| ) |
| void corgi::component_library::EntityFactory::SetFlatbufferSchema | ( | const char * | binary_schema_filename | ) |
| bool corgi::component_library::EntityFactory::WillBeKeptInMemory | ( | const void * | pointer | ) |
Check if the given pointer points to something that will be kept in memory for the lifetime of the EntityFactory.
| [in] | pointer | A void pointer that should be checked if its data will be kept in memory. |
true if the given pointer points to something that will be kept in memory for the of the EntityFactory. Otherwise it returns false.