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

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

#include <flecs_adapter.hpp>

Public Member Functions

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

Detailed Description

Adapter that bridges entity-generator with Flecs.

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

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

Definition at line 32 of file flecs_adapter.hpp.

Constructor & Destructor Documentation

◆ flecs_adapter()

dasmig::ext::flecs_adapter::flecs_adapter ( flecs::world &  world)
inlineexplicit

Construct an adapter bound to a Flecs world.

Parameters
worldThe Flecs world to create entities in.

Definition at line 37 of file flecs_adapter.hpp.

Member Function Documentation

◆ clear_mappings()

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

Remove all registered mappings.

Returns
*this for chaining.

Definition at line 112 of file flecs_adapter.hpp.

◆ map() [1/2]

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

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

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

Definition at line 66 of file flecs_adapter.hpp.

◆ map() [2/2]

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

Register a transform mapping from a generator key to a Flecs component.

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

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

Definition at line 50 of file flecs_adapter.hpp.

◆ spawn()

flecs::entity dasmig::ext::flecs_adapter::spawn ( const entity src)
inline

Create a Flecs entity from a generated entity.

Sets all mapped components whose keys are present.

Parameters
srcThe generated entity.
Returns
The new Flecs entity.

Definition at line 80 of file flecs_adapter.hpp.

◆ spawn_batch()

std::vector< flecs::entity > dasmig::ext::flecs_adapter::spawn_batch ( const std::vector< entity > &  sources)
inline

Create Flecs entities for a batch of generated entities.

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

Definition at line 98 of file flecs_adapter.hpp.

◆ spawn_into()

void dasmig::ext::flecs_adapter::spawn_into ( flecs::entity  target,
const entity src 
)
inline

Set mapped components onto an existing Flecs entity.

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

Definition at line 90 of file flecs_adapter.hpp.


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