Skip to content

Commit

Permalink
feat: registry hash method
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy committed Dec 5, 2024
1 parent 732177c commit 9b566b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
14 changes: 14 additions & 0 deletions ecsact/runtime/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,26 @@ 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)
( //
ecsact_registry_id 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
*/
Expand Down Expand Up @@ -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__); \
Expand Down
4 changes: 4 additions & 0 deletions ecsact/runtime/core.hh
Original file line number Diff line number Diff line change
Expand Up @@ -642,6 +642,10 @@ public:
return cloned_registry;
}

ECSACT_ALWAYS_INLINE auto hash() const -> uint64_t {
return ecsact_hash_registry(_id);
}

template<typename Component, typename... AssocFields>
requires(!std::is_empty_v<Component>)
ECSACT_ALWAYS_INLINE auto get_component( //
Expand Down

0 comments on commit 9b566b1

Please sign in to comment.