1#include <basics.h>
2#include <stdio.h>
3
4typedef struct {
5 double x, y;
6} Position, Velocity;
7
10 const Velocity *v =
ecs_field(it, Velocity, 1);
11
12 for (
int i = 0; i < it->
count; i ++) {
13 p[i].x += v[i].x;
14 p[i].y += v[i].y;
16 p[i].x, p[i].y);
17 }
18}
19
20int main(int argc, char *argv[]) {
22
25
26
28
29
30
31
33 .name = "Move"
34 }),
36 { .id =
ecs_id(Position) },
38 },
39 .callback = Move
40 });
41
42
43
44
45
47 ecs_set(ecs, e1, Position, {10, 20});
48 ecs_set(ecs, e1, Velocity, {1, 2});
49
51 ecs_set(ecs, e2, Position, {10, 20});
52 ecs_set(ecs, e2, Velocity, {3, 4});
53
54
56 ecs_set(ecs, e3, Position, {10, 20});
57
58
60
62}
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
#define ecs_system(world,...)
Shorthand for creating a system with ecs_system_init().
FLECS_API ecs_entity_t ecs_run(ecs_world_t *world, ecs_entity_t system, ecs_ftime_t delta_time, void *param)
Run a specific system manually.
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_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.
@ 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.
int32_t count
Number of entities to iterate.
const ecs_entity_t * entities
Entity identifiers.
conditional_t< sizeof...(Args)==0 &&_::is_sparse_query< Comps... >::value, flecs::sparse_query< Comps... >, flecs::query< Comps... > > query(Args &&... args) const
Create a query.