Flecs: include/flecs/addons/flecs_cpp.h 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
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
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
43FLECS_API
44char* ecs_cpp_get_type_name(
45 char *type_name,
46 const char *func_name,
47 size_t len,
48 size_t front_len);
49
50FLECS_API
51char* ecs_cpp_get_symbol_name(
52 char *symbol_name,
53 const char *type_name,
54 size_t len);
55
56FLECS_API
57char* ecs_cpp_get_constant_name(
58 char *constant_name,
59 const char *func_name,
60 size_t len,
61 size_t back_len);
62
63FLECS_API
64const char* ecs_cpp_trim_module(
65 ecs_world_t *world,
66 const char *type_name);
67
68FLECS_API
69 ecs_entity_t ecs_cpp_component_register(
70 ecs_world_t *world,
71 ecs_entity_t id,
72 int32_t ids_index,
73 const char *name,
74 const char *cpp_name,
75 const char *cpp_symbol,
76 size_t size,
77 size_t alignment,
78 bool is_component,
79 bool explicit_registration,
80 bool *registered_out,
81 bool *existing_out);
82
83FLECS_API
84void ecs_cpp_enum_init(
85 ecs_world_t *world,
86 ecs_entity_t id,
87 ecs_entity_t underlying_type);
88
89FLECS_API
90 ecs_entity_t ecs_cpp_enum_constant_register(
91 ecs_world_t *world,
92 ecs_entity_t parent,
93 ecs_entity_t id,
94 const char *name,
95 void *value,
96 ecs_entity_t value_type,
97 size_t value_size);
98
99typedef struct ecs_cpp_get_mut_t {
100 void *ptr;
101 bool call_modified;
102} ecs_cpp_get_mut_t;
103
104FLECS_API
105FLECS_ALWAYS_INLINE ecs_cpp_get_mut_t ecs_cpp_set(
106 ecs_world_t *world,
107 ecs_entity_t entity,
108 ecs_id_t component,
109 const void *new_ptr,
110 size_t size);
111
112FLECS_API
113FLECS_ALWAYS_INLINE ecs_cpp_get_mut_t ecs_cpp_assign(
114 ecs_world_t *world,
115 ecs_entity_t entity,
116 ecs_id_t component,
117 const void *new_ptr,
118 size_t size);
119
120#ifdef FLECS_META
121FLECS_API
122const ecs_member_t* ecs_cpp_last_member(
123 const ecs_world_t *world,
124 ecs_entity_t type);
125#endif
126
127#ifdef __cplusplus
128}
129#endif
130
131#endif // FLECS_CPP_H
132
133#endif // FLECS_CPP
ecs_entity_t
ecs_id_t ecs_entity_t
An entity identifier.
Definition flecs.h:365
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:409
ecs_id_t
uint64_t ecs_id_t
Ids are the things that can be added to an entity.
Definition flecs.h:358
ecs_member_t
Element type of members vector in EcsStruct.
Definition meta.h:220