Skip to content

chore: ecsact to entt reg prepare #159

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

Merged
merged 3 commits into from
Nov 11, 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
2 changes: 2 additions & 0 deletions ecsact/entt/registry_util.hh
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ inline auto create_registry()
return {registry_id, std::ref(registry)};
}

auto ecsact_init_registry_storage(::entt::registry& registry) -> void;

} // namespace ecsact::entt
15 changes: 7 additions & 8 deletions ecsact/entt/wrapper/core.hh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "ecsact/entt/detail/internal_markers.hh"
#include "ecsact/entt/event_markers.hh"
#include "entt/entity/registry.hpp"
#include "entt/entt.hpp"
#include "ecsact/entt/registry_util.hh"
#include "ecsact/entt/error_check.hh"
#include "ecsact/entt/detail/execution_events_collector.hh"
Expand Down Expand Up @@ -452,11 +453,9 @@ inline auto clear_notify_component(ecsact_registry_id registry_id) -> void {
}

template<typename C>
inline auto prepare_component(ecsact_registry_id registry_id) -> void {
inline auto prepare_component(::entt::registry& reg) -> void {
using namespace ecsact::entt;

auto& reg = ecsact::entt::get_registry(registry_id);

reg.template storage<C>();
reg.template storage<component_added<C>>();
reg.template storage<component_removed<C>>();
Expand All @@ -467,17 +466,17 @@ inline auto prepare_component(ecsact_registry_id registry_id) -> void {
if constexpr(!std::is_empty_v<C>) {
reg.template storage<detail::exec_beforechange_storage<C>>();
reg.template storage<detail::exec_itr_beforechange_storage<C>>();
reg.template storage<detail::run_on_stream<C>>();
}
}

template<typename S>
inline auto prepare_system(ecsact_registry_id registry_id) -> void {
inline auto prepare_system(::entt::registry& registry) -> void {
using namespace ecsact::entt::detail;
auto& reg = ecsact::entt::get_registry(registry_id);

reg.template storage<system_sorted<S>>();
reg.template storage<pending_lazy_execution<S>>();
reg.template storage<run_system<S>>();
registry.template storage<system_sorted<S>>();
registry.template storage<pending_lazy_execution<S>>();
registry.template storage<run_system<S>>();
}

template<typename C, typename V>
Expand Down
4 changes: 3 additions & 1 deletion rt_entt_codegen/core/create_registry.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ auto ecsact::rt_entt_codegen::core::print_create_registry( //
.return_type("ecsact_registry_id");

ctx.write("auto&& [registry_id, reg] = ecsact::entt::create_registry();\n\n");
ctx.write("ecsact_init_registry_storage(registry_id);\n");

ctx.write("auto& entt_reg = ecsact::entt::get_registry(registry_id);\n\n");
ctx.write("ecsact::entt::ecsact_init_registry_storage(entt_reg);\n");
ctx.write("\nreturn registry_id;");
}
12 changes: 8 additions & 4 deletions rt_entt_codegen/core/init_registry_storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@ auto ecsact::rt_entt_codegen::core::print_init_registry_storage(
using ecsact::rt_entt_codegen::util::method_printer;

auto printer = //
method_printer{ctx, "ecsact_init_registry_storage"}
.parameter("ecsact_registry_id", "registry_id")
method_printer{ctx, "ecsact::entt::ecsact_init_registry_storage"}
.parameter("::entt::registry&", "registry")
.return_type("void");

ctx.write(
"registry.template storage<ecsact::entt::detail::destroyed_entity>();\n\n"
);

for(auto comp_id : details.all_components) {
auto cpp_comp_name = cpp_identifier(decl_full_name(comp_id));

ctx.write(std::format(
"ecsact::entt::wrapper::core::prepare_component<{}>(registry_id);\n",
"ecsact::entt::wrapper::core::prepare_component<{}>(registry);\n",
cpp_comp_name
));
}
Expand All @@ -29,7 +33,7 @@ auto ecsact::rt_entt_codegen::core::print_init_registry_storage(
auto cpp_sys_name = cpp_identifier(decl_full_name(system_id));

ctx.write(std::format(
"ecsact::entt::wrapper::core::prepare_system<{}>(registry_id);\n",
"ecsact::entt::wrapper::core::prepare_system<{}>(registry);\n",
cpp_sys_name
));
}
Expand Down