From 6e7f0f9f3113f5aa1176f1621723de463dab8358 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Thu, 5 Dec 2024 12:09:18 -0800 Subject: [PATCH] feat: registry hash method (#270) --- ecsact/runtime/core.h | 14 ++++++++++++++ ecsact/runtime/core.hh | 4 ++++ 2 files changed, 18 insertions(+) diff --git a/ecsact/runtime/core.h b/ecsact/runtime/core.h index c4da30b..76c9662 100644 --- a/ecsact/runtime/core.h +++ b/ecsact/runtime/core.h @@ -53,6 +53,9 @@ ECSACT_CORE_API_FN(void, ecsact_destroy_registry) /** * Creates a new registry from an existing one with all its entities and * components intact. + * + * 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) ( // @@ -60,6 +63,16 @@ ECSACT_CORE_API_FN(ecsact_registry_id, ecsact_clone_registry) const char* registry_name ); +/** + * Creates a hash of current state of the registry. The algorithm is + * implementation defined, but must represent both user state and internal + * state. + */ +ECSACT_CORE_API_FN(uint64_t, ecsact_hash_registry) +( // + ecsact_registry_id registry +); + /** * Destroy all entities */ @@ -307,6 +320,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_hash_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 0d45c31..34f062f 100644 --- a/ecsact/runtime/core.hh +++ b/ecsact/runtime/core.hh @@ -642,6 +642,10 @@ public: return cloned_registry; } + ECSACT_ALWAYS_INLINE auto hash() const -> uint64_t { + return ecsact_hash_registry(_id); + } + template requires(!std::is_empty_v) ECSACT_ALWAYS_INLINE auto get_component( //