1#include <transitive_queries.h>
2#include <stdio.h>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17int main(int argc, char *argv[]) {
19
20
23
24
31
32
35
36
38 ecs_add(ecs, north_america, Continent);
40
42 ecs_add(ecs, europe, Continent);
44
45
47 ecs_add(ecs, united_states, Country);
48 ecs_add_pair(ecs, united_states, LocatedIn, north_america);
49
51 ecs_add(ecs, netherlands, Country);
53
54
56 ecs_add(ecs, california, State);
58
60 ecs_add(ecs, washington, State);
62
64 ecs_add(ecs, noord_holland, State);
65 ecs_add_pair(ecs, noord_holland, LocatedIn, netherlands);
66
67
69 ecs_add(ecs, san_francisco, City);
71
75
79
80
84
88
92
93
94
95
96
97
98
99
101 .terms = {
102 { .id = Person },
103 { .first.id = LocatedIn, .second.name = "$location" },
104 { .first.id = Country, .src.name = "$location" }
105 }
106 });
107
108
109
111
112
116 for (
int i = 0; i < it.
count; i ++) {
117 printf("%s lives in %s\n",
120 }
121 }
122
124
125
126
127
128
129
131}
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Add a (component) ID to an entity.
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.
ecs_entity_t ecs_new(ecs_world_t *world)
Create new entity ID.
#define ecs_add_pair(world, subject, first, second)
Add a pair to an entity.
#define ecs_add(world, entity, T)
Add a component to an entity.
#define ecs_entity(world,...)
Shorthand for creating an entity with ecs_entity_init().
#define ECS_TAG(world, id)
Declare and define a tag.
#define ecs_query(world,...)
Shorthand for creating a query with ecs_query_init().
ecs_entity_t ecs_iter_get_var(ecs_iter_t *it, int32_t var_id)
Get the value of an iterator variable as an entity.
const char * ecs_get_name(const ecs_world_t *world, ecs_entity_t entity)
Get the name of an entity.
bool ecs_query_next(ecs_iter_t *it)
Progress a query iterator.
int32_t ecs_query_find_var(const ecs_query_t *query, const char *name)
Find a variable index.
void ecs_query_fini(ecs_query_t *query)
Delete a query.
ecs_iter_t ecs_query_iter(const ecs_world_t *world, const ecs_query_t *query)
Create a query iterator.
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.
int32_t count
Number of entities to iterate.
const ecs_entity_t * entities
Entity identifiers.
Queries are lists of constraints (terms) that match entities.