1#include <override.h>
2#include <stdio.h>
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20typedef struct {
21 double value;
22} Attack, Defense, Damage;
23
24int main(int argc, char *argv[]) {
26
30
31
34
37
38 ecs_set(ecs, SpaceShip, Attack, { 75 });
39 ecs_set(ecs, SpaceShip, Defense, { 100 });
40 ecs_set(ecs, SpaceShip, Damage, { 50 });
41
42
45
46
47
48
50 printf("instance type = [%s]\n", type);
51 ecs_os_free(type);
52
53
54
56
57
59 printf("instance type = [%s]\n", type);
60 ecs_os_free(type);
61
62
63
64
65 const Attack *attack =
ecs_get(ecs, inst, Attack);
66 const Defense *defense =
ecs_get(ecs, inst, Defense);
67 const Damage *damage =
ecs_get(ecs, inst, Damage);
68
69 printf("attack: %f\n", attack->value);
70 printf("defense: %f\n", defense->value);
71 printf("damage: %f\n", damage->value);
72
73
74
75
76
77
78
79
81}
void ecs_add_id(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component)
Add a (component) ID to an entity.
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.
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_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_get(world, entity, T)
Get a component.
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.