1#ifndef DASMIG_EXT_ENTT_ADAPTER_HPP
2#define DASMIG_EXT_ENTT_ADAPTER_HPP
4#include "../entitygen.hpp"
5#include <entt/entt.hpp>
38 : _registry{registry} {}
49 template <
typename Component>
51 std::function<Component(
const entity&)> mapper)
53 _mappings.push_back({key,
54 [mapper = std::move(mapper)](entt::registry& reg,
57 reg.emplace<Component>(target, mapper(src));
66 template <
typename Component>
69 _mappings.push_back({key,
70 [key](entt::registry& reg, entt::entity target,
72 reg.emplace<Component>(target,
73 src.get<Component>(key));
85 auto target = _registry.create();
102 const std::vector<entity>& sources)
104 std::vector<entt::entity> result;
105 result.reserve(sources.size());
106 for (
const auto& src : sources)
108 result.push_back(
spawn(src));
122 using emplace_fn = std::function<void(entt::registry&, entt::entity,
131 void apply(entt::entity target,
const entity& src)
133 for (
const auto& m : _mappings)
137 m.emplace(_registry, target, src);
142 entt::registry& _registry;
143 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.