Skip to content

Commit 5ed2115

Browse files
authored
fix: generates invalid callback (#113)
1 parent 09e842e commit 5ed2115

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

ecsact/entt/wrapper/dynamic.hh

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -181,18 +181,10 @@ auto context_generate_add(
181181
const void* component_data,
182182
ecsact::entt::entity_id entity
183183
) -> void {
184-
using ecsact::entt::detail::created_entity;
185184
using ecsact::entt::detail::pending_add;
186185

187186
auto& registry = *context->registry;
188187

189-
registry.template emplace<created_entity>(
190-
entity,
191-
created_entity{
192-
.placeholder_entity_id = ecsact_generated_entity,
193-
}
194-
);
195-
196188
const auto& component = *static_cast<const C*>(component_data);
197189
registry.template emplace<pending_add<C>>(entity, component);
198190
}

rt_entt_codegen/core/print_sys_exec.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,12 @@ static auto print_sys_exec_ctx_generate(
431431
// NOTE(Kelwan): Multiple generates blocks are allowed in Ecsact systems but
432432
// currently the interpreter won't allow this. More testing required after the
433433
// issue is resolved https://github.com/ecsact-dev/ecsact_interpret/issues/185
434-
ctx.write("auto entity = this->registry->create();\n");
434+
ctx.write("auto entity = registry->create();\n");
435+
436+
ctx.write(
437+
"registry->template emplace<ecsact::entt::detail::created_entity>(entity, "
438+
"ecsact_generated_entity);\n"
439+
);
435440

436441
block(ctx, "for(int i = 0; i < component_count; ++i)", [&] {
437442
ctx.write("const auto component_id = component_ids[i];\n");

test/runtime_test.cc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ void runtime_test::OtherEntitySystem::impl(context& ctx) {
3434
}
3535

3636
void runtime_test::MakeAnother::impl(context& ctx) {
37-
ctx._ctx.generate(ctx.get<ComponentA>());
37+
ctx._ctx.generate(ctx.get<ComponentA>(), ctx.get<ComponentB>());
3838
}
3939

4040
void runtime_test::TestAction::impl(context& ctx) {
@@ -758,22 +758,23 @@ TEST(Core, GeneratesCreateEvent) {
758758
auto test_entity = reg.create_entity();
759759
auto test_action = runtime_test::MakeAnother{};
760760
reg.add_component(test_entity, runtime_test::ComponentA{});
761+
reg.add_component(test_entity, runtime_test::ComponentB{});
761762

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

765766
auto evc = ecsact::core::execution_events_collector<>{};
766-
auto event_happened = false;
767+
auto created_event_count = 0;
767768
evc.set_entity_created_callback(
768769
[&](ecsact_entity_id, ecsact_placeholder_entity_id placeholder) {
769-
event_happened = true;
770+
created_event_count += 1;
770771
ASSERT_EQ(placeholder, ecsact_generated_entity);
771772
}
772773
);
773774

774775
auto exec_err = reg.execute_systems(std::array{options}, evc);
775776
EXPECT_EQ(exec_err, ECSACT_EXEC_SYS_OK);
776-
EXPECT_TRUE(event_happened);
777+
EXPECT_EQ(created_event_count, 1);
777778
EXPECT_EQ(2, reg.count_entities());
778779
}
779780

test/runtime_test.ecsact

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ component ComponentA {
66
i32 a;
77
}
88

9+
component ComponentB {
10+
i32 b;
11+
}
12+
913
component OtherEntityComponent {
1014
i32 num;
1115
entity target;
@@ -52,8 +56,10 @@ system AlwaysRemove {
5256

5357
action MakeAnother {
5458
readwrite ComponentA;
59+
readwrite ComponentB;
5560
generates {
5661
required ComponentA;
62+
required ComponentB;
5763
}
5864
}
5965

0 commit comments

Comments
 (0)