Skip to content

Commit 9380227

Browse files
committed
chore: Reintroduce preloading components for entt storage
1 parent 70afb7e commit 9380227

File tree

6 files changed

+55
-0
lines changed

6 files changed

+55
-0
lines changed

ecsact/entt/wrapper/core.hh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,4 +373,21 @@ inline auto clear_component(ecsact_registry_id registry_id) -> void {
373373
reg.clear<ecsact::entt::component_removed<C>>();
374374
}
375375

376+
template<typename C>
377+
inline auto init_registry_with_component(ecsact_registry_id registry_id
378+
) -> void {
379+
using namespace ecsact::entt;
380+
381+
auto& reg = ecsact::entt::get_registry(registry_id);
382+
383+
reg.template storage<C>();
384+
reg.template storage<component_added<C>>();
385+
reg.template storage<component_changed<C>>();
386+
reg.template storage<component_removed<C>>();
387+
388+
if constexpr(!std::is_empty_v<C>) {
389+
reg.storage<detail::beforechange_storage<C>>();
390+
}
391+
}
392+
376393
} // namespace ecsact::entt::wrapper::core

rt_entt_codegen/core/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ cc_library(
1313
_CORE_CODEGEN_METHODS = {
1414
"execute_systems": [],
1515
"create_registry": [],
16+
"init_registry_storage": [],
1617
"events": [],
1718
"print_sys_exec": [
1819
"//rt_entt_codegen/shared:comps_with_caps",

rt_entt_codegen/core/core.hh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ auto print_create_registry( //
2121
const ecsact_entt_details& details
2222
) -> void;
2323

24+
auto print_init_registry_storage( //
25+
ecsact::codegen_plugin_context& ctx,
26+
const ecsact::rt_entt_codegen::ecsact_entt_details& details
27+
) -> void;
28+
2429
auto print_execute_system_like_template_specializations( //
2530
codegen_plugin_context& ctx,
2631
const ecsact_entt_details& details

rt_entt_codegen/core/create_registry.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,7 @@ auto ecsact::rt_entt_codegen::core::print_create_registry( //
2727
}
2828
}
2929

30+
ctx.write("ecsact_init_registry_storage(registry_id);\n");
31+
3032
ctx.write("\nreturn registry_id;");
3133
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#include "core.hh"
2+
3+
#include "ecsact/lang-support/lang-cc.hh"
4+
#include "rt_entt_codegen/shared/util.hh"
5+
6+
auto ecsact::rt_entt_codegen::core::print_init_registry_storage(
7+
ecsact::codegen_plugin_context& ctx,
8+
const ecsact::rt_entt_codegen::ecsact_entt_details& details
9+
) -> void {
10+
using ecsact::cc_lang_support::cpp_identifier;
11+
using ecsact::meta::decl_full_name;
12+
using ecsact::rt_entt_codegen::util::method_printer;
13+
14+
auto printer = //
15+
method_printer{ctx, "ecsact_init_registry_storage"}
16+
.parameter("ecsact_registry_id", "registry_id")
17+
.return_type("void");
18+
19+
for(auto comp_id : details.all_components) {
20+
auto cpp_comp_name = cpp_identifier(decl_full_name(comp_id));
21+
22+
ctx.write(
23+
"ecsact::entt::wrapper::core::init_registry_with_component<",
24+
cpp_comp_name,
25+
">(registry_id)"
26+
);
27+
ctx.write(";\n");
28+
}
29+
}

rt_entt_codegen/rt_entt_codegen.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ void ecsact_codegen_plugin(
204204

205205
core::print_check_error_template_specializations(ctx, details);
206206
core::print_execute_system_like_template_specializations(ctx, details);
207+
core::print_init_registry_storage(ctx, details);
207208
core::print_create_registry(ctx, details);
208209
core::print_trigger_ecsact_events_minimal(ctx, details);
209210
core::print_trigger_ecsact_events_all(ctx, details);

0 commit comments

Comments
 (0)