Flecs: include/flecs/addons/cpp/mixins/app/builder.hpp Source File
Description: A fast entity component system (ECS) for C & C++

| Flecs v4.0 A fast entity component system (ECS) for C & C++

Loading...
Searching...
No Matches
builder.hpp
Go to the documentation of this file.
1
5
6#pragma once
7
8namespace flecs {
9
17
19 struct app_builder {
20 app_builder(flecs::world_t *world)
21 : world_(world)
22 , desc_{}
23 {
24 const ecs_world_info_t *stats = ecs_get_world_info(world);
25 desc_.target_fps = stats->target_fps;
26 ecs_ftime_t t_zero = 0.0;
27 if (ECS_EQ(desc_.target_fps, t_zero)) {
28 desc_.target_fps = 60;
29 }
30 }
31
32 app_builder& target_fps(ecs_ftime_t value) {
33 desc_.target_fps = value;
34 return *this;
35 }
36
37 app_builder& delta_time(ecs_ftime_t value) {
38 desc_.delta_time = value;
39 return *this;
40 }
41
42 app_builder& threads(int32_t value) {
43 desc_.threads = value;
44 return *this;
45 }
46
47 app_builder& frames(int32_t value) {
48 desc_.frames = value;
49 return *this;
50 }
51
52 app_builder& enable_rest(uint16_t port = 0) {
53 desc_.enable_rest = true;
54 desc_.port = port;
55 return *this;
56 }
57
58 app_builder& enable_stats(bool value = true) {
59 desc_.enable_stats = value;
60 return *this;
61 }
62
63 app_builder& init(ecs_app_init_action_t value) {
64 desc_.init = value;
65 return *this;
66 }
67
68 app_builder& ctx(void *value) {
69 desc_.ctx = value;
70 return *this;
71 }
72
73 int run() {
74 int result = ecs_app_run(world_, &desc_);
75 if (ecs_should_quit(world_)) {
76 // Only free world if quit flag is set. This ensures that we won't
77 // try to cleanup the world if the app is used in an environment
78 // that takes over the main loop, like with emscripten.
79 if (!flecs_poly_release(world_)) {
80 ecs_fini(world_);
81 }
82 }
83 return result;
84 }
85
86private:
87 flecs::world_t *world_;
88 ecs_app_desc_t desc_;
89};
90
92
93}
ecs_app_init_action_t
int(* ecs_app_init_action_t)(ecs_world_t *world)
Callback type for init action.
Definition app.h:33
ecs_app_run
FLECS_API int ecs_app_run(ecs_world_t *world, ecs_app_desc_t *desc)
Run application.
ecs_ftime_t
#define ecs_ftime_t
Customizable precision for scalar time values.
Definition flecs.h:59
ecs_fini
int ecs_fini(ecs_world_t *world)
Delete a world.
ecs_should_quit
bool ecs_should_quit(const ecs_world_t *world)
Return whether a quit has been requested.
ecs_get_world_info
const ecs_world_info_t * ecs_get_world_info(const ecs_world_t *world)
Get world info.
ecs_app_desc_t
Used with ecs_app_run().
Definition app.h:37
ecs_world_info_t
Type that contains information about the world.
Definition flecs.h:1439
flecs::stats
Definition decl.hpp:27
flecs::world
The world.
Definition world.hpp:137