Flecs
v4.1
A fast entity component system (ECS) for C & C++
Toggle main menu visibility
Loading...
Searching...
No Matches
builder.hpp
Go to the documentation of this file.
1
5
6
#pragma once
7
8
namespace
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
33
app_builder&
target_fps
(
ecs_ftime_t
value) {
34
desc_.
target_fps
= value;
35
return
*
this
;
36
}
37
39
app_builder&
delta_time
(
ecs_ftime_t
value) {
40
desc_.
delta_time
= value;
41
return
*
this
;
42
}
43
45
app_builder&
threads
(int32_t value) {
46
desc_.
threads
= value;
47
return
*
this
;
48
}
49
51
app_builder&
frames
(int32_t value) {
52
desc_.
frames
= value;
53
return
*
this
;
54
}
55
57
app_builder&
enable_rest
(uint16_t port = 0) {
58
desc_.
enable_rest
=
true
;
59
desc_.port = port;
60
return
*
this
;
61
}
62
64
app_builder&
enable_stats
(
bool
value =
true
) {
65
desc_.
enable_stats
= value;
66
return
*
this
;
67
}
68
70
app_builder&
init
(
ecs_app_init_action_t
value) {
71
desc_.
init
= value;
72
return
*
this
;
73
}
74
76
app_builder&
ctx
(
void
*value) {
77
desc_.
ctx
= value;
78
return
*
this
;
79
}
80
82
int
run
() {
83
int
result =
ecs_app_run
(world_, &desc_);
84
if
(
ecs_should_quit
(world_)) {
85
// Only free world if quit flag is set. This ensures that we won't
86
// try to clean up the world if the app is used in an environment
87
// that takes over the main loop, like with emscripten.
88
if
(!flecs_poly_release(world_)) {
89
ecs_fini
(world_);
90
}
91
}
92
return
result;
93
}
94
95
private
:
96
flecs::world_t
*world_;
97
ecs_app_desc_t
desc_;
98
};
99
101
102
}
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.
flecs::world_t
ecs_world_t world_t
World type.
Definition
c_types.hpp:18
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 the 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:1504
flecs::app_builder::frames
app_builder & frames(int32_t value)
Set the number of frames to run.
Definition
builder.hpp:51
flecs::app_builder::init
app_builder & init(ecs_app_init_action_t value)
Set the init callback.
Definition
builder.hpp:70
flecs::app_builder::run
int run()
Run the application.
Definition
builder.hpp:82
flecs::app_builder::enable_stats
app_builder & enable_stats(bool value=true)
Enable statistics collection.
Definition
builder.hpp:64
flecs::app_builder::threads
app_builder & threads(int32_t value)
Set the number of threads.
Definition
builder.hpp:45
flecs::app_builder::enable_rest
app_builder & enable_rest(uint16_t port=0)
Enable the REST API.
Definition
builder.hpp:57
flecs::app_builder::delta_time
app_builder & delta_time(ecs_ftime_t value)
Set the fixed delta time for each frame.
Definition
builder.hpp:39
flecs::app_builder::target_fps
app_builder & target_fps(ecs_ftime_t value)
Set the target frames per second.
Definition
builder.hpp:33
flecs::app_builder::ctx
app_builder & ctx(void *value)
Set the application context.
Definition
builder.hpp:76
flecs::stats
Stats module.
Definition
decl.hpp:28
flecs::world
The world.
Definition
world.hpp:246