Skip to content

Commit 4d596c3

Browse files
Kelwanzaucy
andauthored
fix: generate add events not calling, parent trivial systems children systems not running (#136)
Co-authored-by: Ezekiel Warren <[email protected]>
1 parent c46a61c commit 4d596c3

File tree

4 files changed

+67
-31
lines changed

4 files changed

+67
-31
lines changed

ecsact/entt/wrapper/dynamic.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ auto context_generate_add(
179179

180180
const auto& component = *static_cast<const C*>(component_data);
181181
registry.template emplace<pending_add<C>>(entity, component);
182+
registry.template emplace_or_replace<component_added<C>>(entity);
182183
}
183184

184185
} // namespace ecsact::entt::wrapper::dynamic

rt_entt_codegen/core/print_sys_exec.cc

Lines changed: 51 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -419,39 +419,53 @@ static auto print_execute_systems(
419419
}
420420
}
421421

422-
for(auto provider : system_providers) {
423-
auto result = provider->entity_iteration(ctx, names, [&] {
424-
for(const auto& provider : system_providers) {
425-
provider->pre_exec_system_impl(ctx, names);
426-
}
422+
auto exec_system_impls = [&](bool has_system_impl) {
423+
for(auto provider : system_providers) {
424+
auto result = provider->entity_iteration(ctx, names, [&] {
425+
for(const auto& provider : system_providers) {
426+
provider->pre_exec_system_impl(ctx, names);
427+
}
428+
429+
context_init_provider
430+
->pre_exec_system_impl_context_init(ctx, names, context_type_name);
431+
432+
ecsact::rt_entt_codegen::core::print_child_systems(
433+
ctx,
434+
names,
435+
sys_like_id
436+
);
427437

428-
context_init_provider
429-
->pre_exec_system_impl_context_init(ctx, names, context_type_name);
438+
if(has_system_impl) {
439+
auto result =
440+
std::ranges::find_if(system_providers, [&](auto provider) {
441+
return provider->system_impl(ctx, names) ==
442+
handle_exclusive_provide::HANDLED;
443+
});
430444

431-
ecsact::rt_entt_codegen::core::print_child_systems(
432-
ctx,
433-
names,
434-
sys_like_id
435-
);
445+
if(result == system_providers.end()) {
446+
throw std::logic_error("system_impl was not handled by providers");
447+
}
448+
}
436449

437-
auto result = std::ranges::find_if(system_providers, [&](auto provider) {
438-
return provider->system_impl(ctx, names) ==
439-
handle_exclusive_provide::HANDLED;
440-
});
441-
442-
if(result == system_providers.end()) {
443-
throw std::logic_error("system_impl was not handled by providers");
444-
}
450+
for(const auto& provider : system_providers) {
451+
provider->post_exec_system_impl(ctx, names);
452+
}
445453

446-
for(const auto& provider : system_providers) {
447-
provider->post_exec_system_impl(ctx, names);
454+
ctx.write("\n");
455+
});
456+
if(result == handle_exclusive_provide::HANDLED) {
457+
break;
448458
}
449-
450-
ctx.write("\n");
451-
});
452-
if(result == handle_exclusive_provide::HANDLED) {
453-
break;
454459
}
460+
};
461+
462+
auto child_ids = ecsact::meta::get_child_system_ids(sys_like_id);
463+
if(child_ids.empty()) {
464+
// system impl was already checked at start
465+
exec_system_impls(true);
466+
} else {
467+
block(ctx, "if(system_impl == nullptr)", [&] { exec_system_impls(false); });
468+
block(ctx, "else", [&] { exec_system_impls(true); });
455469
}
456470

457471
for(const auto& provider : system_providers) {
@@ -541,7 +555,11 @@ static auto print_execute_system_template_specialization(
541555
">();\n"
542556
);
543557

544-
block(ctx, "if(system_impl == nullptr)", [&] { ctx.write("return;"); });
558+
auto child_ids = ecsact::meta::get_child_system_ids(system_id);
559+
if(child_ids.empty()) {
560+
block(ctx, "if(system_impl == nullptr)", [&] { ctx.write("return;"); });
561+
ctx.write("\n");
562+
}
545563

546564
print_execute_systems(
547565
ctx,
@@ -591,7 +609,11 @@ static auto print_execute_actions_template_specialization(
591609
">();\n"
592610
);
593611

594-
block(ctx, "if(system_impl == nullptr)", [&] { ctx.write("return;"); });
612+
auto child_ids = ecsact::meta::get_child_system_ids(action_id);
613+
if(child_ids.empty()) {
614+
block(ctx, "if(system_impl == nullptr)", [&] { ctx.write("return;"); });
615+
ctx.write("\n");
616+
}
595617

596618
ctx.write(
597619
"auto actions = actions_map.as_action_span<",

rt_entt_codegen/core/system_provider/association/association.cc

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,14 @@ auto provider::association::system_impl(
125125
ctx,
126126
"if(found_assoc_entities == " + std::to_string(other_view_names.size()) +
127127
")",
128-
[&] { ctx.write("system_impl(&context);\n"); }
128+
[&] {
129+
auto child_ids = ecsact::meta::get_child_system_ids(sys_like_id);
130+
if(child_ids.empty()) {
131+
ctx.write("system_impl(&context);\n");
132+
}
133+
}
129134
);
135+
130136
return HANDLED;
131137
}
132138

test/runtime_test.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ TEST(Core, DynamicSystemImpl) {
778778
EXPECT_EQ(comp_get.a, comp.a);
779779
}
780780

781-
TEST(Core, GeneratesCreateEvent) {
781+
TEST(Core, GeneratesCreateAndInitEvent) {
782782
SET_SYSTEM_IMPL(MakeAnother);
783783

784784
auto reg = ecsact::core::registry("GeneratesCreateEvent");
@@ -800,9 +800,16 @@ TEST(Core, GeneratesCreateEvent) {
800800
}
801801
);
802802

803+
auto init_event_happened = false;
804+
805+
evc.set_init_callback<runtime_test::ComponentA>(
806+
[&](auto entity_id, auto component) { init_event_happened = true; }
807+
);
808+
803809
auto exec_err = reg.execute_systems(std::array{options}, evc);
804810
EXPECT_EQ(exec_err, ECSACT_EXEC_SYS_OK);
805811
EXPECT_EQ(created_event_count, 1);
812+
EXPECT_EQ(init_event_happened, true);
806813
EXPECT_EQ(2, reg.count_entities());
807814
}
808815

0 commit comments

Comments
 (0)