From b480364588651a2885fde36548fa6902a19826bc Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Fri, 17 May 2024 12:42:27 -0700 Subject: [PATCH 1/3] fix: generates invalid callback --- .editorconfig | 3 +++ ecsact/entt/wrapper/dynamic.hh | 8 -------- rt_entt_codegen/core/print_sys_exec.cc | 7 ++++++- test/runtime_test.cc | 9 +++++---- test/runtime_test.ecsact | 6 ++++++ 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/.editorconfig b/.editorconfig index 9b1aeae..41ce6aa 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,3 +4,6 @@ root = true end_of_line = lf insert_final_newline = true +[*.ecsact] +indent_style = tab + diff --git a/ecsact/entt/wrapper/dynamic.hh b/ecsact/entt/wrapper/dynamic.hh index afcc37f..0dc14e9 100644 --- a/ecsact/entt/wrapper/dynamic.hh +++ b/ecsact/entt/wrapper/dynamic.hh @@ -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( - entity, - created_entity{ - .placeholder_entity_id = ecsact_generated_entity, - } - ); - const auto& component = *static_cast(component_data); registry.template emplace>(entity, component); } diff --git a/rt_entt_codegen/core/print_sys_exec.cc b/rt_entt_codegen/core/print_sys_exec.cc index 81dafea..4d63c96 100644 --- a/rt_entt_codegen/core/print_sys_exec.cc +++ b/rt_entt_codegen/core/print_sys_exec.cc @@ -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(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"); diff --git a/test/runtime_test.cc b/test/runtime_test.cc index 9d51b12..2a0067e 100644 --- a/test/runtime_test.cc +++ b/test/runtime_test.cc @@ -34,7 +34,7 @@ void runtime_test::OtherEntitySystem::impl(context& ctx) { } void runtime_test::MakeAnother::impl(context& ctx) { - ctx._ctx.generate(ctx.get()); + ctx._ctx.generate(ctx.get(), ctx.get()); } void runtime_test::TestAction::impl(context& ctx) { @@ -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()); } diff --git a/test/runtime_test.ecsact b/test/runtime_test.ecsact index 23570ea..500198f 100644 --- a/test/runtime_test.ecsact +++ b/test/runtime_test.ecsact @@ -6,6 +6,10 @@ component ComponentA { i32 a; } +component ComponentB { + i32 b; +} + component OtherEntityComponent { i32 num; entity target; @@ -52,8 +56,10 @@ system AlwaysRemove { action MakeAnother { readwrite ComponentA; + readwrite ComponentB; generates { required ComponentA; + required ComponentB; } } From 1ad8746473f0ceba17c1df39a7151cfe48cef83f Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Fri, 17 May 2024 12:43:36 -0700 Subject: [PATCH 2/3] chore: undo editor config change --- .editorconfig | 3 --- 1 file changed, 3 deletions(-) diff --git a/.editorconfig b/.editorconfig index 41ce6aa..9b1aeae 100644 --- a/.editorconfig +++ b/.editorconfig @@ -4,6 +4,3 @@ root = true end_of_line = lf insert_final_newline = true -[*.ecsact] -indent_style = tab - From 9ba45cd888d93303732ef564648e5afc13853f69 Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Fri, 17 May 2024 12:44:44 -0700 Subject: [PATCH 3/3] chore: fix indenting --- test/runtime_test.ecsact | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtime_test.ecsact b/test/runtime_test.ecsact index 500198f..a446f4c 100644 --- a/test/runtime_test.ecsact +++ b/test/runtime_test.ecsact @@ -7,7 +7,7 @@ component ComponentA { } component ComponentB { - i32 b; + i32 b; } component OtherEntityComponent {