1#include <iter_info.h>
2#include <iostream>
3
4struct Position {
5 double x, y;
6};
7
8struct Velocity {
9 double x, y;
10};
11
12struct Mass {
13 double value;
14};
15
16int main(int, char *[]) {
18
19
21 ecs.
query<Position,
const Velocity>();
22
23
25 .set<Position>({10, 20})
26 .set<Velocity>({1, 2});
27
29 .set<Position>({10, 20})
30 .set<Velocity>({3, 4});
31
33 .set<Position>({10, 20})
34 .set<Velocity>({4, 5})
35 .set<Mass>({50});
36
37
38
41 auto p = it.
field<Position>(0);
42 auto v = it.
field<
const Velocity>(1);
43
44
45 std::cout <<
"Table [" << it.
type().
str() <<
"]" << std::endl;
46 std::cout <<
" - number of entities: " << it.
count() << std::endl;
47
48
50 std::cout << " - term " << i << ": " << std::endl;
51 std::cout <<
" - component: " << it.
id(i).
str() << std::endl;
52 std::cout <<
" - type size: " << it.
size(i) << std::endl;
53 }
54
55 std::cout << std::endl;
56
57
58 for (auto i : it) {
59 p[i].x += v[i].x;
60 p[i].y += v[i].y;
61 std::cout << " - " << it.entity(i).name() <<
62 ": {" << p[i].x << ", " << p[i].y << "}\n";
63 }
64
65 std::cout << std::endl;
66 }
67 });
68}
conditional_t< sizeof...(Args)==0 &&_::is_sparse_query< Comps... >::value, flecs::sparse_query< Comps... >, flecs::query< Comps... > > query(Args &&... args) const
Create a query.
flecs::entity entity(Args &&... args) const
Create an entity.
flecs::string str() const
Convert ID to string.
Class for iterating over query results.
flecs::id id(int8_t index) const
Obtain the ID matched for the field.
size_t size(int8_t index) const
Size of the field data type.
flecs::field< A > field(int8_t index) const
Get read-only access to field data.
flecs::type type() const
Get the type of the iterated table.
int32_t field_count() const
Number of fields in the iterator.
size_t count() const
Get the number of entities to iterate over.
bool next()
Progress iterator.
void run(Func &&func) const
Run the iterator.
flecs::string str() const
Convert the type to a comma-separated string.