Skip to content

fix: generate add events not calling, parent trivial systems children systems not running #136

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
Jun 28, 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
1 change: 1 addition & 0 deletions ecsact/entt/wrapper/dynamic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ auto context_generate_add(

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

} // namespace ecsact::entt::wrapper::dynamic
80 changes: 51 additions & 29 deletions rt_entt_codegen/core/print_sys_exec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -419,39 +419,53 @@ static auto print_execute_systems(
}
}

for(auto provider : system_providers) {
auto result = provider->entity_iteration(ctx, names, [&] {
for(const auto& provider : system_providers) {
provider->pre_exec_system_impl(ctx, names);
}
auto exec_system_impls = [&](bool has_system_impl) {
for(auto provider : system_providers) {
auto result = provider->entity_iteration(ctx, names, [&] {
for(const auto& provider : system_providers) {
provider->pre_exec_system_impl(ctx, names);
}

context_init_provider
->pre_exec_system_impl_context_init(ctx, names, context_type_name);

ecsact::rt_entt_codegen::core::print_child_systems(
ctx,
names,
sys_like_id
);

context_init_provider
->pre_exec_system_impl_context_init(ctx, names, context_type_name);
if(has_system_impl) {
auto result =
std::ranges::find_if(system_providers, [&](auto provider) {
return provider->system_impl(ctx, names) ==
handle_exclusive_provide::HANDLED;
});

ecsact::rt_entt_codegen::core::print_child_systems(
ctx,
names,
sys_like_id
);
if(result == system_providers.end()) {
throw std::logic_error("system_impl was not handled by providers");
}
}

auto result = std::ranges::find_if(system_providers, [&](auto provider) {
return provider->system_impl(ctx, names) ==
handle_exclusive_provide::HANDLED;
});

if(result == system_providers.end()) {
throw std::logic_error("system_impl was not handled by providers");
}
for(const auto& provider : system_providers) {
provider->post_exec_system_impl(ctx, names);
}

for(const auto& provider : system_providers) {
provider->post_exec_system_impl(ctx, names);
ctx.write("\n");
});
if(result == handle_exclusive_provide::HANDLED) {
break;
}

ctx.write("\n");
});
if(result == handle_exclusive_provide::HANDLED) {
break;
}
};

auto child_ids = ecsact::meta::get_child_system_ids(sys_like_id);
if(child_ids.empty()) {
// system impl was already checked at start
exec_system_impls(true);
} else {
block(ctx, "if(system_impl == nullptr)", [&] { exec_system_impls(false); });
block(ctx, "else", [&] { exec_system_impls(true); });
}

for(const auto& provider : system_providers) {
Expand Down Expand Up @@ -541,7 +555,11 @@ static auto print_execute_system_template_specialization(
">();\n"
);

block(ctx, "if(system_impl == nullptr)", [&] { ctx.write("return;"); });
auto child_ids = ecsact::meta::get_child_system_ids(system_id);
if(child_ids.empty()) {
block(ctx, "if(system_impl == nullptr)", [&] { ctx.write("return;"); });
ctx.write("\n");
}

print_execute_systems(
ctx,
Expand Down Expand Up @@ -591,7 +609,11 @@ static auto print_execute_actions_template_specialization(
">();\n"
);

block(ctx, "if(system_impl == nullptr)", [&] { ctx.write("return;"); });
auto child_ids = ecsact::meta::get_child_system_ids(action_id);
if(child_ids.empty()) {
block(ctx, "if(system_impl == nullptr)", [&] { ctx.write("return;"); });
ctx.write("\n");
}

ctx.write(
"auto actions = actions_map.as_action_span<",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,14 @@ auto provider::association::system_impl(
ctx,
"if(found_assoc_entities == " + std::to_string(other_view_names.size()) +
")",
[&] { ctx.write("system_impl(&context);\n"); }
[&] {
auto child_ids = ecsact::meta::get_child_system_ids(sys_like_id);
if(child_ids.empty()) {
ctx.write("system_impl(&context);\n");
}
}
);

return HANDLED;
}

Expand Down
9 changes: 8 additions & 1 deletion test/runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ TEST(Core, DynamicSystemImpl) {
EXPECT_EQ(comp_get.a, comp.a);
}

TEST(Core, GeneratesCreateEvent) {
TEST(Core, GeneratesCreateAndInitEvent) {
SET_SYSTEM_IMPL(MakeAnother);

auto reg = ecsact::core::registry("GeneratesCreateEvent");
Expand All @@ -800,9 +800,16 @@ TEST(Core, GeneratesCreateEvent) {
}
);

auto init_event_happened = false;

evc.set_init_callback<runtime_test::ComponentA>(
[&](auto entity_id, auto component) { init_event_happened = true; }
);

auto exec_err = reg.execute_systems(std::array{options}, evc);
EXPECT_EQ(exec_err, ECSACT_EXEC_SYS_OK);
EXPECT_EQ(created_event_count, 1);
EXPECT_EQ(init_event_happened, true);
EXPECT_EQ(2, reg.count_entities());
}

Expand Down