Skip to content

fix: generates invalid callback #113

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
May 17, 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
8 changes: 0 additions & 8 deletions ecsact/entt/wrapper/dynamic.hh
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,10 @@ auto context_generate_add(
const void* component_data,
ecsact::entt::entity_id entity
) -> void {
using ecsact::entt::detail::created_entity;
using ecsact::entt::detail::pending_add;

auto& registry = *context->registry;

registry.template emplace<created_entity>(
entity,
created_entity{
.placeholder_entity_id = ecsact_generated_entity,
}
);

const auto& component = *static_cast<const C*>(component_data);
registry.template emplace<pending_add<C>>(entity, component);
}
Expand Down
7 changes: 6 additions & 1 deletion rt_entt_codegen/core/print_sys_exec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,12 @@ static auto print_sys_exec_ctx_generate(
// NOTE(Kelwan): Multiple generates blocks are allowed in Ecsact systems but
// currently the interpreter won't allow this. More testing required after the
// issue is resolved https://github.com/ecsact-dev/ecsact_interpret/issues/185
ctx.write("auto entity = this->registry->create();\n");
ctx.write("auto entity = registry->create();\n");

ctx.write(
"registry->template emplace<ecsact::entt::detail::created_entity>(entity, "
"ecsact_generated_entity);\n"
);

block(ctx, "for(int i = 0; i < component_count; ++i)", [&] {
ctx.write("const auto component_id = component_ids[i];\n");
Expand Down
9 changes: 5 additions & 4 deletions test/runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ void runtime_test::OtherEntitySystem::impl(context& ctx) {
}

void runtime_test::MakeAnother::impl(context& ctx) {
ctx._ctx.generate(ctx.get<ComponentA>());
ctx._ctx.generate(ctx.get<ComponentA>(), ctx.get<ComponentB>());
}

void runtime_test::TestAction::impl(context& ctx) {
Expand Down Expand Up @@ -758,22 +758,23 @@ TEST(Core, GeneratesCreateEvent) {
auto test_entity = reg.create_entity();
auto test_action = runtime_test::MakeAnother{};
reg.add_component(test_entity, runtime_test::ComponentA{});
reg.add_component(test_entity, runtime_test::ComponentB{});

auto options = ecsact::core::execution_options{};
options.push_action(&test_action);

auto evc = ecsact::core::execution_events_collector<>{};
auto event_happened = false;
auto created_event_count = 0;
evc.set_entity_created_callback(
[&](ecsact_entity_id, ecsact_placeholder_entity_id placeholder) {
event_happened = true;
created_event_count += 1;
ASSERT_EQ(placeholder, ecsact_generated_entity);
}
);

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

Expand Down
6 changes: 6 additions & 0 deletions test/runtime_test.ecsact
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ component ComponentA {
i32 a;
}

component ComponentB {
i32 b;
}

component OtherEntityComponent {
i32 num;
entity target;
Expand Down Expand Up @@ -52,8 +56,10 @@ system AlwaysRemove {

action MakeAnother {
readwrite ComponentA;
readwrite ComponentB;
generates {
required ComponentA;
required ComponentB;
}
}

Expand Down