Skip to content

Commit 6e7f0f9

Browse files
authored
feat: registry hash method (#270)
1 parent 732177c commit 6e7f0f9

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

ecsact/runtime/core.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,26 @@ ECSACT_CORE_API_FN(void, ecsact_destroy_registry)
5353
/**
5454
* Creates a new registry from an existing one with all its entities and
5555
* components intact.
56+
*
57+
* If `ecsact_hash_registry` is defined then the cloned registry hash must
58+
* match the original registry.
5659
*/
5760
ECSACT_CORE_API_FN(ecsact_registry_id, ecsact_clone_registry)
5861
( //
5962
ecsact_registry_id registry,
6063
const char* registry_name
6164
);
6265

66+
/**
67+
* Creates a hash of current state of the registry. The algorithm is
68+
* implementation defined, but must represent both user state and internal
69+
* state.
70+
*/
71+
ECSACT_CORE_API_FN(uint64_t, ecsact_hash_registry)
72+
( //
73+
ecsact_registry_id registry
74+
);
75+
6376
/**
6477
* Destroy all entities
6578
*/
@@ -307,6 +320,7 @@ ECSACT_CORE_API_FN(ecsact_stream_error, ecsact_stream)
307320
fn(ecsact_create_registry, __VA_ARGS__); \
308321
fn(ecsact_destroy_registry, __VA_ARGS__); \
309322
fn(ecsact_clone_registry, __VA_ARGS__); \
323+
fn(ecsact_hash_registry, __VA_ARGS__); \
310324
fn(ecsact_clear_registry, __VA_ARGS__); \
311325
fn(ecsact_create_entity, __VA_ARGS__); \
312326
fn(ecsact_ensure_entity, __VA_ARGS__); \

ecsact/runtime/core.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,10 @@ public:
642642
return cloned_registry;
643643
}
644644

645+
ECSACT_ALWAYS_INLINE auto hash() const -> uint64_t {
646+
return ecsact_hash_registry(_id);
647+
}
648+
645649
template<typename Component, typename... AssocFields>
646650
requires(!std::is_empty_v<Component>)
647651
ECSACT_ALWAYS_INLINE auto get_component( //

0 commit comments

Comments
 (0)