4#ifndef DASMIG_EXT_ENTT_ADAPTER_HPP
5#define DASMIG_EXT_ENTT_ADAPTER_HPP
7#include "../entitygen.hpp"
8#include <entt/entt.hpp>
41 : _registry{registry} {}
52 template <
typename Component>
54 std::function<Component(
const entity&)> mapper)
56 _mappings.push_back({key,
57 [mapper = std::move(mapper)](entt::registry& reg,
60 reg.emplace<Component>(target, mapper(src));
69 template <
typename Component>
72 _mappings.push_back({key,
73 [key](entt::registry& reg, entt::entity target,
75 reg.emplace<Component>(target,
76 src.get<Component>(key));
88 auto target = _registry.create();
105 const std::vector<entity>& sources)
107 std::vector<entt::entity> result;
108 result.reserve(sources.size());
109 for (
const auto& src : sources)
111 result.push_back(
spawn(src));
125 using emplace_fn = std::function<void(entt::registry&, entt::entity,
134 void apply(entt::entity target,
const entity& src)
136 for (
const auto& m : _mappings)
140 m.emplace(_registry, target, src);
145 entt::registry& _registry;
146 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 EnTT.
entt_adapter & clear_mappings()
Remove all registered mappings.
entt_adapter & map(const std::wstring &key)
Register a direct mapping (value type matches EnTT component type).
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_adapter(entt::registry ®istry)
Construct an adapter bound to an EnTT registry.
entt_adapter & map(const std::wstring &key, std::function< Component(const entity &)> mapper)
Register a transform mapping from a generator key to an EnTT component.
entt::entity spawn(const entity &src)
Create an EnTT entity from a generated entity.