Entity Generator 1.1.0
Composable, deterministic entity generation for C++23
Loading...
Searching...
No Matches
dasmig::ext::entt_adapter Class Reference

Adapter that bridges entity-generator with EnTT. More...

#include <entt_adapter.hpp>

Public Member Functions

 entt_adapter (entt::registry &registry)
 Construct an adapter bound to an EnTT registry.
 
template<typename Component >
entt_adaptermap (const std::wstring &key, std::function< Component(const entity &)> mapper)
 Register a transform mapping from a generator key to an EnTT component.
 
template<typename Component >
entt_adaptermap (const std::wstring &key)
 Register a direct mapping (value type matches EnTT component type).
 
entt::entity spawn (const entity &src)
 Create an EnTT entity from a generated entity.
 
void spawn_into (entt::entity target, const entity &src)
 Emplace mapped components onto an existing EnTT entity.
 
std::vector< entt::entity > spawn_batch (const std::vector< entity > &sources)
 Create EnTT entities for a batch of generated entities.
 
entt_adapterclear_mappings ()
 Remove all registered mappings.
 

Detailed Description

Adapter that bridges entity-generator with EnTT.

Users register mappings from generator component keys to EnTT component types, then spawn() converts generated entities into EnTT entities with typed components.

Example
entt::registry registry;
dasmig::ext::entt_adapter adapter(registry);
adapter.map<Position>(L"pos", [](const dasmig::entity& e) {
return Position{ e.get<float>(L"x"), e.get<float>(L"y") };
});
auto entt_entity = adapter.spawn(gen.generate());
A generated entity holding component values in registration order.
Adapter that bridges entity-generator with EnTT.
See also
flecs_adapter

Definition at line 32 of file entt_adapter.hpp.

Constructor & Destructor Documentation

◆ entt_adapter()

dasmig::ext::entt_adapter::entt_adapter ( entt::registry &  registry)
inlineexplicit

Construct an adapter bound to an EnTT registry.

Parameters
registryThe EnTT registry to create entities in.

Definition at line 37 of file entt_adapter.hpp.

Member Function Documentation

◆ clear_mappings()

entt_adapter & dasmig::ext::entt_adapter::clear_mappings ( )
inline

Remove all registered mappings.

Returns
*this for chaining.

Definition at line 115 of file entt_adapter.hpp.

◆ map() [1/2]

template<typename Component >
entt_adapter & dasmig::ext::entt_adapter::map ( const std::wstring &  key)
inline

Register a direct mapping (value type matches EnTT component type).

Template Parameters
ComponentThe EnTT component type.
Parameters
keyGenerator component key whose value type is Component.
Returns
*this for chaining.

Definition at line 67 of file entt_adapter.hpp.

◆ map() [2/2]

template<typename Component >
entt_adapter & dasmig::ext::entt_adapter::map ( const std::wstring &  key,
std::function< Component(const entity &)>  mapper 
)
inline

Register a transform mapping from a generator key to an EnTT component.

The mapper receives the full generated entity so it can read any combination of keys. The component is only emplaced when the specified key is present in the generated entity.

Template Parameters
ComponentThe EnTT component type to emplace.
Parameters
keyGenerator component key to watch for.
mapperTransform function producing the EnTT component.
Returns
*this for chaining.

Definition at line 50 of file entt_adapter.hpp.

◆ spawn()

entt::entity dasmig::ext::entt_adapter::spawn ( const entity src)
inline

Create an EnTT entity from a generated entity.

Emplaces all mapped components whose keys are present.

Parameters
srcThe generated entity.
Returns
The new EnTT entity.

Definition at line 83 of file entt_adapter.hpp.

◆ spawn_batch()

std::vector< entt::entity > dasmig::ext::entt_adapter::spawn_batch ( const std::vector< entity > &  sources)
inline

Create EnTT entities for a batch of generated entities.

Parameters
sourcesA vector of generated entities.
Returns
A vector of new EnTT entities.

Definition at line 101 of file entt_adapter.hpp.

◆ spawn_into()

void dasmig::ext::entt_adapter::spawn_into ( entt::entity  target,
const entity src 
)
inline

Emplace mapped components onto an existing EnTT entity.

Parameters
targetThe pre-existing EnTT entity.
srcThe generated entity.

Definition at line 93 of file entt_adapter.hpp.


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