Skip to content

Commit

Permalink
feat: new clone registry core function (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
zaucy authored Dec 5, 2024
1 parent d7de0cc commit 732177c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions ecsact/runtime/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(ecsact_registry_id, ecsact_clone_registry)
( //
ecsact_registry_id registry,
const char* registry_name
);

/**
* Destroy all entities
*/
Expand Down Expand Up @@ -296,6 +306,7 @@ ECSACT_CORE_API_FN(ecsact_stream_error, ecsact_stream)
# define FOR_EACH_ECSACT_CORE_API_FN(fn, ...) \
fn(ecsact_create_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__); \
Expand Down
7 changes: 7 additions & 0 deletions ecsact/runtime/core.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename Component, typename... AssocFields>
requires(!std::is_empty_v<Component>)
ECSACT_ALWAYS_INLINE auto get_component( //
Expand Down

0 comments on commit 732177c

Please sign in to comment.