1#ifndef DASMIG_EXT_FLECS_ADAPTER_HPP
2#define DASMIG_EXT_FLECS_ADAPTER_HPP
4#include "../entitygen.hpp"
49 template <
typename Component>
51 std::function<Component(
const entity&)> mapper)
53 _mappings.push_back({key,
54 [mapper = std::move(mapper)](flecs::entity target,
56 target.set<Component>(mapper(src));
65 template <
typename Component>
68 _mappings.push_back({key,
69 [key](flecs::entity target,
const entity& src) {
70 target.set<Component>(src.get<Component>(key));
82 auto target = _world.entity();
99 const std::vector<entity>& sources)
101 std::vector<flecs::entity> result;
102 result.reserve(sources.size());
103 for (
const auto& src : sources)
105 result.push_back(
spawn(src));
119 using set_fn = std::function<void(flecs::entity,
const entity&)>;
124 set_fn apply_component;
127 void apply(flecs::entity target,
const entity& src)
129 for (
const auto& m : _mappings)
133 m.apply_component(target, src);
138 flecs::world& _world;
139 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).