From 3ca10b675cf378970c7a1ffbbe83298fc89bd42a Mon Sep 17 00:00:00 2001 From: Sander Mertens Date: Fri, 12 May 2023 11:05:38 -0700 Subject: [PATCH] Change argument of app::enable_rest to REST port --- flecs.c | 2 +- flecs.h | 8 +++++--- include/flecs/addons/app.h | 3 ++- include/flecs/addons/cpp/mixins/app/builder.hpp | 5 +++-- src/addons/app.c | 2 +- 5 files changed, 12 insertions(+), 8 deletions(-) diff --git a/flecs.c b/flecs.c index 224a483c50..92e08f614f 100644 --- a/flecs.c +++ b/flecs.c @@ -44586,7 +44586,7 @@ int ecs_app_run( #ifdef ECS_TARGET_EM flecs_wasm_rest_server = ecs_rest_server_init(world, NULL); #else - ecs_set(world, EcsWorld, EcsRest, {.port = 0}); + ecs_set(world, EcsWorld, EcsRest, {.port = desc->port }); #endif #else ecs_warn("cannot enable remote API, REST addon not available"); diff --git a/flecs.h b/flecs.h index ef82cc79da..08ae5d89fd 100644 --- a/flecs.h +++ b/flecs.h @@ -9630,8 +9630,9 @@ typedef struct ecs_app_desc_t { ecs_ftime_t delta_time; /**< Frame time increment (0 for measured values) */ int32_t threads; /**< Number of threads. */ int32_t frames; /**< Number of frames to run (0 for infinite) */ - bool enable_rest; /**< Allows HTTP clients to access ECS data */ + bool enable_rest; /**< Enables ECS access over HTTP, necessary for explorer */ bool enable_monitor; /**< Periodically collect statistics */ + uint16_t port; /**< HTTP port used by REST API */ ecs_app_init_action_t init; /**< If set, function is ran before starting the * main loop. */ @@ -17477,8 +17478,9 @@ struct app_builder { return *this; } - app_builder& enable_rest(bool value = true) { - m_desc.enable_rest = value; + app_builder& enable_rest(uint16_t port = 0) { + m_desc.enable_rest = true; + m_desc.port = port; return *this; } diff --git a/include/flecs/addons/app.h b/include/flecs/addons/app.h index fa42795e3a..d71dee09fd 100644 --- a/include/flecs/addons/app.h +++ b/include/flecs/addons/app.h @@ -39,8 +39,9 @@ typedef struct ecs_app_desc_t { ecs_ftime_t delta_time; /**< Frame time increment (0 for measured values) */ int32_t threads; /**< Number of threads. */ int32_t frames; /**< Number of frames to run (0 for infinite) */ - bool enable_rest; /**< Allows HTTP clients to access ECS data */ + bool enable_rest; /**< Enables ECS access over HTTP, necessary for explorer */ bool enable_monitor; /**< Periodically collect statistics */ + uint16_t port; /**< HTTP port used by REST API */ ecs_app_init_action_t init; /**< If set, function is ran before starting the * main loop. */ diff --git a/include/flecs/addons/cpp/mixins/app/builder.hpp b/include/flecs/addons/cpp/mixins/app/builder.hpp index 96fff0f569..331c97715b 100644 --- a/include/flecs/addons/cpp/mixins/app/builder.hpp +++ b/include/flecs/addons/cpp/mixins/app/builder.hpp @@ -47,8 +47,9 @@ struct app_builder { return *this; } - app_builder& enable_rest(bool value = true) { - m_desc.enable_rest = value; + app_builder& enable_rest(uint16_t port = 0) { + m_desc.enable_rest = true; + m_desc.port = port; return *this; } diff --git a/src/addons/app.c b/src/addons/app.c index a58d314579..87e053d3ce 100644 --- a/src/addons/app.c +++ b/src/addons/app.c @@ -96,7 +96,7 @@ int ecs_app_run( #ifdef ECS_TARGET_EM flecs_wasm_rest_server = ecs_rest_server_init(world, NULL); #else - ecs_set(world, EcsWorld, EcsRest, {.port = 0}); + ecs_set(world, EcsWorld, EcsRest, {.port = desc->port }); #endif #else ecs_warn("cannot enable remote API, REST addon not available");