1#include <ser_opaque_vector.h>
2#include <stdio.h>
3
4
5typedef struct {
6 size_t count;
7 int32_t *array;
8} IntVector;
9
10
12 const IntVector *data = ptr;
13 for (size_t i = 0; i < data->count; i ++) {
15 }
16 return 0;
17}
18
19size_t IntVector_count(const void *ptr) {
20 const IntVector *data = ptr;
21 return data->count;
22}
23
24static void IntVector_resize(void *ptr, size_t size) {
25 IntVector *data = ptr;
26 if (data->count != size) {
27 data->count = size;
28 if (!data->count) {
29 ecs_os_free(data->array);
30 data->array = NULL;
31 } else {
32 data->array = ecs_os_realloc_n(data->array, int32_t, (ecs_size_t)size);
33 }
34 }
35}
36
37static void* IntVector_ensure_element(void *ptr, size_t index) {
38 IntVector *data = ptr;
39 if (data->count <= index) {
40 IntVector_resize(ptr, index + 1);
41 }
42 return &data->
array[index];
43}
44
45int main(int argc, char *argv[]) {
47
48
50
51
52
54
55 .entity =
ecs_id(IntVector),
56 .type = {
57
59
60 .serialize = IntVector_serialize,
61 .count = IntVector_count,
62 .resize = IntVector_resize,
63 .ensure_element = IntVector_ensure_element
64 }
65 });
66
67 IntVector v = {0};
68
69
71
72
73 printf("[");
74 for (size_t i = 0; i < v.count; i ++) {
75 if (i) printf(", ");
76 printf("%d", v.array[i]);
77 }
78 printf("]\n");
79
80
82 printf("%s\n", json);
83 ecs_os_free(json);
84
85
86
87 ecs_os_free(v.array);
88
90
91
92
93
94}
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component ID for EcsDocDescription.
FLECS_API char * ecs_ptr_to_json(const ecs_world_t *world, ecs_entity_t type, const void *data)
Serialize value into JSON string.
FLECS_API const char * ecs_ptr_from_json(const ecs_world_t *world, ecs_entity_t type, void *ptr, const char *json, const ecs_from_json_desc_t *desc)
Parse JSON string into value.
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
#define ECS_COMPONENT(world, id)
Declare and define 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.
int(*) value(const struct ecs_serializer_t *ser, ecs_entity_t type, const void *value)
Serialize value.