Skip to content

generates test #40

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 1 commit into from
Feb 28, 2023
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
5 changes: 4 additions & 1 deletion ecsact/entt/detail/system_execution_context.hh
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ struct system_execution_context : system_execution_context_base {
using ecsact::entt::detail::pending_add;

auto new_entity = info.create_entity().entt_entity_id;
info.registry.template emplace<created_entity>(new_entity);
info.registry.template emplace<created_entity>(
new_entity,
ecsact_generated_entity
);
for(int i = 0; component_count > i; ++i) {
auto component_id = component_ids[i];
auto component_data = components_data[i];
Expand Down
31 changes: 31 additions & 0 deletions runtime/test/runtime_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ void runtime_test::OtherEntitySystem::impl(context& ctx) {
}

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

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

TEST(Core, GeneratesCreateEvent) {
ecsact_set_system_execution_impl(
ecsact_id_cast<ecsact_system_like_id>(runtime_test::MakeAnother::id),
&runtime_test__MakeAnother
);

auto reg = ecsact::core::registry("GeneratesCreateEvent");

auto test_entity = reg.create_entity();
auto test_action = runtime_test::MakeAnother{};
reg.add_component(test_entity, runtime_test::ComponentA{});

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

auto evc = ecsact::core::execution_events_collector<>{};
auto event_happened = false;
evc.set_entity_created_callback(
[&](ecsact_entity_id, ecsact_placeholder_entity_id placeholder) {
event_happened = true;
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(2, reg.count_entities());
}

TEST(Core, CreateAndDestroyEntity) {
auto reg = ecsact::core::registry("CreateAndDestroyEntity");

Expand Down
2 changes: 1 addition & 1 deletion runtime/test/runtime_test.ecsact
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ system AlwaysRemove {
action MakeAnother {
readwrite ComponentA;
generates {
required OtherEntityComponent;
required ComponentA;
}
}

Expand Down