Flecs v3.1
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 if (m_desc.target_fps == static_cast<ecs_ftime_t>(0.0)) {
26 m_desc.target_fps = 60;
27 }
28 }
29
30 app_builder& target_fps(ecs_ftime_t value) {
31 m_desc.target_fps = value;
32 return *this;
33 }
34
35 app_builder& delta_time(ecs_ftime_t value) {
36 m_desc.delta_time = value;
37 return *this;
38 }
39
40 app_builder& threads(int32_t value) {
41 m_desc.threads = value;
42 return *this;
43 }
44
45 app_builder& frames(int32_t value) {
46 m_desc.frames = value;
47 return *this;
48 }
49
50 app_builder& enable_rest(bool value = true) {
51 m_desc.enable_rest = value;
52 return *this;
53 }
54
55 app_builder& enable_monitor(bool value = true) {
56 m_desc.enable_monitor = value;
57 return *this;
58 }
59
61 m_desc.init = value;
62 return *this;
63 }
64
65 app_builder& ctx(void *value) {
66 m_desc.ctx = value;
67 return *this;
68 }
69
70 int run() {
71 int result = ecs_app_run(m_world, &m_desc);
72 if (ecs_should_quit(m_world)) {
73 // Only free world if quit flag is set. This ensures that we won't
74 // try to cleanup the world if the app is used in an environment
75 // that takes over the main loop, like with emscripten.
76 ecs_fini(m_world);
77 }
78 return result;
79 }
80
81private:
82 flecs::world_t *m_world;
83 ecs_app_desc_t m_desc;
84};
85
88}
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
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:45
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:48
bool enable_rest
Allows HTTP clients to access ECS data.
Definition: app.h:42
int32_t threads
Number of threads.
Definition: app.h:40
Type that contains information about the world.
Definition: flecs.h:928
float target_fps
Target fps.
Definition: flecs.h:937
App builder interface.
Definition: builder.hpp:18
The world.
Definition: world.hpp:113