diff --git a/ecsact_rt_entt/runtime/ecsact_rt_entt_core.cc b/ecsact_rt_entt/runtime/ecsact_rt_entt_core.cc index b91f39b..17d585e 100644 --- a/ecsact_rt_entt/runtime/ecsact_rt_entt_core.cc +++ b/ecsact_rt_entt/runtime/ecsact_rt_entt_core.cc @@ -40,6 +40,22 @@ auto ecsact_clone_registry( // return cloned_reg_id; } +void ecsact_copy_registry( + ecsact_registry_id src_id, + ecsact_registry_id dst_id +) { + auto& src_reg = ecsact::entt::get_registry(src_id); + auto& dst_reg = ecsact::entt::get_registry(dst_id); + dst_reg = {}; + ecsact::entt::ecsact_init_registry_storage(dst_reg); + for(auto&& [entity_id] : src_reg.template storage().each()) { + [[maybe_unused]] auto cloned_entity_id = dst_reg.create(entity_id); + assert(cloned_entity_id == entity_id); + } + ecsact::entt::copy_components(src_reg, dst_reg); +} + + auto ecsact_hash_registry(ecsact_registry_id reg_id) -> uint64_t { auto& reg = ecsact::entt::get_registry(reg_id); return ecsact::entt::hash_registry(reg); diff --git a/ecsact_runtime/ecsact/runtime/core.h b/ecsact_runtime/ecsact/runtime/core.h index 2a0fa5f..8222ddc 100644 --- a/ecsact_runtime/ecsact/runtime/core.h +++ b/ecsact_runtime/ecsact/runtime/core.h @@ -52,10 +52,19 @@ ECSACT_CORE_API_FN(void, ecsact_destroy_registry) * If `ecsact_hash_registry` is defined then the cloned registry hash must * match the original registry. */ -ECSACT_CORE_API_FN(ecsact_registry_id, ecsact_clone_registry) -( // +ECSACT_CORE_API_FN(ecsact_registry_id, ecsact_clone_registry)( ecsact_registry_id registry, - const char* registry_name); + const char* registry_name +); + +/** + * Copies all entities and components from a source registry to a destination + * registry. The destination registry is cleared before copy. + */ +ECSACT_CORE_API_FN(void, ecsact_copy_registry)( + ecsact_registry_id src_registry, + ecsact_registry_id dest_registry +); /** * Creates a hash of current state of the registry. The algorithm is @@ -295,6 +304,7 @@ ECSACT_CORE_API_FN(ecsact_stream_error, ecsact_stream) fn(ecsact_create_registry, __VA_ARGS__); \ fn(ecsact_destroy_registry, __VA_ARGS__); \ fn(ecsact_clone_registry, __VA_ARGS__); \ + fn(ecsact_copy_registry, __VA_ARGS__); \ fn(ecsact_hash_registry, __VA_ARGS__); \ fn(ecsact_clear_registry, __VA_ARGS__); \ fn(ecsact_create_entity, __VA_ARGS__); \ diff --git a/ecsact_runtime/ecsact/runtime/core.hh b/ecsact_runtime/ecsact/runtime/core.hh index f35a200..2d9fd9e 100644 --- a/ecsact_runtime/ecsact/runtime/core.hh +++ b/ecsact_runtime/ecsact/runtime/core.hh @@ -648,6 +648,11 @@ public: return cloned_registry; } + ECSACT_ALWAYS_INLINE auto copy_to(const registry& dest) const -> void { + ecsact_copy_registry(_id, dest.id()); + } + + ECSACT_ALWAYS_INLINE auto hash() const -> uint64_t { return ecsact_hash_registry(_id); }