1#include <basics.h>
2#include <stdio.h>
3
4typedef struct {
5 double x;
6 double y;
7} Position, Velocity;
8
9int main(int argc, char *argv[]) {
11
14
15
16
18 .terms = {
19 { .id =
ecs_id(Position) },
21 },
22
23
25 });
26
27
29 ecs_set(ecs, e1, Position, {10, 20});
30 ecs_set(ecs, e1, Velocity, {1, 2});
31
33 ecs_set(ecs, e2, Position, {10, 20});
34 ecs_set(ecs, e2, Velocity, {3, 4});
35
36
38 ecs_set(ecs, e3, Position, {10, 20});
39
40
42
43
45 Position *p =
ecs_field(&it, Position, 0);
46 const Velocity *v =
ecs_field(&it, Velocity, 1);
47
48
49 for (int i = 0; i < it.count; i ++) {
50 p[i].x += v[i].x;
51 p[i].y += v[i].y;
52 printf(
"%s: {%f, %f}\n",
ecs_get_name(ecs, it.entities[i]),
53 p[i].x, p[i].y);
54 }
55 }
56
57
59
61}
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.
#define ecs_entity(world,...)
Shorthand for creating an entity with ecs_entity_init().
#define ECS_COMPONENT(world, id)
Declare and define a component.
#define ecs_query(world,...)
Shorthand for creating a query with ecs_query_init().
#define ecs_set(world, entity, component,...)
Set a component value.
#define ecs_field(it, T, index)
Get field data for a component.
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.
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.
@ EcsQueryCacheAuto
Cache query terms that are cacheable.
@ EcsIn
Term is only read.
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.
Queries are lists of constraints (terms) that match entities.