Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions ecsact_rt_entt/runtime/ecsact_rt_entt_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<entt::entity>().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);
Expand Down
16 changes: 13 additions & 3 deletions ecsact_runtime/ecsact/runtime/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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__); \
Expand Down
5 changes: 5 additions & 0 deletions ecsact_runtime/ecsact/runtime/core.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down