1#include <basics.h>
2#include <stdio.h>
3
4typedef struct {
5 double x, y;
6} Position;
7
8int main(int argc, char *argv[]) {
10
13
14
16
17
18 ecs_set(ecs, bob, Position, {10, 20});
19
20
22
23
24 const Position *ptr =
ecs_get(ecs, bob, Position);
25 printf("{%f, %f}\n", ptr->x, ptr->y);
26
27
28 ecs_set(ecs, bob, Position, {20, 30});
29
30
32 ecs_set(ecs, alice, Position, {10, 20});
34
35
36
38 printf("[%s]\n", str);
39 ecs_os_free(str);
40
41
43
44
47 Position *p =
ecs_field(&it, Position, 0);
48 for (
int i = 0; i < it.
count; i ++) {
50 p[i].x, p[i].y);
51 }
52 }
53
55
56
57
58
59
60
61}
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.
bool ecs_each_next(ecs_iter_t *it)
Progress an iterator created with ecs_each_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_remove(world, entity, T)
Remove a component from 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.
#define ecs_get(world, entity, T)
Get a component.
#define ecs_field(it, T, index)
Get field data for a component.
#define ecs_each(world, id)
Iterate entities with a component.
ecs_entity_t ecs_set_name(ecs_world_t *world, ecs_entity_t entity, const char *name)
Set the name of an entity.
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.
int32_t count
Number of entities to iterate.
const ecs_entity_t * entities
Entity identifiers.