galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
galaxy::meta::EntityFactory Class Referencefinal

Handles entity meta (de)serialization. More...

#include <EntityFactory.hpp>

+ Collaboration diagram for galaxy::meta::EntityFactory:

Classes

struct  SerializationData
 Data needed to serialize an entity. More...
 

Public Member Functions

template<valid_component ToValidate, valid_component... Dependencies>
void register_dependencies ()
 Defines a dependency validation for components.
 
template<valid_component Component>
void register_component (const std::string &name)
 Registers a component definition.
 
void json_factory (const std::string &type, const entt::entity entity, entt::registry &registry, const nlohmann::json &json)
 Construct component from json and assign to provided entity and registry.
 
entt::any any_from_json (const std::string &type, const nlohmann::json &json)
 Construct an entt::any from a json object.
 
nlohmann::json serialize_entity (const entt::entity entity, entt::registry &registry)
 Serialise a single entity.
 
entt::entity deserialize_entity (const nlohmann::json &json, entt::registry &registry)
 Create an entity from a JSON object.
 
const std::string & get_type (const entt::id_type id)
 Get a string representation of an entity type id.
 
entt::id_type get_typeid (const std::string &name)
 Get an entity type id from a string.
 
Validationsget_validations ()
 Get a list of configurations.
 
const std::vector< entt::id_type > & get_validation_list () const
 Get a list of validations to run.
 

Private Types

using Validations = ankerl::unordered_dense::map<entt::id_type, std::move_only_function<bool(const entt::entity, entt::registry&)>>
 
using ComponentJSONFactory = ankerl::unordered_dense::map<std::string, std::move_only_function<void(const entt::entity, entt::registry&, const nlohmann::json&)>>
 
using AnyJSONFactory = ankerl::unordered_dense::map<std::string, std::move_only_function<entt::any(const nlohmann::json&)>>
 
using SerializeFactory = ankerl::unordered_dense::map<std::string, std::move_only_function<EntityFactory::SerializationData(void*)>>
 

Private Attributes

ankerl::unordered_dense::map< entt::id_type, std::string > m_id_to_name
 Maps an entt type id to a string.
 
ankerl::unordered_dense::map< std::string, entt::id_type > m_name_to_id
 Maps a string name to an entt id.
 
ComponentJSONFactory m_json_factory
 Used to allow for component creation from json.
 
AnyJSONFactory m_json_any_factory
 Creates an entt::any from a json component data.
 
SerializeFactory m_serialize_factory
 Serializes an entity from a void* pointer.
 
Validations m_validations
 Stores validation configurations.
 
std::vector< entt::id_type > m_validations_to_run
 Validations to run upon request.
 

Detailed Description

Handles entity meta (de)serialization.

Definition at line 26 of file EntityFactory.hpp.

Member Typedef Documentation

◆ Validations

using galaxy::meta::EntityFactory::Validations = ankerl::unordered_dense::map<entt::id_type, std::move_only_function<bool(const entt::entity, entt::registry&)>>
private

Definition at line 44 of file EntityFactory.hpp.

◆ ComponentJSONFactory

using galaxy::meta::EntityFactory::ComponentJSONFactory = ankerl::unordered_dense::map<std::string, std::move_only_function<void(const entt::entity, entt::registry&, const nlohmann::json&)>>
private

Definition at line 45 of file EntityFactory.hpp.

◆ AnyJSONFactory

using galaxy::meta::EntityFactory::AnyJSONFactory = ankerl::unordered_dense::map<std::string, std::move_only_function<entt::any(const nlohmann::json&)>>
private

Definition at line 46 of file EntityFactory.hpp.

◆ SerializeFactory

using galaxy::meta::EntityFactory::SerializeFactory = ankerl::unordered_dense::map<std::string, std::move_only_function<EntityFactory::SerializationData(void*)>>
private

Definition at line 47 of file EntityFactory.hpp.

Member Function Documentation

◆ register_dependencies()

template<valid_component ToValidate, valid_component... Dependencies>
void galaxy::meta::EntityFactory::register_dependencies ( )
inline

Defines a dependency validation for components.

Template Parameters
ToValidateThe component to validate.
DependenciesThe components required by ToValidate.

Definition at line 188 of file EntityFactory.hpp.

◆ register_component()

template<valid_component Component>
void galaxy::meta::EntityFactory::register_component ( const std::string & name)
inline

Registers a component definition.

