Skip to content

Commit

Permalink
Add build info to WorldSummary component
Browse files Browse the repository at this point in the history
  • Loading branch information
SanderMertens committed Mar 13, 2024
1 parent bc933e6 commit b968586
Show file tree
Hide file tree
Showing 9 changed files with 128 additions and 15 deletions.
53 changes: 51 additions & 2 deletions flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -30812,6 +30812,8 @@ void UpdateWorldSummary(ecs_iter_t *it) {
summary[i].merge_time_total = (double)info->merge_time_total;

summary[i].frame_count ++;

summary[i].build_info = *ecs_get_build_info();
}
}

Expand Down Expand Up @@ -31092,6 +31094,7 @@ void FlecsMonitorImport(
ECS_COMPONENT_DEFINE(world, EcsWorldSummary);

#if defined(FLECS_META) && defined(FLECS_UNITS)
ecs_entity_t build_info = ecs_lookup(world, "flecs.core.build_info_t");
ecs_struct(world, {
.entity = ecs_id(EcsWorldSummary),
.members = {
Expand All @@ -31102,7 +31105,8 @@ void FlecsMonitorImport(
{ .name = "frame_time_last", .type = ecs_id(ecs_f64_t), .unit = EcsSeconds },
{ .name = "system_time_last", .type = ecs_id(ecs_f64_t), .unit = EcsSeconds },
{ .name = "merge_time_last", .type = ecs_id(ecs_f64_t), .unit = EcsSeconds },
{ .name = "frame_count", .type = ecs_id(ecs_u64_t) }
{ .name = "frame_count", .type = ecs_id(ecs_u64_t) },
{ .name = "build_info", .type = build_info }
}
});
#endif
Expand Down Expand Up @@ -58343,6 +58347,28 @@ double ecs_meta_ptr_to_float(

#ifdef FLECS_META

/* Opaque type serializatior addon vector */
static
int flecs_addon_vec_serialize(const ecs_serializer_t *ser, const void *ptr) {
char ***data = ECS_CONST_CAST(char***, ptr);
char **addons = data[0];
do {
ser->value(ser, ecs_id(ecs_string_t), addons);
} while((++ addons)[0]);
return 0;
}

static
size_t flecs_addon_vec_count(const void *ptr) {
int32_t count = 0;
char ***data = ECS_CONST_CAST(char***, ptr);
char **addons = data[0];
do {
++ count;
} while(addons[count]);
return flecs_ito(size_t, count);
}

/* Initialize reflection data for core components */
static
void flecs_meta_import_core_definitions(
Expand All @@ -58356,14 +58382,34 @@ void flecs_meta_import_core_definitions(
}
});

ecs_entity_t string_vec = ecs_vector(world, {
.entity = ecs_entity(world, { .name = "flecs.core.string_vec_t "}),
.type = ecs_id(ecs_string_t)
});

ecs_entity_t addon_vec = ecs_opaque(world, {
.entity = ecs_component(world, {
.type = {
.name = "flecs.core.addon_vec_t",
.size = ECS_SIZEOF(char**),
.alignment = ECS_ALIGNOF(char**)
}
}),
.type = {
.as_type = string_vec,
.serialize = flecs_addon_vec_serialize,
.count = flecs_addon_vec_count,
}
});

ecs_struct(world, {
.entity = ecs_entity(world, {
.name = "flecs.core.build_info_t",
.root_sep = ""
}),
.members = {
{ .name = "compiler", .type = ecs_id(ecs_string_t) },
{ .name = "addons", .type = ecs_id(ecs_string_t) },
{ .name = "addons", .type = addon_vec },
{ .name = "version", .type = ecs_id(ecs_string_t) },
{ .name = "version_major", .type = ecs_id(ecs_i16_t) },
{ .name = "version_minor", .type = ecs_id(ecs_i16_t) },
Expand All @@ -58379,12 +58425,15 @@ static
void flecs_meta_import_doc_definitions(
ecs_world_t *world)
{
(void)world;
#ifdef FLECS_DOC
ecs_struct(world, {
.entity = ecs_id(EcsDocDescription),
.members = {
{ .name = "value", .type = ecs_id(ecs_string_t) }
}
});
#endif
}

/* Initialize reflection data for meta components */
Expand Down
14 changes: 11 additions & 3 deletions flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@
* @{
*/

/* Flecs version macro */
#define FLECS_VERSION_MAJOR 3
#define FLECS_VERSION_MINOR 2
#define FLECS_VERSION_PATCH 12
#define FLECS_VERSION__(major, minor, patch) #major "." #minor "." #patch
#define FLECS_VERSION_(major, minor, patch) FLECS_VERSION__(major, minor, patch)
#define FLECS_VERSION FLECS_VERSION_(FLECS_VERSION_MAJOR, FLECS_VERSION_MINOR, FLECS_VERSION_PATCH)
#define FLECS_VERSION FLECS_VERSION_IMPL(\
FLECS_VERSION_MAJOR, FLECS_VERSION_MINOR, FLECS_VERSION_PATCH)

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

/* Utilities to convert flecs version to string */
#define FLECS_VERSION_IMPLSTR(major, minor, patch) #major "." #minor "." #patch
#define FLECS_VERSION_IMPL(major, minor, patch) \
FLECS_VERSION_IMPLSTR(major, minor, patch)

#define ECS_CONCAT(a, b) a ## b

////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -12497,6 +12502,9 @@ typedef struct {

/* Frame count */
int64_t frame_count; /**< Number of frames processed */

/* Build info */
ecs_build_info_t build_info; /**< Build info */
} EcsWorldSummary;

/* Module import */
Expand Down
6 changes: 3 additions & 3 deletions include/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@
* @{
*/

/* Flecs version macro */
#define FLECS_VERSION_MAJOR 3
#define FLECS_VERSION_MINOR 2
#define FLECS_VERSION_PATCH 12
#define FLECS_VERSION__(major, minor, patch) #major "." #minor "." #patch
#define FLECS_VERSION_(major, minor, patch) FLECS_VERSION__(major, minor, patch)
#define FLECS_VERSION FLECS_VERSION_(FLECS_VERSION_MAJOR, FLECS_VERSION_MINOR, FLECS_VERSION_PATCH)
#define FLECS_VERSION FLECS_VERSION_IMPL(\
FLECS_VERSION_MAJOR, FLECS_VERSION_MINOR, FLECS_VERSION_PATCH)

/** @def FLECS_CONFIG_HEADER
* Allows for including a user-customizable header that specifies compile-time
Expand Down
3 changes: 3 additions & 0 deletions include/flecs/addons/monitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ typedef struct {

/* Frame count */
int64_t frame_count; /**< Number of frames processed */

/* Build info */
ecs_build_info_t build_info; /**< Build info */
} EcsWorldSummary;

/* Module import */
Expand Down
5 changes: 5 additions & 0 deletions include/flecs/private/api_defines.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ typedef struct ecs_allocator_t ecs_allocator_t;
#define ECS_EQZERO(a) ECS_EQ(a, (uint64_t){0})
#define ECS_NEQZERO(a) ECS_NEQ(a, (uint64_t){0})

/* Utilities to convert flecs version to string */
#define FLECS_VERSION_IMPLSTR(major, minor, patch) #major "." #minor "." #patch
#define FLECS_VERSION_IMPL(major, minor, patch) \
FLECS_VERSION_IMPLSTR(major, minor, patch)

#define ECS_CONCAT(a, b) a ## b

////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ endif

flecs_src = files(
'src/addons/alerts.c',
'src/addons/coredoc.c',
'src/addons/doc.c',
'src/addons/expr/deserialize.c',
'src/addons/expr/serialize.c',
Expand Down
47 changes: 46 additions & 1 deletion src/addons/meta/definitions.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,28 @@

#ifdef FLECS_META

/* Opaque type serializatior addon vector */
static
int flecs_addon_vec_serialize(const ecs_serializer_t *ser, const void *ptr) {
char ***data = ECS_CONST_CAST(char***, ptr);
char **addons = data[0];
do {
ser->value(ser, ecs_id(ecs_string_t), addons);
} while((++ addons)[0]);
return 0;
}

static
size_t flecs_addon_vec_count(const void *ptr) {
int32_t count = 0;
char ***data = ECS_CONST_CAST(char***, ptr);
char **addons = data[0];
do {
++ count;
} while(addons[count]);
return flecs_ito(size_t, count);
}

/* Initialize reflection data for core components */
static
void flecs_meta_import_core_definitions(
Expand All @@ -21,14 +43,34 @@ void flecs_meta_import_core_definitions(
}
});

ecs_entity_t string_vec = ecs_vector(world, {
.entity = ecs_entity(world, { .name = "flecs.core.string_vec_t "}),
.type = ecs_id(ecs_string_t)
});

ecs_entity_t addon_vec = ecs_opaque(world, {
.entity = ecs_component(world, {
.type = {
.name = "flecs.core.addon_vec_t",
.size = ECS_SIZEOF(char**),
.alignment = ECS_ALIGNOF(char**)
}
}),
.type = {
.as_type = string_vec,
.serialize = flecs_addon_vec_serialize,
.count = flecs_addon_vec_count,
}
});

ecs_struct(world, {
.entity = ecs_entity(world, {
.name = "flecs.core.build_info_t",
.root_sep = ""
}),
.members = {
{ .name = "compiler", .type = ecs_id(ecs_string_t) },
{ .name = "addons", .type = ecs_id(ecs_string_t) },
{ .name = "addons", .type = addon_vec },
{ .name = "version", .type = ecs_id(ecs_string_t) },
{ .name = "version_major", .type = ecs_id(ecs_i16_t) },
{ .name = "version_minor", .type = ecs_id(ecs_i16_t) },
Expand All @@ -44,12 +86,15 @@ static
void flecs_meta_import_doc_definitions(
ecs_world_t *world)
{
(void)world;
#ifdef FLECS_DOC
ecs_struct(world, {
.entity = ecs_id(EcsDocDescription),
.members = {
{ .name = "value", .type = ecs_id(ecs_string_t) }
}
});
#endif
}

/* Initialize reflection data for meta components */
Expand Down
6 changes: 5 additions & 1 deletion src/addons/monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ void UpdateWorldSummary(ecs_iter_t *it) {
summary[i].merge_time_total = (double)info->merge_time_total;

summary[i].frame_count ++;

summary[i].build_info = *ecs_get_build_info();
}
}

Expand Down Expand Up @@ -339,6 +341,7 @@ void FlecsMonitorImport(
ECS_COMPONENT_DEFINE(world, EcsWorldSummary);

#if defined(FLECS_META) && defined(FLECS_UNITS)
ecs_entity_t build_info = ecs_lookup(world, "flecs.core.build_info_t");
ecs_struct(world, {
.entity = ecs_id(EcsWorldSummary),
.members = {
Expand All @@ -349,7 +352,8 @@ void FlecsMonitorImport(
{ .name = "frame_time_last", .type = ecs_id(ecs_f64_t), .unit = EcsSeconds },
{ .name = "system_time_last", .type = ecs_id(ecs_f64_t), .unit = EcsSeconds },
{ .name = "merge_time_last", .type = ecs_id(ecs_f64_t), .unit = EcsSeconds },
{ .name = "frame_count", .type = ecs_id(ecs_u64_t) }
{ .name = "frame_count", .type = ecs_id(ecs_u64_t) },
{ .name = "build_info", .type = build_info }
}
});
#endif
Expand Down
8 changes: 4 additions & 4 deletions test/meta/src/SerializeEntityToJson.c
Original file line number Diff line number Diff line change
Expand Up @@ -1104,13 +1104,13 @@ void SerializeEntityToJson_serialize_w_2_alerts(void) {
"\"path\":\"e1\", "
"\"ids\":[[\"Position\"]], "
"\"alerts\":[{"
"\"alert\":\"position_without_velocity.e1_alert_1\", "
"\"message\":\"e1 has Position but not Velocity\", "
"\"severity\":\"Error\""
"}, {"
"\"alert\":\"position_without_mass.e1_alert_2\", "
"\"message\":\"e1 has Position but not Mass\", "
"\"severity\":\"Error\""
"}, {"
"\"alert\":\"position_without_velocity.e1_alert_1\", "
"\"message\":\"e1 has Position but not Velocity\", "
"\"severity\":\"Error\""
"}]"
"}");
ecs_os_free(json);
Expand Down

0 comments on commit b968586

Please sign in to comment.