diff --git a/distr/flecs.h b/distr/flecs.h index dc7e06521..60521a053 100644 --- a/distr/flecs.h +++ b/distr/flecs.h @@ -28306,34 +28306,34 @@ struct iterable { return this->iter().first(); } - iter_iterable set_var(int var_id, flecs::entity_t value) { + iter_iterable set_var(int var_id, flecs::entity_t value) const { return this->iter().set_var(var_id, value); } - iter_iterable set_var(const char *name, flecs::entity_t value) { + iter_iterable set_var(const char *name, flecs::entity_t value) const { return this->iter().set_var(name, value); } - iter_iterable set_var(const char *name, flecs::table_t *value) { + iter_iterable set_var(const char *name, flecs::table_t *value) const { return this->iter().set_var(name, value); } - iter_iterable set_var(const char *name, ecs_table_range_t value) { + iter_iterable set_var(const char *name, ecs_table_range_t value) const { return this->iter().set_var(name, value); } - iter_iterable set_var(const char *name, flecs::table_range value) { + iter_iterable set_var(const char *name, flecs::table_range value) const { return this->iter().set_var(name, value); } // Limit results to tables with specified group id (grouped queries only) - iter_iterable set_group(uint64_t group_id) { + iter_iterable set_group(uint64_t group_id) const { return this->iter().set_group(group_id); } // Limit results to tables with specified group id (grouped queries only) template - iter_iterable set_group() { + iter_iterable set_group() const { return this->iter().template set_group(); } diff --git a/include/flecs/addons/cpp/utils/iterable.hpp b/include/flecs/addons/cpp/utils/iterable.hpp index 8f202875c..68624b251 100644 --- a/include/flecs/addons/cpp/utils/iterable.hpp +++ b/include/flecs/addons/cpp/utils/iterable.hpp @@ -110,34 +110,34 @@ struct iterable { return this->iter().first(); } - iter_iterable set_var(int var_id, flecs::entity_t value) { + iter_iterable set_var(int var_id, flecs::entity_t value) const { return this->iter().set_var(var_id, value); } - iter_iterable set_var(const char *name, flecs::entity_t value) { + iter_iterable set_var(const char *name, flecs::entity_t value) const { return this->iter().set_var(name, value); } - iter_iterable set_var(const char *name, flecs::table_t *value) { + iter_iterable set_var(const char *name, flecs::table_t *value) const { return this->iter().set_var(name, value); } - iter_iterable set_var(const char *name, ecs_table_range_t value) { + iter_iterable set_var(const char *name, ecs_table_range_t value) const { return this->iter().set_var(name, value); } - iter_iterable set_var(const char *name, flecs::table_range value) { + iter_iterable set_var(const char *name, flecs::table_range value) const { return this->iter().set_var(name, value); } // Limit results to tables with specified group id (grouped queries only) - iter_iterable set_group(uint64_t group_id) { + iter_iterable set_group(uint64_t group_id) const { return this->iter().set_group(group_id); } // Limit results to tables with specified group id (grouped queries only) template - iter_iterable set_group() { + iter_iterable set_group() const { return this->iter().template set_group(); } diff --git a/test/cpp/project.json b/test/cpp/project.json index 6425d85bd..73579eb99 100644 --- a/test/cpp/project.json +++ b/test/cpp/project.json @@ -669,6 +669,9 @@ "captured_query", "page_iter_captured_query", "worker_iter_captured_query", + "set_group_captured_query", + "set_var_captured_query", + "set_var_id_captured_query", "iter_entities", "iter_get_pair_w_id", "find", diff --git a/test/cpp/src/Query.cpp b/test/cpp/src/Query.cpp index dccf17cb2..67c13c8ac 100644 --- a/test/cpp/src/Query.cpp +++ b/test/cpp/src/Query.cpp @@ -2755,6 +2755,88 @@ void Query_worker_iter_captured_query(void) { }(); } + +void Query_set_group_captured_query(void) { + flecs::world ecs; + + flecs::entity Rel = ecs.entity(); + flecs::entity TgtA = ecs.entity(); + flecs::entity TgtB = ecs.entity(); + + flecs::query q = ecs.query_builder() + .group_by(Rel) + .build(); + + /* flecs::entity e_1 = */ ecs.entity().set({10, 20}).add(Rel, TgtA); + flecs::entity e_2 = ecs.entity().set({20, 30}).add(Rel, TgtB); + + [=]() { + int count = 0; + q.set_group(TgtB).each([&](flecs::entity e, Position& p) { + test_assert(e == e_2); + test_int(p.x, 20); + test_int(p.y, 30); + count ++; + }); + test_int(count, 1); + }(); +} + +void Query_set_var_captured_query(void) { + flecs::world ecs; + + flecs::entity Rel = ecs.entity(); + flecs::entity TgtA = ecs.entity(); + flecs::entity TgtB = ecs.entity(); + + flecs::query q = ecs.query_builder() + .with(Rel, "$var") + .build(); + + /* flecs::entity e_1 = */ ecs.entity().set({10, 20}).add(Rel, TgtA); + flecs::entity e_2 = ecs.entity().set({20, 30}).add(Rel, TgtB); + + [=]() { + int count = 0; + q.set_var("var", TgtB).each([&](flecs::entity e, Position& p) { + test_assert(e == e_2); + test_int(p.x, 20); + test_int(p.y, 30); + count ++; + }); + test_int(count, 1); + }(); +} + +void Query_set_var_id_captured_query(void) { + flecs::world ecs; + + flecs::entity Rel = ecs.entity(); + flecs::entity TgtA = ecs.entity(); + flecs::entity TgtB = ecs.entity(); + + flecs::query q = ecs.query_builder() + .with(Rel, "$var") + .build(); + + int var = q.find_var("var"); + test_assert(var != -1); + + /* flecs::entity e_1 = */ ecs.entity().set({10, 20}).add(Rel, TgtA); + flecs::entity e_2 = ecs.entity().set({20, 30}).add(Rel, TgtB); + + [=]() { + int count = 0; + q.set_var(var, TgtB).each([&](flecs::entity e, Position& p) { + test_assert(e == e_2); + test_int(p.x, 20); + test_int(p.y, 30); + count ++; + }); + test_int(count, 1); + }(); +} + void Query_iter_entities(void) { flecs::world ecs; diff --git a/test/cpp/src/main.cpp b/test/cpp/src/main.cpp index edd5957d1..7a5c45ac9 100644 --- a/test/cpp/src/main.cpp +++ b/test/cpp/src/main.cpp @@ -645,6 +645,9 @@ void Query_instanced_nested_query_w_world(void); void Query_captured_query(void); void Query_page_iter_captured_query(void); void Query_worker_iter_captured_query(void); +void Query_set_group_captured_query(void); +void Query_set_var_captured_query(void); +void Query_set_var_id_captured_query(void); void Query_iter_entities(void); void Query_iter_get_pair_w_id(void); void Query_find(void); @@ -3902,6 +3905,18 @@ bake_test_case Query_testcases[] = { "worker_iter_captured_query", Query_worker_iter_captured_query }, + { + "set_group_captured_query", + Query_set_group_captured_query + }, + { + "set_var_captured_query", + Query_set_var_captured_query + }, + { + "set_var_id_captured_query", + Query_set_var_id_captured_query + }, { "iter_entities", Query_iter_entities @@ -6923,7 +6938,7 @@ static bake_test_suite suites[] = { "Query", NULL, NULL, - 118, + 121, Query_testcases }, {