Skip to content
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

Fix issue with using query.find(flecs::entity, ...) and QueryMatchEmp… #1448

Merged
merged 1 commit into from
Nov 22, 2024
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
Fix issue with using query.find(flecs::entity, ...) and QueryMatchEmp…
…tyTables
  • Loading branch information
SanderMertens committed Nov 22, 2024
commit fae383684fd8b756f217e627dcf48f6951357278
6 changes: 0 additions & 6 deletions distr/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -26153,9 +26153,6 @@ struct each_delegate : public delegate {
static void invoke_callback(
ecs_iter_t *iter, const Func& func, size_t i, Args... comps)
{
ecs_assert(iter->count > 0, ECS_INVALID_OPERATION,
"no entities returned, use each() without flecs::entity argument");

func(flecs::entity(iter->world, iter->entities[i]),
(ColumnType< remove_reference_t<Components> >(iter, comps, i)
.get_row())...);
Expand Down Expand Up @@ -26272,9 +26269,6 @@ struct find_delegate : public delegate {
size_t count = static_cast<size_t>(iter->count);
flecs::entity result;

ecs_assert(count > 0, ECS_INVALID_OPERATION,
"no entities returned, use find() without flecs::entity argument");

for (size_t i = 0; i < count; i ++) {
if (func(flecs::entity(world, iter->entities[i]),
(ColumnType< remove_reference_t<Components> >(iter, comps, i)
Expand Down
6 changes: 0 additions & 6 deletions include/flecs/addons/cpp/delegate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,6 @@ struct each_delegate : public delegate {
static void invoke_callback(
ecs_iter_t *iter, const Func& func, size_t i, Args... comps)
{
ecs_assert(iter->count > 0, ECS_INVALID_OPERATION,
"no entities returned, use each() without flecs::entity argument");

func(flecs::entity(iter->world, iter->entities[i]),
(ColumnType< remove_reference_t<Components> >(iter, comps, i)
.get_row())...);
Expand Down Expand Up @@ -420,9 +417,6 @@ struct find_delegate : public delegate {
size_t count = static_cast<size_t>(iter->count);
flecs::entity result;

ecs_assert(count > 0, ECS_INVALID_OPERATION,
"no entities returned, use find() without flecs::entity argument");

for (size_t i = 0; i < count; i ++) {
if (func(flecs::entity(world, iter->entities[i]),
(ColumnType< remove_reference_t<Components> >(iter, comps, i)
Expand Down
2 changes: 2 additions & 0 deletions test/cpp/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -674,6 +674,8 @@
"find",
"find_not_found",
"find_w_entity",
"find_w_match_empty_tables",
"find_w_entity_w_match_empty_tables",
"optional_pair_term",
"empty_tables_each",
"empty_tables_each_w_entity",
Expand Down
36 changes: 36 additions & 0 deletions test/cpp/src/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,42 @@ void Query_find_w_entity(void) {
test_assert(r == e2);
}

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

auto e1 = ecs.entity().set<Position>({10, 20}).add<Velocity>();
e1.destruct(); // creates empty table
auto e2 = ecs.entity().set<Position>({20, 30});

auto q = ecs.query_builder<Position>()
.query_flags(EcsQueryMatchEmptyTables)
.build();

auto r = q.find([](Position& p) {
return p.x == 20;
});

test_assert(r == e2);
}

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

auto e1 = ecs.entity().set<Position>({10, 20}).add<Velocity>();
e1.destruct(); // creates empty table
auto e2 = ecs.entity().set<Position>({20, 30});

auto q = ecs.query_builder<Position>()
.query_flags(EcsQueryMatchEmptyTables)
.build();

auto r = q.find([](flecs::entity e, Position& p) {
return p.x == 20;
});

test_assert(r == e2);
}

// Generic lambdas are a C++14 feature.

struct GenericLambdaFindEntity {
Expand Down
12 changes: 11 additions & 1 deletion test/cpp/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,8 @@ void Query_iter_get_pair_w_id(void);
void Query_find(void);
void Query_find_not_found(void);
void Query_find_w_entity(void);
void Query_find_w_match_empty_tables(void);
void Query_find_w_entity_w_match_empty_tables(void);
void Query_optional_pair_term(void);
void Query_empty_tables_each(void);
void Query_empty_tables_each_w_entity(void);
Expand Down Expand Up @@ -3919,6 +3921,14 @@ bake_test_case Query_testcases[] = {
"find_w_entity",
Query_find_w_entity
},
{
"find_w_match_empty_tables",
Query_find_w_match_empty_tables
},
{
"find_w_entity_w_match_empty_tables",
Query_find_w_entity_w_match_empty_tables
},
{
"optional_pair_term",
Query_optional_pair_term
Expand Down Expand Up @@ -6908,7 +6918,7 @@ static bake_test_suite suites[] = {
"Query",
NULL,
NULL,
116,
118,
Query_testcases
},
{
Expand Down