diff --git a/distr/flecs.c b/distr/flecs.c index 9980b892b..71d489c09 100644 --- a/distr/flecs.c +++ b/distr/flecs.c @@ -62384,39 +62384,47 @@ void FlecsWorldMonitorImport( ECS_COMPONENT_DECLARE(EcsWorldSummary); -static -void UpdateWorldSummary(ecs_iter_t *it) { - EcsWorldSummary *summary = ecs_field(it, EcsWorldSummary, 0); +static +void flecs_copy_world_summary( + ecs_world_t *world, + EcsWorldSummary *dst) +{ + const ecs_world_info_t *info = ecs_get_world_info(world); - const ecs_world_info_t *info = ecs_get_world_info(it->world); + dst->target_fps = (double)info->target_fps; + dst->time_scale = (double)info->time_scale; - int32_t i, count = it->count; - for (i = 0; i < count; i ++) { - summary[i].target_fps = (double)info->target_fps; - summary[i].time_scale = (double)info->time_scale; + dst->frame_time_last = (double)info->frame_time_total - dst->frame_time_total; + dst->system_time_last = (double)info->system_time_total - dst->system_time_total; + dst->merge_time_last = (double)info->merge_time_total - dst->merge_time_total; - summary[i].frame_time_last = (double)info->frame_time_total - summary[i].frame_time_total; - summary[i].system_time_last = (double)info->system_time_total - summary[i].system_time_total; - summary[i].merge_time_last = (double)info->merge_time_total - summary[i].merge_time_total; + dst->frame_time_total = (double)info->frame_time_total; + dst->system_time_total = (double)info->system_time_total; + dst->merge_time_total = (double)info->merge_time_total; - summary[i].frame_time_total = (double)info->frame_time_total; - summary[i].system_time_total = (double)info->system_time_total; - summary[i].merge_time_total = (double)info->merge_time_total; + dst->frame_count ++; + dst->command_count += + info->cmd.add_count + + info->cmd.remove_count + + info->cmd.delete_count + + info->cmd.clear_count + + info->cmd.set_count + + info->cmd.ensure_count + + info->cmd.modified_count + + info->cmd.discard_count + + info->cmd.event_count + + info->cmd.other_count; - summary[i].frame_count ++; - summary[i].command_count += - info->cmd.add_count + - info->cmd.remove_count + - info->cmd.delete_count + - info->cmd.clear_count + - info->cmd.set_count + - info->cmd.ensure_count + - info->cmd.modified_count + - info->cmd.discard_count + - info->cmd.event_count + - info->cmd.other_count; + dst->build_info = *ecs_get_build_info(); +} + +static +void UpdateWorldSummary(ecs_iter_t *it) { + EcsWorldSummary *summary = ecs_field(it, EcsWorldSummary, 0); - summary[i].build_info = *ecs_get_build_info(); + int32_t i, count = it->count; + for (i = 0; i < count; i ++) { + flecs_copy_world_summary(it->world, &summary[i]); } } @@ -62479,6 +62487,10 @@ void FlecsWorldSummaryImport( .target_fps = (double)info->target_fps, .time_scale = (double)info->time_scale }); + + EcsWorldSummary *summary = ecs_ensure(world, EcsWorld, EcsWorldSummary); + flecs_copy_world_summary(world, summary); + ecs_modified(world, EcsWorld, EcsWorldSummary); } #endif diff --git a/src/addons/stats/world_summary.c b/src/addons/stats/world_summary.c index 6f1ea6d63..cb856de2b 100644 --- a/src/addons/stats/world_summary.c +++ b/src/addons/stats/world_summary.c @@ -10,39 +10,47 @@ ECS_COMPONENT_DECLARE(EcsWorldSummary); +static +void flecs_copy_world_summary( + ecs_world_t *world, + EcsWorldSummary *dst) +{ + const ecs_world_info_t *info = ecs_get_world_info(world); + + dst->target_fps = (double)info->target_fps; + dst->time_scale = (double)info->time_scale; + + dst->frame_time_last = (double)info->frame_time_total - dst->frame_time_total; + dst->system_time_last = (double)info->system_time_total - dst->system_time_total; + dst->merge_time_last = (double)info->merge_time_total - dst->merge_time_total; + + dst->frame_time_total = (double)info->frame_time_total; + dst->system_time_total = (double)info->system_time_total; + dst->merge_time_total = (double)info->merge_time_total; + + dst->frame_count ++; + dst->command_count += + info->cmd.add_count + + info->cmd.remove_count + + info->cmd.delete_count + + info->cmd.clear_count + + info->cmd.set_count + + info->cmd.ensure_count + + info->cmd.modified_count + + info->cmd.discard_count + + info->cmd.event_count + + info->cmd.other_count; + + dst->build_info = *ecs_get_build_info(); +} + static void UpdateWorldSummary(ecs_iter_t *it) { EcsWorldSummary *summary = ecs_field(it, EcsWorldSummary, 0); - const ecs_world_info_t *info = ecs_get_world_info(it->world); - int32_t i, count = it->count; for (i = 0; i < count; i ++) { - summary[i].target_fps = (double)info->target_fps; - summary[i].time_scale = (double)info->time_scale; - - summary[i].frame_time_last = (double)info->frame_time_total - summary[i].frame_time_total; - summary[i].system_time_last = (double)info->system_time_total - summary[i].system_time_total; - summary[i].merge_time_last = (double)info->merge_time_total - summary[i].merge_time_total; - - summary[i].frame_time_total = (double)info->frame_time_total; - summary[i].system_time_total = (double)info->system_time_total; - summary[i].merge_time_total = (double)info->merge_time_total; - - summary[i].frame_count ++; - summary[i].command_count += - info->cmd.add_count + - info->cmd.remove_count + - info->cmd.delete_count + - info->cmd.clear_count + - info->cmd.set_count + - info->cmd.ensure_count + - info->cmd.modified_count + - info->cmd.discard_count + - info->cmd.event_count + - info->cmd.other_count; - - summary[i].build_info = *ecs_get_build_info(); + flecs_copy_world_summary(it->world, &summary[i]); } } @@ -105,6 +113,10 @@ void FlecsWorldSummaryImport( .target_fps = (double)info->target_fps, .time_scale = (double)info->time_scale }); + + EcsWorldSummary *summary = ecs_ensure(world, EcsWorld, EcsWorldSummary); + flecs_copy_world_summary(world, summary); + ecs_modified(world, EcsWorld, EcsWorldSummary); } #endif diff --git a/test/addons/include/addons/bake_config.h b/test/addons/include/addons/bake_config.h index f6eccefc6..a130e8aff 100644 --- a/test/addons/include/addons/bake_config.h +++ b/test/addons/include/addons/bake_config.h @@ -1,25 +1,25 @@ -/* - ) - (.) - .|. - | | - _.--| |--._ - .-'; ;`-'& ; `&. - \ & ; & &_/ - |"""---...---"""| - \ | | | | | | | / - `---.|.|.|.---' - - * This file is generated by bake.lang.c for your convenience. Headers of - * dependencies will automatically show up in this file. Include bake_config.h - * in your main project file. Do not edit! */ - -#ifndef ADDONS_BAKE_CONFIG_H -#define ADDONS_BAKE_CONFIG_H - -/* Headers of public dependencies */ -#include -#include - -#endif - +/* + ) + (.) + .|. + | | + _.--| |--._ + .-'; ;`-'& ; `&. + \ & ; & &_/ + |"""---...---"""| + \ | | | | | | | / + `---.|.|.|.---' + + * This file is generated by bake.lang.c for your convenience. Headers of + * dependencies will automatically show up in this file. Include bake_config.h + * in your main project file. Do not edit! */ + +#ifndef ADDONS_BAKE_CONFIG_H +#define ADDONS_BAKE_CONFIG_H + +/* Headers of public dependencies */ +#include +#include + +#endif + diff --git a/test/addons/project.json b/test/addons/project.json index 6eaf341ae..4914642a6 100644 --- a/test/addons/project.json +++ b/test/addons/project.json @@ -129,7 +129,7 @@ "invalid_entity_id", "invalid_null_string", "invalid_empty_string", - "invalid_empty_string_w_space", + "invalid_empty_string_w_space", "redefine_row_system", "system_w_or_prefab", "system_w_or_disabled", @@ -499,7 +499,8 @@ "request_commands_garbage_collect", "script_error", "import_rest_after_mini", - "get_pipeline_stats_after_delete_system" + "get_pipeline_stats_after_delete_system", + "request_world_summary_before_monitor_sys_run" ] }, { "id": "Metrics", diff --git a/test/addons/src/Rest.c b/test/addons/src/Rest.c index 13b76f876..4dd3f8b1e 100644 --- a/test/addons/src/Rest.c +++ b/test/addons/src/Rest.c @@ -542,3 +542,25 @@ void Rest_get_pipeline_stats_after_delete_system(void) { ecs_fini(world); } + +void Rest_request_world_summary_before_monitor_sys_run(void) { + ecs_world_t *world = ecs_init(); + + ECS_IMPORT(world, FlecsStats); + + ecs_http_server_t *srv = ecs_rest_server_init(world, NULL); + test_assert(srv != NULL); + + ecs_http_reply_t reply = ECS_HTTP_REPLY_INIT; + test_int(0, ecs_http_server_request(srv, "GET", + "/entity/flecs/core/World?values=true", &reply)); + test_int(reply.code, 200); + + char *reply_str = ecs_strbuf_get(&reply.body); + test_assert(reply_str != NULL); + ecs_os_free(reply_str); + + ecs_rest_server_fini(srv); + + ecs_fini(world); +} diff --git a/test/addons/src/main.c b/test/addons/src/main.c index 9f24aa406..073212d16 100644 --- a/test/addons/src/main.c +++ b/test/addons/src/main.c @@ -452,6 +452,7 @@ void Rest_request_commands_garbage_collect(void); void Rest_script_error(void); void Rest_import_rest_after_mini(void); void Rest_get_pipeline_stats_after_delete_system(void); +void Rest_request_world_summary_before_monitor_sys_run(void); // Testsuite 'Metrics' void Metrics_member_gauge_1_entity(void); @@ -2183,6 +2184,10 @@ bake_test_case Rest_testcases[] = { { "get_pipeline_stats_after_delete_system", Rest_get_pipeline_stats_after_delete_system + }, + { + "request_world_summary_before_monitor_sys_run", + Rest_request_world_summary_before_monitor_sys_run } }; @@ -2635,7 +2640,7 @@ static bake_test_suite suites[] = { "Rest", NULL, NULL, - 16, + 17, Rest_testcases }, {