Flecs v3.2
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
builder.hpp
Go to the documentation of this file.
1
6#pragma once
7
8namespace flecs {
9
19 app_builder(flecs::world_t *world)
20 : m_world(world)
21 , m_desc{}
22 {
24 m_desc.target_fps = stats->target_fps;
25 ecs_ftime_t t_zero = 0.0;
26 if (ECS_EQ(m_desc.target_fps, t_zero)) {
27 m_desc.target_fps = 60;
28 }
29 }
30
31 app_builder& target_fps(ecs_ftime_t value) {
32 m_desc.target_fps = value;
33 return *this;
34 }
35
36 app_builder& delta_time(ecs_ftime_t value) {
37 m_desc.delta_time = value;
38 return *this;
39 }
40
41 app_builder& threads(int32_t value) {
42 m_desc.threads = value;
43 return *this;
44 }
45
46 app_builder& frames(int32_t value) {
47 m_desc.frames = value;
48 return *this;
49 }
50
51 app_builder& enable_rest(uint16_t port = 0) {
52 m_desc.enable_rest = true;
53 m_desc.port = port;
54 return *this;
55 }
56
57 app_builder& enable_monitor(bool value = true) {
58 m_desc.enable_monitor = value;
59 return *this;
60 }
61
63 m_desc.init = value;
64 return *this;
65 }
66
67 app_builder& ctx(void *value) {
68 m_desc.ctx = value;
69 return *this;
70 }
71
72 int run() {
73 int result = ecs_app_run(m_world, &m_desc);
74 if (ecs_should_quit(m_world)) {
75 // Only free world if quit flag is set. This ensures that we won't
76 // try to cleanup the world if the app is used in an environment
77 // that takes over the main loop, like with emscripten.
78 ecs_fini(m_world);
79 }
80 return result;
81 }
82
83private:
84 flecs::world_t *m_world;
85 ecs_app_desc_t m_desc;
86};
87
90}
int(* ecs_app_init_action_t)(ecs_world_t *world)
Callback type for init action.
Definition: app.h:33
FLECS_API int ecs_app_run(ecs_world_t *world, ecs_app_desc_t *desc)
Run application.
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition: flecs.h:42
int ecs_fini(ecs_world_t *world)
Delete a world.
bool ecs_should_quit(const ecs_world_t *world)
Return whether a quit has been signaled.
const ecs_world_info_t * ecs_get_world_info(const ecs_world_t *world)
Get world info.
Used with ecs_app_run.
Definition: app.h:37
uint16_t port
HTTP port used by REST API.
Definition: app.h:44
ecs_ftime_t target_fps
Target FPS.
Definition: app.h:38
ecs_ftime_t delta_time
Frame time increment (0 for measured values)
Definition: app.h:39
ecs_app_init_action_t init
If set, function is ran before starting the main loop.
Definition: app.h:46
int32_t frames
Number of frames to run (0 for infinite)
Definition: app.h:41
bool enable_monitor
Periodically collect statistics.
Definition: app.h:43
void * ctx
Reserved for custom run/frame actions.
Definition: app.h:49
bool enable_rest
Enables ECS access over HTTP, necessary for explorer.
Definition: app.h:42
int32_t threads
Number of threads.
Definition: app.h:40
Type that contains information about the world.
Definition: flecs.h:1184
float target_fps
Target fps.
Definition: flecs.h:1192
App builder interface.
Definition: builder.hpp:18
The world.
Definition: world.hpp:132