Skip to content

Commit 2fcb2f6

Browse files
SanderMertens#1550 Support C++ enum reflection without meta addon
1 parent d8f09c7 commit 2fcb2f6

File tree

16 files changed

+178
-53
lines changed

16 files changed

+178
-53
lines changed

distr/flecs.c

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4356,6 +4356,14 @@ void flecs_bootstrap(
43564356
/* Run bootstrap functions for other parts of the code */
43574357
flecs_bootstrap_hierarchy(world);
43584358

4359+
/* Register constant tag */
4360+
ecs_component(world, {
4361+
.entity = ecs_entity(world, { .id = EcsConstant,
4362+
.name = "constant", .symbol = "EcsConstant",
4363+
.add = ecs_ids(ecs_pair(EcsOnInstantiate, EcsDontInherit))
4364+
})
4365+
});
4366+
43594367
ecs_set_scope(world, 0);
43604368
ecs_set_name_prefix(world, NULL);
43614369

@@ -18500,10 +18508,11 @@ const ecs_entity_t ecs_id(EcsVector) = FLECS_HI_COMPONENT_ID + 107;
1850018508
const ecs_entity_t ecs_id(EcsOpaque) = FLECS_HI_COMPONENT_ID + 108;
1850118509
const ecs_entity_t ecs_id(EcsUnit) = FLECS_HI_COMPONENT_ID + 109;
1850218510
const ecs_entity_t ecs_id(EcsUnitPrefix) = FLECS_HI_COMPONENT_ID + 110;
18503-
const ecs_entity_t EcsConstant = FLECS_HI_COMPONENT_ID + 111;
1850418511
const ecs_entity_t EcsQuantity = FLECS_HI_COMPONENT_ID + 112;
1850518512
#endif
1850618513

18514+
const ecs_entity_t EcsConstant = FLECS_HI_COMPONENT_ID + 111;
18515+
1850718516
/* Doc module components */
1850818517
#ifdef FLECS_DOC
1850918518
const ecs_entity_t ecs_id(EcsDocDescription) = FLECS_HI_COMPONENT_ID + 113;
@@ -22344,7 +22353,6 @@ ecs_entity_t ecs_cpp_enum_constant_register(
2234422353
ecs_entity_t value_type,
2234522354
size_t value_size)
2234622355
{
22347-
#ifdef FLECS_META
2234822356
ecs_suspend_readonly_state_t readonly_state;
2234922357
world = flecs_suspend_readonly(world, &readonly_state);
2235022358

@@ -22374,6 +22382,7 @@ ecs_entity_t ecs_cpp_enum_constant_register(
2237422382

2237522383
flecs_resume_readonly(world, &readonly_state);
2237622384

22385+
#ifdef FLECS_META
2237722386
if (ecs_should_log(0)) {
2237822387
ecs_value_t v = { .type = value_type, .ptr = value };
2237922388
char *str = NULL;
@@ -22384,19 +22393,9 @@ ecs_entity_t ecs_cpp_enum_constant_register(
2238422393
ecs_get_name(world, parent), name, str);
2238522394
ecs_os_free(str);
2238622395
}
22396+
#endif
2238722397

2238822398
return id;
22389-
#else
22390-
(void)world;
22391-
(void)parent;
22392-
(void)id;
22393-
(void)name;
22394-
(void)value;
22395-
(void)value_type;
22396-
(void)value_size;
22397-
ecs_err("enum reflection not supported without FLECS_META addon");
22398-
return 0;
22399-
#endif
2240022399
}
2240122400

2240222401
#ifdef FLECS_META
@@ -51983,13 +51982,6 @@ void FlecsMetaImport(
5198351982
.type.alignment = ECS_ALIGNOF(EcsPrimitive)
5198451983
});
5198551984

51986-
ecs_component(world, {
51987-
.entity = ecs_entity(world, { .id = EcsConstant,
51988-
.name = "constant", .symbol = "EcsConstant",
51989-
.add = ecs_ids(ecs_pair(EcsOnInstantiate, EcsDontInherit))
51990-
})
51991-
});
51992-
5199351985
ecs_component(world, {
5199451986
.entity = ecs_entity(world, { .id = ecs_id(EcsEnum),
5199551987
.name = "enum", .symbol = "EcsEnum",

distr/flecs.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5157,6 +5157,8 @@ FLECS_API extern const ecs_entity_t EcsOnStore; /**< OnStore pipeline phase.
51575157
FLECS_API extern const ecs_entity_t EcsPostFrame; /**< PostFrame pipeline phase. */
51585158
FLECS_API extern const ecs_entity_t EcsPhase; /**< Phase pipeline phase. */
51595159

5160+
FLECS_API extern const ecs_entity_t EcsConstant; /**< Tag added to enum/bitmask constants. */
5161+
51605162
/** Value used to quickly check if component is builtin. This is used to quickly
51615163
* filter out tables with builtin components (for example for ecs_delete()) */
51625164
#define EcsLastInternalComponentId (ecs_id(EcsPoly))
@@ -15634,7 +15636,6 @@ FLECS_API extern const ecs_entity_t ecs_id(EcsVector); /**< Id for comp
1563415636
FLECS_API extern const ecs_entity_t ecs_id(EcsOpaque); /**< Id for component that stores reflection data for an opaque type. */
1563515637
FLECS_API extern const ecs_entity_t ecs_id(EcsUnit); /**< Id for component that stores unit data. */
1563615638
FLECS_API extern const ecs_entity_t ecs_id(EcsUnitPrefix); /**< Id for component that stores unit prefix data. */
15637-
FLECS_API extern const ecs_entity_t EcsConstant; /**< Tag added to enum/bitmask constants. */
1563815639
FLECS_API extern const ecs_entity_t EcsQuantity; /**< Tag added to unit quantities. */
1563915640

1564015641
/* Primitive type component ids */
@@ -17332,6 +17333,7 @@ static const flecs::entity_t Monitor = EcsMonitor;
1733217333
static const flecs::entity_t System = EcsSystem;
1733317334
static const flecs::entity_t Pipeline = ecs_id(EcsPipeline);
1733417335
static const flecs::entity_t Phase = EcsPhase;
17336+
static const flecs::entity_t Constant = EcsConstant;
1733517337

1733617338
/* Builtin event tags */
1733717339
static const flecs::entity_t OnAdd = EcsOnAdd;
@@ -19230,7 +19232,6 @@ static const flecs::entity_t F32 = ecs_id(ecs_f32_t);
1923019232
static const flecs::entity_t F64 = ecs_id(ecs_f64_t);
1923119233
static const flecs::entity_t String = ecs_id(ecs_string_t);
1923219234
static const flecs::entity_t Entity = ecs_id(ecs_entity_t);
19233-
static const flecs::entity_t Constant = EcsConstant;
1923419235
static const flecs::entity_t Quantity = EcsQuantity;
1923519236

1923619237
namespace meta {

include/flecs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,6 +1859,8 @@ FLECS_API extern const ecs_entity_t EcsOnStore; /**< OnStore pipeline phase.
18591859
FLECS_API extern const ecs_entity_t EcsPostFrame; /**< PostFrame pipeline phase. */
18601860
FLECS_API extern const ecs_entity_t EcsPhase; /**< Phase pipeline phase. */
18611861

1862+
FLECS_API extern const ecs_entity_t EcsConstant; /**< Tag added to enum/bitmask constants. */
1863+
18621864
/** Value used to quickly check if component is builtin. This is used to quickly
18631865
* filter out tables with builtin components (for example for ecs_delete()) */
18641866
#define EcsLastInternalComponentId (ecs_id(EcsPoly))

include/flecs/addons/cpp/c_types.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ static const flecs::entity_t Monitor = EcsMonitor;
8484
static const flecs::entity_t System = EcsSystem;
8585
static const flecs::entity_t Pipeline = ecs_id(EcsPipeline);
8686
static const flecs::entity_t Phase = EcsPhase;
87+
static const flecs::entity_t Constant = EcsConstant;
8788

8889
/* Builtin event tags */
8990
static const flecs::entity_t OnAdd = EcsOnAdd;

include/flecs/addons/cpp/mixins/meta/decl.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ static const flecs::entity_t F32 = ecs_id(ecs_f32_t);
7272
static const flecs::entity_t F64 = ecs_id(ecs_f64_t);
7373
static const flecs::entity_t String = ecs_id(ecs_string_t);
7474
static const flecs::entity_t Entity = ecs_id(ecs_entity_t);
75-
static const flecs::entity_t Constant = EcsConstant;
7675
static const flecs::entity_t Quantity = EcsQuantity;
7776

7877
namespace meta {

include/flecs/addons/meta.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,6 @@ FLECS_API extern const ecs_entity_t ecs_id(EcsVector); /**< Id for comp
125125
FLECS_API extern const ecs_entity_t ecs_id(EcsOpaque); /**< Id for component that stores reflection data for an opaque type. */
126126
FLECS_API extern const ecs_entity_t ecs_id(EcsUnit); /**< Id for component that stores unit data. */
127127
FLECS_API extern const ecs_entity_t ecs_id(EcsUnitPrefix); /**< Id for component that stores unit prefix data. */
128-
FLECS_API extern const ecs_entity_t EcsConstant; /**< Tag added to enum/bitmask constants. */
129128
FLECS_API extern const ecs_entity_t EcsQuantity; /**< Tag added to unit quantities. */
130129

131130
/* Primitive type component ids */

src/addons/flecs_cpp.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,6 @@ ecs_entity_t ecs_cpp_enum_constant_register(
394394
ecs_entity_t value_type,
395395
size_t value_size)
396396
{
397-
#ifdef FLECS_META
398397
ecs_suspend_readonly_state_t readonly_state;
399398
world = flecs_suspend_readonly(world, &readonly_state);
400399

@@ -424,6 +423,7 @@ ecs_entity_t ecs_cpp_enum_constant_register(
424423

425424
flecs_resume_readonly(world, &readonly_state);
426425

426+
#ifdef FLECS_META
427427
if (ecs_should_log(0)) {
428428
ecs_value_t v = { .type = value_type, .ptr = value };
429429
char *str = NULL;
@@ -434,19 +434,9 @@ ecs_entity_t ecs_cpp_enum_constant_register(
434434
ecs_get_name(world, parent), name, str);
435435
ecs_os_free(str);
436436
}
437+
#endif
437438

438439
return id;
439-
#else
440-
(void)world;
441-
(void)parent;
442-
(void)id;
443-
(void)name;
444-
(void)value;
445-
(void)value_type;
446-
(void)value_size;
447-
ecs_err("enum reflection not supported without FLECS_META addon");
448-
return 0;
449-
#endif
450440
}
451441

452442
#ifdef FLECS_META

src/addons/meta/meta.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,13 +1257,6 @@ void FlecsMetaImport(
12571257
.type.alignment = ECS_ALIGNOF(EcsPrimitive)
12581258
});
12591259

1260-
ecs_component(world, {
1261-
.entity = ecs_entity(world, { .id = EcsConstant,
1262-
.name = "constant", .symbol = "EcsConstant",
1263-
.add = ecs_ids(ecs_pair(EcsOnInstantiate, EcsDontInherit))
1264-
})
1265-
});
1266-
12671260
ecs_component(world, {
12681261
.entity = ecs_entity(world, { .id = ecs_id(EcsEnum),
12691262
.name = "enum", .symbol = "EcsEnum",

src/bootstrap.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,6 +1104,14 @@ void flecs_bootstrap(
11041104
/* Run bootstrap functions for other parts of the code */
11051105
flecs_bootstrap_hierarchy(world);
11061106

1107+
/* Register constant tag */
1108+
ecs_component(world, {
1109+
.entity = ecs_entity(world, { .id = EcsConstant,
1110+
.name = "constant", .symbol = "EcsConstant",
1111+
.add = ecs_ids(ecs_pair(EcsOnInstantiate, EcsDontInherit))
1112+
})
1113+
});
1114+
11071115
ecs_set_scope(world, 0);
11081116
ecs_set_name_prefix(world, NULL);
11091117

src/world.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,11 @@ const ecs_entity_t ecs_id(EcsVector) = FLECS_HI_COMPONENT_ID + 107;
156156
const ecs_entity_t ecs_id(EcsOpaque) = FLECS_HI_COMPONENT_ID + 108;
157157
const ecs_entity_t ecs_id(EcsUnit) = FLECS_HI_COMPONENT_ID + 109;
158158
const ecs_entity_t ecs_id(EcsUnitPrefix) = FLECS_HI_COMPONENT_ID + 110;
159-
const ecs_entity_t EcsConstant = FLECS_HI_COMPONENT_ID + 111;
160159
const ecs_entity_t EcsQuantity = FLECS_HI_COMPONENT_ID + 112;
161160
#endif
162161

162+
const ecs_entity_t EcsConstant = FLECS_HI_COMPONENT_ID + 111;
163+
163164
/* Doc module components */
164165
#ifdef FLECS_DOC
165166
const ecs_entity_t ecs_id(EcsDocDescription) = FLECS_HI_COMPONENT_ID + 113;

0 commit comments

Comments
 (0)