1#include <relation_component.h>
2#include <stdio.h>
3
4
5
6
7
8
9typedef struct {
10 double amount;
11} Requires;
12
13typedef struct {
14 double timeout;
15} Expires;
16
17typedef struct {
18 double x;
19 double y;
20} Position;
21
22int main(int argc, char *argv[]) {
24
28
31
32
33
36 const Requires *r =
ecs_get_pair(ecs, e1, Requires, Gigawatts);
37 printf("requires: %.2f\n", r->amount);
38
39
43 printf("requires: %.2f\n", r->amount);
44
45
46
47
48
49
53 printf("expires: %.1f\n", e->timeout);
54
55
56
58
59
60
62
63
65 char *type_str;
66
69 printf("%s\n", type_str);
70 ecs_os_free(type_str);
71
74 printf("%s\n", type_str);
75 ecs_os_free(type_str);
76
79 printf("%s\n", type_str);
80 ecs_os_free(type_str);
81
84 printf("%s\n", type_str);
85 ecs_os_free(type_str);
86
87
89 .terms = {
90 { .id = ecs_pair(
ecs_id(Requires), Gigawatts) }
91 }
92 });
93
94
98 for (int i = 0; i < it.count; i ++) {
99 printf("requires %.2f gigawatts\n", r[i].amount);
100 }
101 }
102
103
104
105
106
107
108
109
110
111
112}
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Add a (component) ID to an entity.
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.
ecs_entity_t ecs_new(ecs_world_t *world)
Create new entity ID.
#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_get_pair_second(world, subject, first, Second)
Get the second element of a pair.
#define ecs_get_pair(world, subject, First, second)
Get the first element of a pair.
#define ecs_set_pair_second(world, subject, first, Second,...)
Set the second element of a pair.
#define ecs_set_pair(world, subject, First, second,...)
Set the first element of a pair.
#define ecs_field(it, T, index)
Get field data for a component.
ecs_entity_t ecs_get_typeid(const ecs_world_t *world, ecs_id_t component)
Get the type for a component.
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.
ecs_world_t * ecs_init_w_args(int argc, char *argv[])
Create a new world with arguments.
Queries are lists of constraints (terms) that match entities.