1#include <iterate_components.h>
2#include <stdio.h>
3
4typedef struct {
5 double x, y;
6} Position, Velocity;
7
9
11
12
14 printf("ecs_type_str: %s\n\n", type_str);
15 ecs_os_free(type_str);
16
17
19 int32_t i, count = type->
count;
20
21 for (i = 0; i < count; i ++) {
24 printf("%d: %s\n", i, id_str);
25 ecs_os_free(id_str);
26 }
27
28 printf("\n");
29
30
31
32
33 for (i = 0; i < count; i ++) {
35
36 printf("%d: ", i);
37
38 if (ECS_HAS_ID_FLAG(id, PAIR)) {
41 printf("rel: %s, tgt: %s",
43 } else {
46 }
47
48 printf("\n");
49 }
50
51 printf("\n\n");
52}
53
54int main(int argc, char *argv[]) {
56
57
60
61
63
64
67
68
70
71 ecs_set(ecs, Bob, Position, {10, 20});
72 ecs_set(ecs, Bob, Velocity, {1, 1});
75
76
77 printf("Bob's components:\n");
78 iterate_components(ecs, Bob);
79
80
81 printf("Position's components:\n");
82 iterate_components(ecs,
ecs_id(Position));
83
85}
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
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.
ecs_entity_t ecs_new(ecs_world_t *world)
Create new entity ID.
const ecs_type_t * ecs_get_type(const ecs_world_t *world, ecs_entity_t entity)
Get the type of an entity.
char * ecs_type_str(const ecs_world_t *world, const ecs_type_t *type)
Convert a type to a string.
#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_COMPONENT(world, id)
Declare and define a component.
#define ECS_TAG(world, id)
Declare and define a tag.
#define ecs_set(world, entity, component,...)
Set a component value.
char * ecs_id_str(const ecs_world_t *world, ecs_id_t component)
Convert a component ID to a string.
const char * ecs_get_name(const ecs_world_t *world, ecs_entity_t entity)
Get the name of an entity.
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.
A type is a list of (component) IDs.
ecs_id_t * array
Array with IDs.
int32_t count
Number of elements in array.