Skip to content

Commit

Permalink
Fix issue with creating C++ systems/observers with name relative to root
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Oct 24, 2023
1 parent e3edd98 commit f20cf1f
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 4 deletions.
1 change: 1 addition & 0 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -28473,6 +28473,7 @@ struct node_builder : IBuilder<Base, Components ...>
ecs_entity_desc_t entity_desc = {};
entity_desc.name = name;
entity_desc.sep = "::";
entity_desc.root_sep = "::";
m_desc.entity = ecs_entity_init(m_world, &entity_desc);
}

Expand Down
1 change: 1 addition & 0 deletions include/flecs/addons/cpp/utils/node_builder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct node_builder : IBuilder<Base, Components ...>
ecs_entity_desc_t entity_desc = {};
entity_desc.name = name;
entity_desc.sep = "::";
entity_desc.root_sep = "::";
m_desc.entity = ecs_entity_init(m_world, &entity_desc);
}

Expand Down
6 changes: 4 additions & 2 deletions test/cpp_api/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,8 @@
"20_terms",
"name_arg",
"create_w_no_template_args",
"write_annotation"
"write_annotation",
"name_from_root"
]
}, {
"id": "Observer",
Expand Down Expand Up @@ -883,7 +884,8 @@
"on_add_pair_wildcard_singleton",
"on_add_with_pair_singleton",
"add_in_yield_existing",
"add_in_yield_existing_multi"
"add_in_yield_existing_multi",
"name_from_root"
]
}, {
"id": "Filter",
Expand Down
13 changes: 13 additions & 0 deletions test/cpp_api/src/Observer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -803,3 +803,16 @@ void Observer_add_in_yield_existing_multi(void) {
test_assert(e3.has<Mass>());
test_assert(e3.has<Velocity>());
}

void Observer_name_from_root(void) {
flecs::world ecs;

flecs::entity sys = ecs.observer<Position>("::ns::MySystem")
.event(flecs::OnSet)
.each([](Position& p) { });

test_str(sys.name(), "MySystem");

flecs::entity ns = ecs.entity("::ns");
test_assert(ns == sys.parent());
}
12 changes: 12 additions & 0 deletions test/cpp_api/src/SystemBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,3 +514,15 @@ void SystemBuilder_write_annotation(void) {

test_assert(e1.has<TagB>());
}

void SystemBuilder_name_from_root(void) {
flecs::world ecs;

flecs::entity sys = ecs.system("::ns::MySystem")
.each([](flecs::entity e) { });

test_str(sys.name(), "MySystem");

flecs::entity ns = ecs.entity("::ns");
test_assert(ns == sys.parent());
}
14 changes: 12 additions & 2 deletions test/cpp_api/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ void SystemBuilder_20_terms(void);
void SystemBuilder_name_arg(void);
void SystemBuilder_create_w_no_template_args(void);
void SystemBuilder_write_annotation(void);
void SystemBuilder_name_from_root(void);

// Testsuite 'Observer'
void Observer_2_terms_on_add(void);
Expand Down Expand Up @@ -850,6 +851,7 @@ void Observer_on_add_pair_wildcard_singleton(void);
void Observer_on_add_with_pair_singleton(void);
void Observer_add_in_yield_existing(void);
void Observer_add_in_yield_existing_multi(void);
void Observer_name_from_root(void);

// Testsuite 'Filter'
void Filter_term_each_component(void);
Expand Down Expand Up @@ -4479,6 +4481,10 @@ bake_test_case SystemBuilder_testcases[] = {
{
"write_annotation",
SystemBuilder_write_annotation
},
{
"name_from_root",
SystemBuilder_name_from_root
}
};

Expand Down Expand Up @@ -4606,6 +4612,10 @@ bake_test_case Observer_testcases[] = {
{
"add_in_yield_existing_multi",
Observer_add_in_yield_existing_multi
},
{
"name_from_root",
Observer_name_from_root
}
};

Expand Down Expand Up @@ -6480,14 +6490,14 @@ static bake_test_suite suites[] = {
"SystemBuilder",
NULL,
NULL,
21,
22,
SystemBuilder_testcases
},
{
"Observer",
NULL,
NULL,
31,
32,
Observer_testcases
},
{
Expand Down

0 comments on commit f20cf1f

Please sign in to comment.