Flecs
v4.1
A fast entity component system (ECS) for C & C++
Toggle main menu visibility
Loading...
Searching...
No Matches
flecs_cpp.h
Go to the documentation of this file.
1
9
10
#ifdef FLECS_CPP
11
12
#ifndef FLECS_CPP_H
13
#define FLECS_CPP_H
14
15
#ifdef __cplusplus
16
extern
"C"
{
17
#endif
18
19
// The functions in this file can be used from C or C++, but these macros are only relevant to C++.
20
#ifdef __cplusplus
21
22
#if defined(__clang__)
23
#define ECS_FUNC_NAME_FRONT(type, name) ((sizeof(#type) + sizeof(" flecs::_::() [T = ") + sizeof(#name)) - 3u)
24
#define ECS_FUNC_NAME_BACK (sizeof("]") - 1u)
25
#define ECS_FUNC_NAME __PRETTY_FUNCTION__
26
#elif defined(__GNUC__)
27
#define ECS_FUNC_NAME_FRONT(type, name) ((sizeof(#type) + sizeof(" flecs::_::() [with T = ") + sizeof(#name)) - 3u)
28
#define ECS_FUNC_NAME_BACK (sizeof("]") - 1u)
29
#define ECS_FUNC_NAME __PRETTY_FUNCTION__
30
#elif defined(_WIN32)
31
#define ECS_FUNC_NAME_FRONT(type, name) ((sizeof(#type) + sizeof(" __cdecl flecs::_::<") + sizeof(#name)) - 3u)
32
#define ECS_FUNC_NAME_BACK (sizeof(">(void)") - 1u)
33
#define ECS_FUNC_NAME __FUNCSIG__
34
#else
35
#error "implicit component registration not supported"
36
#endif
37
38
#define ECS_FUNC_TYPE_LEN(type, name, str)\
39
(flecs::string::length(str) - (ECS_FUNC_NAME_FRONT(type, name) + ECS_FUNC_NAME_BACK))
40
41
#endif
42
51
FLECS_API
52
char
* ecs_cpp_get_type_name(
53
char
*type_name,
54
const
char
*func_name,
55
size_t
len,
56
size_t
front_len);
57
65
FLECS_API
66
char
* ecs_cpp_get_symbol_name(
67
/* If symbol_name is NULL, the function allocates a buffer with ecs_os_malloc().
68
* Callers must free the returned pointer with ecs_os_free(). */
69
char
*symbol_name,
70
const
char
*type_name,
71
/* If len is 0, the function derives it from type_name. */
72
size_t
len);
73
82
FLECS_API
83
char
* ecs_cpp_get_constant_name(
84
char
*constant_name,
85
const
char
*func_name,
86
size_t
len,
87
size_t
back_len);
88
95
FLECS_API
96
const
char
* ecs_cpp_trim_module(
97
ecs_world_t
*world,
98
const
char
*type_name);
99
100
typedef
void (*ecs_cpp_type_action_t)(
101
ecs_world_t
*world,
102
ecs_entity_t
component
);
103
104
typedef
struct
ecs_cpp_component_desc_t {
105
ecs_entity_t
id
;
106
int32_t ids_index;
107
const
char
*name;
108
const
char
*cpp_name;
109
const
char
*cpp_symbol;
110
size_t
size;
111
size_t
alignment;
112
ecs_cpp_type_action_t lifecycle_action;
113
ecs_cpp_type_action_t enum_action;
114
bool
is_component;
115
bool
explicit_registration;
116
} ecs_cpp_component_desc_t;
117
123
FLECS_API
124
ecs_entity_t
ecs_cpp_component_register(
125
ecs_world_t
*world,
126
const
ecs_cpp_component_desc_t *desc);
127
134
FLECS_API
135
void
ecs_cpp_enum_init(
136
ecs_world_t
*world,
137
ecs_entity_t
id
,
138
ecs_entity_t
underlying_type);
139
151
FLECS_API
152
ecs_entity_t
ecs_cpp_enum_constant_register(
153
ecs_world_t
*world,
154
ecs_entity_t
parent,
155
ecs_entity_t
id
,
156
const
char
*name,
157
void
*value,
158
ecs_entity_t
value_type,
159
size_t
value_size);
160
162
typedef
struct
ecs_cpp_get_mut_t {
163
ecs_world_t
*world;
164
ecs_stage_t
*stage;
165
void
*ptr;
166
bool
call_modified;
167
} ecs_cpp_get_mut_t;
168
178
FLECS_API
179
FLECS_ALWAYS_INLINE ecs_cpp_get_mut_t ecs_cpp_set(
180
ecs_world_t
*world,
181
ecs_entity_t
entity,
182
ecs_id_t
component,
183
const
void
*new_ptr,
184
size_t
size);
185
195
FLECS_API
196
FLECS_ALWAYS_INLINE ecs_cpp_get_mut_t ecs_cpp_assign(
197
ecs_world_t
*world,
198
ecs_entity_t
entity,
199
ecs_id_t
component,
200
const
void
*new_ptr,
201
size_t
size);
202
212
FLECS_API
213
FLECS_ALWAYS_INLINE
ecs_entity_t
ecs_cpp_new(
214
ecs_world_t
*world,
215
ecs_entity_t
parent,
216
const
char
*name,
217
const
char
*sep,
218
const
char
*root_sep);
219
220
#ifdef FLECS_META
227
FLECS_API
228
ecs_member_t
* ecs_cpp_last_member(
229
const
ecs_world_t
*world,
230
ecs_entity_t
type);
231
#endif
232
233
#ifdef __cplusplus
234
}
235
#endif
236
237
#endif
// FLECS_CPP_H
238
239
#endif
// FLECS_CPP
ecs_stage_t
struct ecs_stage_t ecs_stage_t
A stage enables modification while iterating and from multiple threads.
Definition
flecs.h:432
ecs_entity_t
ecs_id_t ecs_entity_t
An entity identifier.
Definition
flecs.h:385
ecs_world_t
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition
flecs.h:429
ecs_id_t
uint64_t ecs_id_t
IDs are the things that can be added to an entity.
Definition
flecs.h:378
ecs_member_t
Element type of members vector in EcsStruct.
Definition
meta.h:220
flecs::world::id
flecs::id id(E value) const
Convert an enum constant to an entity.
flecs::world::component
flecs::component< T > component(Args &&... args) const
Find or register a component.