64template<
typename Registry>
65void remove_all_components(entt::basic_handle<Registry>
handle)
67 auto& registry = *
handle.registry();
70 for(
auto [
id, storage] : registry.storage())
76auto get_scene_registry_impl() -> std::vector<scene*>&
78 static std::vector<scene*> scenes;
82void register_scene(
scene* scn)
84 auto& scenes = get_scene_registry_impl();
85 scenes.emplace_back(scn);
88void unregister_scene(
scene* scn)
90 auto& scenes = get_scene_registry_impl();
91 scenes.erase(std::remove(scenes.begin(), scenes.end(), scn), scenes.end());
95template<
typename ...Ts>
96void destroy_dependent_components(entt::registry& r, entt::entity e)
101template<
typename ...Ts>
102void destroy_dependent_components_recursive(entt::registry& r, entt::entity e)
108 destroy_dependent_components<Ts...>(
r,
e);
111 auto transform =
r.try_get<transform_component>(
e);
114 for(
auto child :
transform->get_children())
116 destroy_dependent_components_recursive<Ts...>(
r, child);
121auto on_load_callback(hpp::span<const entt::handle> entities) ->
void
123 if(!entities.empty())
127 auto& play = ctx.get_cached<play_mode>();
129 if(play.is_simulation_running())
131 auto& rsys = ctx.get_cached<rendering_system>();
132 auto& ssys = ctx.get_cached<script_system>();
135 rsys.on_play_begin(entities, dt);
136 ssys.on_play_begin(entities);
145 return get_scene_registry_impl();
151 register_scene(
this);
153 registry = std::make_unique<entt::registry>();
197 unregister_scene(
this);
240 return instantiate_out(*registry, pfb, e, call_callbacks);
276 auto load_callback_override = [&](hpp::span<const entt::handle> entities) ->
void
278 if(parent && !entities.empty())
280 auto e = entities[0];
288 APPLOG_ERROR(
"Entity not found in instantiate callback");
295 on_load_callback(entities);
307 entt::handle ent(r, r.create());
315 transform.set_parent(parent,
false);
323 if(target_uuid.is_nil())
332 return entt::handle(registry, e);
340 return ::unravel::find_entity_by_uuid(*registry, target_uuid);
350 for(
auto scene : get_all_scenes())
362 return create_entity(*registry,
tag, parent);
365void scene::clone_entity(entt::handle& clone_to, entt::handle clone_from,
bool keep_parent,
bool call_callbacks)
369 auto load_callback_override = [&](hpp::span<const entt::handle> entities) ->
void
380 auto parent = clone_from_component.
get_parent();
389 on_load_callback(entities);
402 auto* reg = clone_from.registry();
403 entt::handle clone_to(*reg, reg->create());
404 clone_entity(clone_to, clone_from, keep_parent, call_callbacks);
424 remove_all_components(
handle);
430 entt::handle
handle(*registry, e);
436 entt::const_handle
handle(*registry, e);
448 if (id_comp && id_comp->id == target_uuid)
457 for (
auto child : transform->get_children())
459 auto found = find_entity_by_prefab_uuid(child, target_uuid);
static void on_create_component(entt::registry &r, entt::entity e)
Called when the component is created.
static void on_destroy_component(entt::registry &r, entt::entity e)
Called when the component is destroyed.
static void on_create_component(entt::registry &r, entt::entity e)
Called when the component is created.
static void on_destroy_component(entt::registry &r, entt::entity e)
Called when the component is destroyed.
static void on_destroy_component(entt::registry &r, entt::entity e)
static void on_create_component(entt::registry &r, entt::entity e)
static void on_destroy_component(entt::registry &r, entt::entity e)
static void on_create_component(entt::registry &r, entt::entity e)
static void on_destroy_component(entt::registry &r, entt::entity e)
Called when a physics component is destroyed.
static void on_create_component(entt::registry &r, entt::entity e)
Called when a physics component is created.
static void on_create_cc_component(entt::registry &r, entt::entity e)
static void on_destroy_cc_component(entt::registry &r, entt::entity e)
Class that contains core data for audio listeners. There can only be one instance of it per scene.
static void on_destroy_component(entt::registry &r, entt::entity e)
Called when the component is destroyed.
static void on_create_component(entt::registry &r, entt::entity e)
Called when the component is created.
std::chrono::duration< float > delta_t
#define APPLOG_ERROR(...)
bgfx::Transform transform
void clone_scene_from_stream(const scene &src_scene, scene &dst_scene)
auto on_destroy(entt::registry ®) -> decltype(auto)
void pop_on_load_callbacks()
auto on_update(entt::registry ®) -> decltype(auto)
auto on_construct(entt::registry ®) -> decltype(auto)
auto load_from_prefab_out(const asset_handle< prefab > &pfb, entt::registry ®istry, entt::handle &obj) -> bool
auto on_load(entt::registry ®) -> typename on_load_bus< T >::sink_t
auto find_entity_by_uuid(entt::registry ®istry, const hpp::uuid &target_uuid) -> entt::handle
Finds an entity by id_component UUID in a registry (no scene wrapper required).
void push_on_load_callbacks(const post_load_callbacks &callbacks)
auto load_from_prefab(const asset_handle< prefab > &pfb, entt::registry ®istry) -> entt::handle
void clone_entity_from_stream(entt::const_handle src_obj, entt::handle &dst_obj)
#define APP_SCOPE_PERF_OWNED(name)
Create a scoped performance timer that records to the timeline profiler. Only accepts string literals...
#define APP_SCOPE_PERF(name_literal)
Create a scoped performance timer that records to the timeline profiler. Only accepts string literals...
Thread-safe handle to an asset.
entt::registry * registry
auto resolve() const -> entt::handle
static auto context() -> rtti::context &
hpp::uuid id
The unique identifier for the entity.
Component that provides a unique identifier (UUID) for an entity.
Component that provides a layer mask for an entity.
Component that provides a unique identifier (UUID) for a prefab.
static void on_update_component(entt::registry &r, entt::entity e)
Called when the component is updated.
static void on_create_component(entt::registry &r, entt::entity e)
Called when the component is created.
static void on_destroy_component(entt::registry &r, entt::entity e)
Called when the component is destroyed.
Represents a scene in the ACE framework, managing entities and their relationships.
auto find_entity_by_uuid(const hpp::uuid &target_uuid) const -> entt::handle
Finds an entity by UUID in the scene.
void clear_entity(entt::handle &handle)
void reload(bool call_callbacks=true)
Reloads the scene from the source prefab asset.
auto instantiate_out(const asset_handle< prefab > &pfb, entt::handle &, bool call_callbacks=true) -> bool
Instantiates a prefab in the scene.
asset_handle< scene_prefab > source
The source prefab asset handle for the scene.
~scene()
Destroys the scene and cleans up resources.
auto load_from(const asset_handle< scene_prefab > &pfb, bool call_callbacks=true) -> bool
Loads a scene from a prefab asset.
static auto get_all_scenes() -> const std::vector< scene * > &
auto clone_entity(entt::handle clone_from, bool keep_parent=true, bool call_callbacks=true) -> entt::handle
Clones an existing entity in the scene.
auto instantiate(const asset_handle< prefab > &pfb, bool call_callbacks=true) -> entt::handle
auto create_entity(const std::string &tag={}, entt::handle parent={}) -> entt::handle
Creates an entity in the scene with an optional tag and parent.
static auto get_scene(entt::handle entity) -> scene *
Gets the scene from an entity handle.
void unload()
Unloads the scene, removing all entities.
static void clone_scene(const scene &src_scene, scene &dst_scene, bool call_callbacks=true)
Clones the entities from one scene to another.
std::unique_ptr< entt::registry > registry
The registry that manages all entities in the scene.
scene(const std::string &tag_name)
Constructs a new scene.
auto create_handle(entt::entity e) -> entt::handle
Creates an entity in the scene.
static auto find_entity_by_prefab_uuid(entt::handle root_entity, const hpp::uuid &target_uuid) -> entt::handle
Finds an entity by UUID in the scene.
Component that provides a tag (name or label) for an entity.
static void on_create_component(entt::registry &r, entt::entity e)
static void on_load_component(entt::registry &r, entt::entity e)
static void on_destroy_component(entt::registry &r, entt::entity e)