Template Parameters
ComponentA valid component type is required. Must be move assignable/constructible and a class with a json constructor.
Parameters
nameName of component class in string format i.e. "Transform" or "Tag".

Definition at line 215 of file EntityFactory.hpp.

◆ json_factory()

void galaxy::meta::EntityFactory::json_factory ( const std::string & type,
const entt::entity entity,
entt::registry & registry,
const nlohmann::json & json )

Construct component from json and assign to provided entity and registry.

Parameters
typeType of component as a string.
entityEntity to assign component to.
registryRegistry that the entity belong to and where to create the component.
jsonComponent data as a json object.

Definition at line 23 of file EntityFactory.cpp.

+ Here is the caller graph for this function:

◆ any_from_json()

entt::any galaxy::meta::EntityFactory::any_from_json ( const std::string & type,
const nlohmann::json & json )
nodiscard

Construct an entt::any from a json object.

Parameters
typeComponent type as a string.
jsonComponent data as a json object.
Returns
Newly constructed entt::any.

Definition at line 35 of file EntityFactory.cpp.

◆ serialize_entity()

nlohmann::json galaxy::meta::EntityFactory::serialize_entity ( const entt::entity entity,
entt::registry & registry )
nodiscard

Serialise a single entity.

Parameters
entityEntity to serialize.
registryRegistry entity belongs to.
Returns
JSON entity data.

Definition at line 40 of file EntityFactory.cpp.

+ Here is the call graph for this function:

◆ deserialize_entity()

entt::entity galaxy::meta::EntityFactory::deserialize_entity ( const nlohmann::json & json,
entt::registry & registry )

Create an entity from a JSON object.

If your using this make sure you have called register_component().

Parameters
jsonPreloaded JSON object.
registryRegistry entity belongs to.
Returns
Created entity, or entt::null if failed.

Definition at line 60 of file EntityFactory.cpp.

+ Here is the call graph for this function:

◆ get_type()

const std::string & galaxy::meta::EntityFactory::get_type ( const entt::id_type id)
nodiscard

Get a string representation of an entity type id.

Parameters
idEntt meta type id of a component.
Returns
String name of component.

Definition at line 77 of file EntityFactory.cpp.

+ Here is the caller graph for this function:

◆ get_typeid()

entt::id_type galaxy::meta::EntityFactory::get_typeid ( const std::string & name)
nodiscard

Get an entity type id from a string.

Parameters
nameString name of component.
Returns
Entt meta type id of a component.

Definition at line 82 of file EntityFactory.cpp.

◆ get_validations()

EntityFactory::Validations & galaxy::meta::EntityFactory::get_validations ( )
nodiscard

Get a list of configurations.

Returns
Reference to validations map.

Definition at line 87 of file EntityFactory.cpp.

◆ get_validation_list()

const std::vector< entt::id_type > & galaxy::meta::EntityFactory::get_validation_list ( ) const
nodiscard

Get a list of validations to run.

Returns
Const reference to list of validations to run.

Definition at line 92 of file EntityFactory.cpp.

Member Data Documentation

◆ m_id_to_name

ankerl::unordered_dense::map<entt::id_type, std::string> galaxy::meta::EntityFactory::m_id_to_name
private

Maps an entt type id to a string.

Definition at line 154 of file EntityFactory.hpp.

◆ m_name_to_id

ankerl::unordered_dense::map<std::string, entt::id_type> galaxy::meta::EntityFactory::m_name_to_id
private

Maps a string name to an entt id.

Definition at line 159 of file EntityFactory.hpp.

◆ m_json_factory

ComponentJSONFactory galaxy::meta::EntityFactory::m_json_factory
private

Used to allow for component creation from json.

Definition at line 164 of file EntityFactory.hpp.

◆ m_json_any_factory

AnyJSONFactory galaxy::meta::EntityFactory::m_json_any_factory
private

Creates an entt::any from a json component data.

Definition at line 169 of file EntityFactory.hpp.

◆ m_serialize_factory

SerializeFactory galaxy::meta::EntityFactory::m_serialize_factory
private

Serializes an entity from a void* pointer.

Definition at line 174 of file EntityFactory.hpp.

◆ m_validations

Validations galaxy::meta::EntityFactory::m_validations
private

Stores validation configurations.

Definition at line 179 of file EntityFactory.hpp.

◆ m_validations_to_run

std::vector<entt::id_type> galaxy::meta::EntityFactory::m_validations_to_run
private

Validations to run upon request.

Definition at line 184 of file EntityFactory.hpp.


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