Adapter that bridges entity-generator with Flecs.
More...
#include <flecs_adapter.hpp>
|
| | flecs_adapter (flecs::world &world) |
| | Construct an adapter bound to a Flecs world.
|
| |
| template<typename Component > |
| flecs_adapter & | map (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_adapter & | map (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_adapter & | clear_mappings () |
| | Remove all registered mappings.
|
| |
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;
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.
◆ flecs_adapter()
| dasmig::ext::flecs_adapter::flecs_adapter |
( |
flecs::world & |
world | ) |
|
|
inlineexplicit |
Construct an adapter bound to a Flecs world.
- Parameters
-
| world | The Flecs world to create entities in. |
Definition at line 37 of file flecs_adapter.hpp.
◆ clear_mappings()
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
-
| Component | The Flecs component type. |
- Parameters
-
| key | Generator 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
-
| Component | The Flecs component type. |
- Parameters
-
| key | Generator component key to watch for. |
| mapper | Transform 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
-
- 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
-
| sources | A 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
-
| target | The pre-existing Flecs entity. |
| src | The generated entity. |
Definition at line 90 of file flecs_adapter.hpp.
The documentation for this class was generated from the following file: