4#ifndef DASMIG_EXT_FLECS_ADAPTER_HPP
5#define DASMIG_EXT_FLECS_ADAPTER_HPP
7#include "../entitygen.hpp"
52 template <
typename Component>
54 std::function<Component(
const entity&)> mapper)
56 _mappings.push_back({key,
57 [mapper = std::move(mapper)](flecs::entity target,
59 target.set<Component>(mapper(src));
68 template <
typename Component>
71 _mappings.push_back({key,
72 [key](flecs::entity target,
const entity& src) {
73 target.set<Component>(src.get<Component>(key));
85 auto target = _world.entity();
102 const std::vector<entity>& sources)
104 std::vector<flecs::entity> result;
105 result.reserve(sources.size());
106 for (
const auto& src : sources)
108 result.push_back(
spawn(src));
122 using set_fn = std::function<void(flecs::entity,
const entity&)>;
127 set_fn apply_component;
130 void apply(flecs::entity target,
const entity& src)
132 for (
const auto& m : _mappings)
136 m.apply_component(target, src);
141 flecs::world& _world;
142 std::vector<mapping> _mappings;
A generated entity holding component values in registration order.
bool has(const std::wstring &component_key) const
Check if a component value exists by key.
Adapter that bridges entity-generator with Flecs.
std::vector< flecs::entity > spawn_batch(const std::vector< entity > &sources)
Create Flecs entities for a batch of generated entities.
void spawn_into(flecs::entity target, const entity &src)
Set mapped components onto an existing Flecs entity.
flecs::entity spawn(const entity &src)
Create a Flecs entity from a generated entity.
flecs_adapter(flecs::world &world)
Construct an adapter bound to a Flecs world.
flecs_adapter & clear_mappings()
Remove all registered mappings.
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.
flecs_adapter & map(const std::wstring &key)
Register a direct mapping (value type matches Flecs component type).