Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
flecs_cpp.h
Go to the documentation of this file.
1
10#ifdef FLECS_CPP
11
12#ifndef FLECS_CPP_H
13#define FLECS_CPP_H
14
15#ifdef __cplusplus
16extern "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
51FLECS_API
53 char *type_name,
54 const char *func_name,
55 size_t len,
56 size_t front_len);
57
65FLECS_API
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
82FLECS_API
84 char *constant_name,
85 const char *func_name,
86 size_t len,
87 size_t back_len);
88
95FLECS_API
97 ecs_world_t *world,
98 const char *type_name);
99
100typedef void (*ecs_cpp_type_action_t)(
101 ecs_world_t *world,
102 ecs_entity_t component);
103
105 ecs_entity_t id;
106#ifdef FLECS_MULTI_WORLD
107 int32_t ids_index;
108#else
109 ecs_entity_t *id_storage;
110#endif
111 const char *name;
112 const char *cpp_name;
113 const char *cpp_symbol;
114 size_t size;
115 size_t alignment;
116 ecs_cpp_type_action_t lifecycle_action;
117 ecs_cpp_type_action_t enum_action;
118 bool is_component;
119 bool explicit_registration;
121
127FLECS_API
129 ecs_world_t *world,
130 const ecs_cpp_component_desc_t *desc);
131
138FLECS_API
140 ecs_world_t *world,
141 ecs_entity_t id,
142 ecs_entity_t underlying_type);
143
155FLECS_API
157 ecs_world_t *world,
158 ecs_entity_t parent,
159 ecs_entity_t id,
160 const char *name,
161 void *value,
162 ecs_entity_t value_type,
163 size_t value_size);
164
172
182FLECS_API
183FLECS_ALWAYS_INLINE ecs_cpp_get_mut_t ecs_cpp_set(
184 ecs_world_t *world,
185 ecs_entity_t entity,
186 ecs_id_t component,
187 const void *new_ptr,
188 size_t size);
189
199FLECS_API
201 ecs_world_t *world,
202 ecs_entity_t entity,
203 ecs_id_t component,
204 const void *new_ptr,
205 size_t size);
206
216FLECS_API
217FLECS_ALWAYS_INLINE ecs_entity_t ecs_cpp_new(
218 ecs_world_t *world,
219 ecs_entity_t parent,
220 const char *name,
221 const char *sep,
222 const char *root_sep);
223
224#ifdef FLECS_META
231FLECS_API
233 const ecs_world_t *world,
234 ecs_entity_t type);
235#endif
236
237#ifdef __cplusplus
238}
239#endif
240
241#endif // FLECS_CPP_H
242
243#endif // FLECS_CPP
struct ecs_cpp_get_mut_t ecs_cpp_get_mut_t
Result type for C++ set/assign operations.
FLECS_API ecs_member_t * ecs_cpp_last_member(const ecs_world_t *world, ecs_entity_t type)
Get the last registered member for a type.
FLECS_API ecs_entity_t ecs_cpp_component_register(ecs_world_t *world, const ecs_cpp_component_desc_t *desc)
Register a C++ component.
FLECS_API FLECS_ALWAYS_INLINE ecs_cpp_get_mut_t ecs_cpp_set(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component, const void *new_ptr, size_t size)
Set a component value for a C++ entity.
FLECS_API char * ecs_cpp_get_type_name(char *type_name, const char *func_name, size_t len, size_t front_len)
Get type name from compiler-generated function name.
FLECS_API const char * ecs_cpp_trim_module(ecs_world_t *world, const char *type_name)
Trim module prefix from type name.
FLECS_API void ecs_cpp_enum_init(ecs_world_t *world, ecs_entity_t id, ecs_entity_t underlying_type)
Initialize a C++ enum type.
FLECS_API ecs_entity_t ecs_cpp_enum_constant_register(ecs_world_t *world, ecs_entity_t parent, ecs_entity_t id, const char *name, void *value, ecs_entity_t value_type, size_t value_size)
Register a C++ enum constant.
FLECS_API char * ecs_cpp_get_symbol_name(char *symbol_name, const char *type_name, size_t len)
Get symbol name from type name.
FLECS_API FLECS_ALWAYS_INLINE ecs_entity_t ecs_cpp_new(ecs_world_t *world, ecs_entity_t parent, const char *name, const char *sep, const char *root_sep)
Create a new entity from C++.
FLECS_API char * ecs_cpp_get_constant_name(char *constant_name, const char *func_name, size_t len, size_t back_len)
Get constant name from compiler-generated function name.
FLECS_API FLECS_ALWAYS_INLINE ecs_cpp_get_mut_t ecs_cpp_assign(ecs_world_t *world, ecs_entity_t entity, ecs_id_t component, const void *new_ptr, size_t size)
Assign a component value for a C++ entity.
struct ecs_stage_t ecs_stage_t
A stage enables modification while iterating and from multiple threads.
Definition flecs.h:440
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:393
struct ecs_world_t ecs_world_t
A world is the container for all ECS data and supporting features.
Definition flecs.h:437
uint64_t ecs_id_t
IDs are the things that can be added to an entity.
Definition flecs.h:386
Result type for C++ set/assign operations.
Definition flecs_cpp.h:166
bool call_modified
Whether modified should be called.
Definition flecs_cpp.h:170
ecs_stage_t * stage
The stage.
Definition flecs_cpp.h:168
ecs_world_t * world
The world.
Definition flecs_cpp.h:167
void * ptr
Pointer to the component data.
Definition flecs_cpp.h:169
Element type of members vector in EcsStruct.
Definition meta.h:224