Skip to content

Commit de7a389

Browse files
authored
generates test (#40)
1 parent cb4bb93 commit de7a389

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

ecsact/entt/detail/system_execution_context.hh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,10 @@ struct system_execution_context : system_execution_context_base {
345345
using ecsact::entt::detail::pending_add;
346346

347347
auto new_entity = info.create_entity().entt_entity_id;
348-
info.registry.template emplace<created_entity>(new_entity);
348+
info.registry.template emplace<created_entity>(
349+
new_entity,
350+
ecsact_generated_entity
351+
);
349352
for(int i = 0; component_count > i; ++i) {
350353
auto component_id = component_ids[i];
351354
auto component_data = components_data[i];

runtime/test/runtime_test.cc

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ void runtime_test::OtherEntitySystem::impl(context& ctx) {
3131
}
3232

3333
void runtime_test::MakeAnother::impl(context& ctx) {
34+
ctx._ctx.generate(ctx.get<ComponentA>());
3435
}
3536

3637
void runtime_test::AlwaysRemove::impl(context& ctx) {
@@ -644,6 +645,36 @@ TEST(Core, DynamicSystemImpl) {
644645
EXPECT_EQ(comp_get.a, comp.a);
645646
}
646647

648+
TEST(Core, GeneratesCreateEvent) {
649+
ecsact_set_system_execution_impl(
650+
ecsact_id_cast<ecsact_system_like_id>(runtime_test::MakeAnother::id),
651+
&runtime_test__MakeAnother
652+
);
653+
654+
auto reg = ecsact::core::registry("GeneratesCreateEvent");
655+
656+
auto test_entity = reg.create_entity();
657+
auto test_action = runtime_test::MakeAnother{};
658+
reg.add_component(test_entity, runtime_test::ComponentA{});
659+
660+
auto options = ecsact::core::execution_options{};
661+
options.push_action(&test_action);
662+
663+
auto evc = ecsact::core::execution_events_collector<>{};
664+
auto event_happened = false;
665+
evc.set_entity_created_callback(
666+
[&](ecsact_entity_id, ecsact_placeholder_entity_id placeholder) {
667+
event_happened = true;
668+
ASSERT_EQ(placeholder, ecsact_generated_entity);
669+
}
670+
);
671+
672+
auto exec_err = reg.execute_systems(std::array{options}, evc);
673+
EXPECT_EQ(exec_err, ECSACT_EXEC_SYS_OK);
674+
EXPECT_TRUE(event_happened);
675+
EXPECT_EQ(2, reg.count_entities());
676+
}
677+
647678
TEST(Core, CreateAndDestroyEntity) {
648679
auto reg = ecsact::core::registry("CreateAndDestroyEntity");
649680

runtime/test/runtime_test.ecsact

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ system AlwaysRemove {
5151
action MakeAnother {
5252
readwrite ComponentA;
5353
generates {
54-
required OtherEntityComponent;
54+
required ComponentA;
5555
}
5656
}
5757

0 commit comments

Comments
 (0)