From 732177c98ba0603b38c46323c8a13102dabd0d85 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Thu, 5 Dec 2024 11:58:20 -0800 Subject: [PATCH] feat: new clone registry core function (#269) --- ecsact/runtime/core.h | 11 +++++++++++ ecsact/runtime/core.hh | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/ecsact/runtime/core.h b/ecsact/runtime/core.h index c392b4c7..c4da30b2 100644 --- a/ecsact/runtime/core.h +++ b/ecsact/runtime/core.h @@ -50,6 +50,16 @@ ECSACT_CORE_API_FN(void, ecsact_destroy_registry) ecsact_registry_id registry ); +/** + * Creates a new registry from an existing one with all its entities and + * components intact. + */ +ECSACT_CORE_API_FN(ecsact_registry_id, ecsact_clone_registry) +( // + ecsact_registry_id registry, + const char* registry_name +); + /** * Destroy all entities */ @@ -296,6 +306,7 @@ ECSACT_CORE_API_FN(ecsact_stream_error, ecsact_stream) # define FOR_EACH_ECSACT_CORE_API_FN(fn, ...) \ fn(ecsact_create_registry, __VA_ARGS__); \ fn(ecsact_destroy_registry, __VA_ARGS__); \ + fn(ecsact_clone_registry, __VA_ARGS__); \ fn(ecsact_clear_registry, __VA_ARGS__); \ fn(ecsact_create_entity, __VA_ARGS__); \ fn(ecsact_ensure_entity, __VA_ARGS__); \ diff --git a/ecsact/runtime/core.hh b/ecsact/runtime/core.hh index b427303e..0d45c313 100644 --- a/ecsact/runtime/core.hh +++ b/ecsact/runtime/core.hh @@ -635,6 +635,13 @@ public: return ecsact_create_entity(_id); } + ECSACT_ALWAYS_INLINE auto clone(const char* name) const -> registry { + auto cloned_registry_id = ecsact_clone_registry(_id, name); + auto cloned_registry = registry{cloned_registry_id}; + cloned_registry._owned = true; + return cloned_registry; + } + template requires(!std::is_empty_v) ECSACT_ALWAYS_INLINE auto get_component( //