1#include <group_by_custom.h>
2#include <stdio.h>
3
4
5
6
7
8typedef struct {
9 double x, y;
10} Position;
11
14{
15 (void)ctx;
16
17
20 return ecs_pair_second(ecs, match);
21 }
22
23 return 0;
24}
25
26int main(int argc, char *argv[]) {
28
31
32
33
35
36
40
41
43 .terms = {
45 },
46 .group_by_callback = group_by_relation,
47 .group_by = Group
48 });
49
50
52 ecs_set(ecs, e1, Position, {1, 1});
53
55 ecs_set(ecs, e2, Position, {2, 2});
56
58 ecs_set(ecs, e3, Position, {3, 3});
59
61 ecs_set(ecs, e4, Position, {4, 4});
63
65 ecs_set(ecs, e5, Position, {5, 5});
67
69 ecs_set(ecs, e6, Position, {6, 6});
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
89 Position *p =
ecs_field(&it, Position, 0);
92
93 printf(" - group %s: table [%s]\n", group_str, table_str);
94
95 for (
int i = 0; i < it.
count; i ++) {
96 printf(" {%f, %f}\n", p[i].x, p[i].y);
97 }
98
99 ecs_os_free(group_str);
100 ecs_os_free(table_str);
101 printf("\n");
102 }
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
124}
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
ecs_id_t ecs_entity_t
An entity identifier.
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
uint64_t ecs_id_t
IDs are the things that can be added to an entity.
struct ecs_table_t ecs_table_t
A table stores entities and components for a specific type.
char * ecs_table_str(const ecs_world_t *world, const ecs_table_t *table)
Convert a table to a string.
#define ecs_add(world, entity, T)
Add a component to an entity.
#define ecs_new_w_pair(world, first, second)
Create a new entity with a pair.
#define ECS_COMPONENT(world, id)
Declare and define a component.
#define ECS_TAG(world, id)
Declare and define a tag.
#define ecs_query(world,...)
Shorthand for creating a query with ecs_query_init().
#define ecs_get_path(world, child)
Get path from root.
#define ecs_set(world, entity, component,...)
Set a component value.
#define ecs_field(it, T, index)
Get field data for a component.
uint64_t ecs_iter_get_group(const ecs_iter_t *it)
Return the group ID for the currently iterated result.
bool ecs_query_next(ecs_iter_t *it)
Progress a query iterator.
ecs_iter_t ecs_query_iter(const ecs_world_t *world, const ecs_query_t *query)
Create a query iterator.
int32_t ecs_search(const ecs_world_t *world, const ecs_table_t *table, ecs_id_t component, ecs_id_t *component_out)
Search for a component in a table type.
int ecs_fini(ecs_world_t *world)
Delete a world.
ecs_world_t * ecs_init_w_args(int argc, char *argv[])
Create a new world with arguments.
ecs_table_t * table
Current table.
int32_t count
Number of entities to iterate.
Queries are lists of constraints (terms) that match entities.