1#include <on_validate.h>
2#include <stdio.h>
3
4
5
6
7
8
9typedef struct {
10 double x, y;
11} Position;
12
13
15 (void)world; (void)e;
16 Position *p = ptr;
17 return p->x >= 0 && p->x <= 100 && p->y >= 0 && p->y <= 100;
18}
19
22
23 for (
int i = 0; i < it->
count; i ++) {
24 printf("%s set to {%.0f, %.0f}\n",
26 }
27}
28
29int main(int argc, char *argv[]) {
31
33
35 .on_validate = validate_position,
36 .on_set = on_set_position
37 });
38
40
41
42 ecs_set(world, e, Position, {50, 50});
43
44
45 ecs_set(world, e, Position, {150, 50});
46
48
49
50
51}
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_set_hooks(world, T,...)
Set component hooks.
#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.
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.