From 50bc6745d8d1f0c5c0e6fbf5518be64bfb2aea83 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Sat, 30 Nov 2024 13:35:09 -0800 Subject: [PATCH 1/3] feat: new clone registry core function --- ecsact/runtime/core.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ecsact/runtime/core.h b/ecsact/runtime/core.h index c392b4c7..ad4fbc3a 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(void, ecsact_clone_registry) +( // + ecsact_registry_id registry, + const char* registry_name +); + /** * Destroy all entities */ @@ -295,6 +305,7 @@ ECSACT_CORE_API_FN(ecsact_stream_error, ecsact_stream) #else # define FOR_EACH_ECSACT_CORE_API_FN(fn, ...) \ fn(ecsact_create_registry, __VA_ARGS__); \ + fn(ecsact_clone_registry, __VA_ARGS__); \ fn(ecsact_destroy_registry, __VA_ARGS__); \ fn(ecsact_clear_registry, __VA_ARGS__); \ fn(ecsact_create_entity, __VA_ARGS__); \ From 6fa9a2eb54da479a9f17a9b8c61d14c75df3e667 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Sat, 30 Nov 2024 13:40:14 -0800 Subject: [PATCH 2/3] feat: add c++ wrapper --- ecsact/runtime/core.h | 2 +- ecsact/runtime/core.hh | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ecsact/runtime/core.h b/ecsact/runtime/core.h index ad4fbc3a..ca0b3356 100644 --- a/ecsact/runtime/core.h +++ b/ecsact/runtime/core.h @@ -54,7 +54,7 @@ ECSACT_CORE_API_FN(void, ecsact_destroy_registry) * Creates a new registry from an existing one with all its entities and * components intact. */ -ECSACT_CORE_API_FN(void, ecsact_clone_registry) +ECSACT_CORE_API_FN(ecsact_registry_id, ecsact_clone_registry) ( // ecsact_registry_id registry, const char* registry_name 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( // From 68586f0a2c2b6910da7f941bcfd83ef3ccc91a06 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Sat, 30 Nov 2024 13:41:14 -0800 Subject: [PATCH 3/3] fix: wrong order for clone --- ecsact/runtime/core.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ecsact/runtime/core.h b/ecsact/runtime/core.h index ca0b3356..c4da30b2 100644 --- a/ecsact/runtime/core.h +++ b/ecsact/runtime/core.h @@ -305,8 +305,8 @@ ECSACT_CORE_API_FN(ecsact_stream_error, ecsact_stream) #else # define FOR_EACH_ECSACT_CORE_API_FN(fn, ...) \ fn(ecsact_create_registry, __VA_ARGS__); \ - fn(ecsact_clone_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__); \