Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: registry hash method #270

Merged
merged 1 commit into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading