Skip to content

Commit b968586

Browse files
committed
Add build info to WorldSummary component
1 parent bc933e6 commit b968586

File tree

9 files changed

+128
-15
lines changed

9 files changed

+128
-15
lines changed

flecs.c

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30812,6 +30812,8 @@ void UpdateWorldSummary(ecs_iter_t *it) {
3081230812
summary[i].merge_time_total = (double)info->merge_time_total;
3081330813

3081430814
summary[i].frame_count ++;
30815+
30816+
summary[i].build_info = *ecs_get_build_info();
3081530817
}
3081630818
}
3081730819

@@ -31092,6 +31094,7 @@ void FlecsMonitorImport(
3109231094
ECS_COMPONENT_DEFINE(world, EcsWorldSummary);
3109331095

3109431096
#if defined(FLECS_META) && defined(FLECS_UNITS)
31097+
ecs_entity_t build_info = ecs_lookup(world, "flecs.core.build_info_t");
3109531098
ecs_struct(world, {
3109631099
.entity = ecs_id(EcsWorldSummary),
3109731100
.members = {
@@ -31102,7 +31105,8 @@ void FlecsMonitorImport(
3110231105
{ .name = "frame_time_last", .type = ecs_id(ecs_f64_t), .unit = EcsSeconds },
3110331106
{ .name = "system_time_last", .type = ecs_id(ecs_f64_t), .unit = EcsSeconds },
3110431107
{ .name = "merge_time_last", .type = ecs_id(ecs_f64_t), .unit = EcsSeconds },
31105-
{ .name = "frame_count", .type = ecs_id(ecs_u64_t) }
31108+
{ .name = "frame_count", .type = ecs_id(ecs_u64_t) },
31109+
{ .name = "build_info", .type = build_info }
3110631110
}
3110731111
});
3110831112
#endif
@@ -58343,6 +58347,28 @@ double ecs_meta_ptr_to_float(
5834358347

5834458348
#ifdef FLECS_META
5834558349

58350+
/* Opaque type serializatior addon vector */
58351+
static
58352+
int flecs_addon_vec_serialize(const ecs_serializer_t *ser, const void *ptr) {
58353+
char ***data = ECS_CONST_CAST(char***, ptr);
58354+
char **addons = data[0];
58355+
do {
58356+
ser->value(ser, ecs_id(ecs_string_t), addons);
58357+
} while((++ addons)[0]);
58358+
return 0;
58359+
}
58360+
58361+
static
58362+
size_t flecs_addon_vec_count(const void *ptr) {
58363+
int32_t count = 0;
58364+
char ***data = ECS_CONST_CAST(char***, ptr);
58365+
char **addons = data[0];
58366+
do {
58367+
++ count;
58368+
} while(addons[count]);
58369+
return flecs_ito(size_t, count);
58370+
}
58371+
5834658372
/* Initialize reflection data for core components */
5834758373
static
5834858374
void flecs_meta_import_core_definitions(
@@ -58356,14 +58382,34 @@ void flecs_meta_import_core_definitions(
5835658382
}
5835758383
});
5835858384

58385+
ecs_entity_t string_vec = ecs_vector(world, {
58386+
.entity = ecs_entity(world, { .name = "flecs.core.string_vec_t "}),
58387+
.type = ecs_id(ecs_string_t)
58388+
});
58389+
58390+
ecs_entity_t addon_vec = ecs_opaque(world, {
58391+
.entity = ecs_component(world, {
58392+
.type = {
58393+
.name = "flecs.core.addon_vec_t",
58394+
.size = ECS_SIZEOF(char**),
58395+
.alignment = ECS_ALIGNOF(char**)
58396+
}
58397+
}),
58398+
.type = {
58399+
.as_type = string_vec,
58400+
.serialize = flecs_addon_vec_serialize,
58401+
.count = flecs_addon_vec_count,
58402+
}
58403+
});
58404+
5835958405
ecs_struct(world, {
5836058406
.entity = ecs_entity(world, {
5836158407
.name = "flecs.core.build_info_t",
5836258408
.root_sep = ""
5836358409
}),
5836458410
.members = {
5836558411
{ .name = "compiler", .type = ecs_id(ecs_string_t) },
58366-
{ .name = "addons", .type = ecs_id(ecs_string_t) },
58412+
{ .name = "addons", .type = addon_vec },
5836758413
{ .name = "version", .type = ecs_id(ecs_string_t) },
5836858414
{ .name = "version_major", .type = ecs_id(ecs_i16_t) },
5836958415
{ .name = "version_minor", .type = ecs_id(ecs_i16_t) },
@@ -58379,12 +58425,15 @@ static
5837958425
void flecs_meta_import_doc_definitions(
5838058426
ecs_world_t *world)
5838158427
{
58428+
(void)world;
58429+
#ifdef FLECS_DOC
5838258430
ecs_struct(world, {
5838358431
.entity = ecs_id(EcsDocDescription),
5838458432
.members = {
5838558433
{ .name = "value", .type = ecs_id(ecs_string_t) }
5838658434
}
5838758435
});
58436+
#endif
5838858437
}
5838958438

5839058439
/* Initialize reflection data for meta components */

flecs.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232
* @{
3333
*/
3434

35+
/* Flecs version macro */
3536
#define FLECS_VERSION_MAJOR 3
3637
#define FLECS_VERSION_MINOR 2
3738
#define FLECS_VERSION_PATCH 12
38-
#define FLECS_VERSION__(major, minor, patch) #major "." #minor "." #patch
39-
#define FLECS_VERSION_(major, minor, patch) FLECS_VERSION__(major, minor, patch)
40-
#define FLECS_VERSION FLECS_VERSION_(FLECS_VERSION_MAJOR, FLECS_VERSION_MINOR, FLECS_VERSION_PATCH)
39+
#define FLECS_VERSION FLECS_VERSION_IMPL(\
40+
FLECS_VERSION_MAJOR, FLECS_VERSION_MINOR, FLECS_VERSION_PATCH)
4141

4242
/** @def FLECS_CONFIG_HEADER
4343
* Allows for including a user-customizable header that specifies compile-time
@@ -800,6 +800,11 @@ typedef struct ecs_allocator_t ecs_allocator_t;
800800
#define ECS_EQZERO(a) ECS_EQ(a, (uint64_t){0})
801801
#define ECS_NEQZERO(a) ECS_NEQ(a, (uint64_t){0})
802802

803+
/* Utilities to convert flecs version to string */
804+
#define FLECS_VERSION_IMPLSTR(major, minor, patch) #major "." #minor "." #patch
805+
#define FLECS_VERSION_IMPL(major, minor, patch) \
806+
FLECS_VERSION_IMPLSTR(major, minor, patch)
807+
803808
#define ECS_CONCAT(a, b) a ## b
804809

805810
////////////////////////////////////////////////////////////////////////////////
@@ -12497,6 +12502,9 @@ typedef struct {
1249712502

1249812503
/* Frame count */
1249912504
int64_t frame_count; /**< Number of frames processed */
12505+
12506+
/* Build info */
12507+
ecs_build_info_t build_info; /**< Build info */
1250012508
} EcsWorldSummary;
1250112509

1250212510
/* Module import */

include/flecs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@
3030
* @{
3131
*/
3232

33+
/* Flecs version macro */
3334
#define FLECS_VERSION_MAJOR 3
3435
#define FLECS_VERSION_MINOR 2
3536
#define FLECS_VERSION_PATCH 12
36-
#define FLECS_VERSION__(major, minor, patch) #major "." #minor "." #patch
37-
#define FLECS_VERSION_(major, minor, patch) FLECS_VERSION__(major, minor, patch)
38-
#define FLECS_VERSION FLECS_VERSION_(FLECS_VERSION_MAJOR, FLECS_VERSION_MINOR, FLECS_VERSION_PATCH)
37+
#define FLECS_VERSION FLECS_VERSION_IMPL(\
38+
FLECS_VERSION_MAJOR, FLECS_VERSION_MINOR, FLECS_VERSION_PATCH)
3939

4040
/** @def FLECS_CONFIG_HEADER
4141
* Allows for including a user-customizable header that specifies compile-time

include/flecs/addons/monitor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ typedef struct {
7373

7474
/* Frame count */
7575
int64_t frame_count; /**< Number of frames processed */
76+
77+
/* Build info */
78+
ecs_build_info_t build_info; /**< Build info */
7679
} EcsWorldSummary;
7780

7881
/* Module import */

include/flecs/private/api_defines.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,11 @@ typedef struct ecs_allocator_t ecs_allocator_t;
257257
#define ECS_EQZERO(a) ECS_EQ(a, (uint64_t){0})
258258
#define ECS_NEQZERO(a) ECS_NEQ(a, (uint64_t){0})
259259

260+
/* Utilities to convert flecs version to string */
261+
#define FLECS_VERSION_IMPLSTR(major, minor, patch) #major "." #minor "." #patch
262+
#define FLECS_VERSION_IMPL(major, minor, patch) \
263+
FLECS_VERSION_IMPLSTR(major, minor, patch)
264+
260265
#define ECS_CONCAT(a, b) a ## b
261266

262267
////////////////////////////////////////////////////////////////////////////////

meson.build

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ endif
2020

2121
flecs_src = files(
2222
'src/addons/alerts.c',
23-
'src/addons/coredoc.c',
2423
'src/addons/doc.c',
2524
'src/addons/expr/deserialize.c',
2625
'src/addons/expr/serialize.c',

src/addons/meta/definitions.c

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,28 @@
88

99
#ifdef FLECS_META
1010

11+
/* Opaque type serializatior addon vector */
12+
static
13+
int flecs_addon_vec_serialize(const ecs_serializer_t *ser, const void *ptr) {
14+
char ***data = ECS_CONST_CAST(char***, ptr);
15+
char **addons = data[0];
16+
do {
17+
ser->value(ser, ecs_id(ecs_string_t), addons);
18+
} while((++ addons)[0]);
19+
return 0;
20+
}
21+
22+
static
23+
size_t flecs_addon_vec_count(const void *ptr) {
24+
int32_t count = 0;
25+
char ***data = ECS_CONST_CAST(char***, ptr);
26+
char **addons = data[0];
27+
do {
28+
++ count;
29+
} while(addons[count]);
30+
return flecs_ito(size_t, count);
31+
}
32+
1133
/* Initialize reflection data for core components */
1234
static
1335
void flecs_meta_import_core_definitions(
@@ -21,14 +43,34 @@ void flecs_meta_import_core_definitions(
2143
}
2244
});
2345

46+
ecs_entity_t string_vec = ecs_vector(world, {
47+
.entity = ecs_entity(world, { .name = "flecs.core.string_vec_t "}),
48+
.type = ecs_id(ecs_string_t)
49+
});
50+
51+
ecs_entity_t addon_vec = ecs_opaque(world, {
52+
.entity = ecs_component(world, {
53+
.type = {
54+
.name = "flecs.core.addon_vec_t",
55+
.size = ECS_SIZEOF(char**),
56+
.alignment = ECS_ALIGNOF(char**)
57+
}
58+
}),
59+
.type = {
60+
.as_type = string_vec,
61+
.serialize = flecs_addon_vec_serialize,
62+
.count = flecs_addon_vec_count,
63+
}
64+
});
65+
2466
ecs_struct(world, {
2567
.entity = ecs_entity(world, {
2668
.name = "flecs.core.build_info_t",
2769
.root_sep = ""
2870
}),
2971
.members = {
3072
{ .name = "compiler", .type = ecs_id(ecs_string_t) },
31-
{ .name = "addons", .type = ecs_id(ecs_string_t) },
73+
{ .name = "addons", .type = addon_vec },
3274
{ .name = "version", .type = ecs_id(ecs_string_t) },
3375
{ .name = "version_major", .type = ecs_id(ecs_i16_t) },
3476
{ .name = "version_minor", .type = ecs_id(ecs_i16_t) },
@@ -44,12 +86,15 @@ static
4486
void flecs_meta_import_doc_definitions(
4587
ecs_world_t *world)
4688
{
89+
(void)world;
90+
#ifdef FLECS_DOC
4791
ecs_struct(world, {
4892
.entity = ecs_id(EcsDocDescription),
4993
.members = {
5094
{ .name = "value", .type = ecs_id(ecs_string_t) }
5195
}
5296
});
97+
#endif
5398
}
5499

55100
/* Initialize reflection data for meta components */

src/addons/monitor.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ void UpdateWorldSummary(ecs_iter_t *it) {
5959
summary[i].merge_time_total = (double)info->merge_time_total;
6060

6161
summary[i].frame_count ++;
62+
63+
summary[i].build_info = *ecs_get_build_info();
6264
}
6365
}
6466

@@ -339,6 +341,7 @@ void FlecsMonitorImport(
339341
ECS_COMPONENT_DEFINE(world, EcsWorldSummary);
340342

341343
#if defined(FLECS_META) && defined(FLECS_UNITS)
344+
ecs_entity_t build_info = ecs_lookup(world, "flecs.core.build_info_t");
342345
ecs_struct(world, {
343346
.entity = ecs_id(EcsWorldSummary),
344347
.members = {
@@ -349,7 +352,8 @@ void FlecsMonitorImport(
349352
{ .name = "frame_time_last", .type = ecs_id(ecs_f64_t), .unit = EcsSeconds },
350353
{ .name = "system_time_last", .type = ecs_id(ecs_f64_t), .unit = EcsSeconds },
351354
{ .name = "merge_time_last", .type = ecs_id(ecs_f64_t), .unit = EcsSeconds },
352-
{ .name = "frame_count", .type = ecs_id(ecs_u64_t) }
355+
{ .name = "frame_count", .type = ecs_id(ecs_u64_t) },
356+
{ .name = "build_info", .type = build_info }
353357
}
354358
});
355359
#endif

test/meta/src/SerializeEntityToJson.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,13 +1104,13 @@ void SerializeEntityToJson_serialize_w_2_alerts(void) {
11041104
"\"path\":\"e1\", "
11051105
"\"ids\":[[\"Position\"]], "
11061106
"\"alerts\":[{"
1107-
"\"alert\":\"position_without_velocity.e1_alert_1\", "
1108-
"\"message\":\"e1 has Position but not Velocity\", "
1109-
"\"severity\":\"Error\""
1110-
"}, {"
11111107
"\"alert\":\"position_without_mass.e1_alert_2\", "
11121108
"\"message\":\"e1 has Position but not Mass\", "
11131109
"\"severity\":\"Error\""
1110+
"}, {"
1111+
"\"alert\":\"position_without_velocity.e1_alert_1\", "
1112+
"\"message\":\"e1 has Position but not Velocity\", "
1113+
"\"severity\":\"Error\""
11141114
"}]"
11151115
"}");
11161116
ecs_os_free(json);

0 commit comments

Comments
 (0)