Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions distr/flecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -6758,10 +6758,10 @@ ecs_entity_t ecs_component_init(
ptr->alignment = desc->type.alignment;
if (!new_component || ptr->size != desc->type.size) {
if (!ptr->size) {
ecs_trace("#[green]tag#[reset] %s created",
ecs_trace("#[green]tag#[reset] %s registered",
ecs_get_name(world, result));
} else {
ecs_trace("#[green]component#[reset] %s created",
ecs_trace("#[green]component#[reset] %s registered",
ecs_get_name(world, result));
}
}
Expand Down Expand Up @@ -18093,9 +18093,6 @@ static const char *flecs_addons_info[] = {
#ifdef FLECS_MODULE
"FLECS_MODULE",
#endif
#ifdef FLECS_SCRIPT
"FLECS_SCRIPT",
#endif
#ifdef FLECS_STATS
"FLECS_STATS",
#endif
Expand Down Expand Up @@ -18138,6 +18135,12 @@ static const char *flecs_addons_info[] = {
#ifdef FLECS_OS_API_IMPL
"FLECS_OS_API_IMPL",
#endif
#ifdef FLECS_PARSER
"FLECS_PARSER",
#endif
#ifdef FLECS_QUERY_DSL
"FLECS_QUERY_DSL",
#endif
#ifdef FLECS_SCRIPT
"FLECS_SCRIPT",
#endif
Expand Down
15 changes: 15 additions & 0 deletions distr/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,15 @@
*/
// #define FLECS_CPP_NO_AUTO_REGISTRATION

/** @def FLECS_CPP_NO_ENUM_REFLECTION
* When set, the C++ API will not attempt to discover and register enum
* constants for registered enum components. This will cause C++ APIs that
* accept enum constants to not work.
* Disabling this feature can significantly improve compile times and reduces
* the RAM footprint of an application.
*/
// #define FLECS_CPP_NO_ENUM_REFLECTION

/** @def FLECS_CUSTOM_BUILD
* This macro lets you customize which addons to build flecs with.
* Without any addons Flecs is just a minimal ECS storage, but addons add
Expand Down Expand Up @@ -17880,6 +17889,12 @@ struct string_view : string {
#define FLECS_ENUM_MAX(T) _::to_constant<T, 126>::value
#define FLECS_ENUM_MAX_COUNT (FLECS_ENUM_MAX(int) + 1)

// Flag to turn off enum reflection
#ifdef FLECS_CPP_NO_ENUM_REFLECTION
#define FLECS_CPP_ENUM_REFLECTION_SUPPORT 0
#endif

// Test if we're using a compiler that supports the required features
#ifndef FLECS_CPP_ENUM_REFLECTION_SUPPORT
#if !defined(__clang__) && defined(__GNUC__)
#if __GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 5)
Expand Down
9 changes: 9 additions & 0 deletions include/flecs.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,15 @@
*/
// #define FLECS_CPP_NO_AUTO_REGISTRATION

/** @def FLECS_CPP_NO_ENUM_REFLECTION
* When set, the C++ API will not attempt to discover and register enum
* constants for registered enum components. This will cause C++ APIs that
* accept enum constants to not work.
* Disabling this feature can significantly improve compile times and reduces
* the RAM footprint of an application.
*/
// #define FLECS_CPP_NO_ENUM_REFLECTION

/** @def FLECS_CUSTOM_BUILD
* This macro lets you customize which addons to build flecs with.
* Without any addons Flecs is just a minimal ECS storage, but addons add
Expand Down
6 changes: 6 additions & 0 deletions include/flecs/addons/cpp/utils/enum.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
#define FLECS_ENUM_MAX(T) _::to_constant<T, 126>::value
#define FLECS_ENUM_MAX_COUNT (FLECS_ENUM_MAX(int) + 1)

// Flag to turn off enum reflection
#ifdef FLECS_CPP_NO_ENUM_REFLECTION
#define FLECS_CPP_ENUM_REFLECTION_SUPPORT 0
#endif

// Test if we're using a compiler that supports the required features
#ifndef FLECS_CPP_ENUM_REFLECTION_SUPPORT
#if !defined(__clang__) && defined(__GNUC__)
#if __GNUC__ > 7 || (__GNUC__ == 7 && __GNUC_MINOR__ >= 5)
Expand Down
4 changes: 2 additions & 2 deletions src/entity.c
Original file line number Diff line number Diff line change
Expand Up @@ -2272,10 +2272,10 @@ ecs_entity_t ecs_component_init(
ptr->alignment = desc->type.alignment;
if (!new_component || ptr->size != desc->type.size) {
if (!ptr->size) {
ecs_trace("#[green]tag#[reset] %s created",
ecs_trace("#[green]tag#[reset] %s registered",
ecs_get_name(world, result));
} else {
ecs_trace("#[green]component#[reset] %s created",
ecs_trace("#[green]component#[reset] %s registered",
ecs_get_name(world, result));
}
}
Expand Down
9 changes: 6 additions & 3 deletions src/world.c
Original file line number Diff line number Diff line change
Expand Up @@ -812,9 +812,6 @@ static const char *flecs_addons_info[] = {
#ifdef FLECS_MODULE
"FLECS_MODULE",
#endif
#ifdef FLECS_SCRIPT
"FLECS_SCRIPT",
#endif
#ifdef FLECS_STATS
"FLECS_STATS",
#endif
Expand Down Expand Up @@ -857,6 +854,12 @@ static const char *flecs_addons_info[] = {
#ifdef FLECS_OS_API_IMPL
"FLECS_OS_API_IMPL",
#endif
#ifdef FLECS_PARSER
"FLECS_PARSER",
#endif
#ifdef FLECS_QUERY_DSL
"FLECS_QUERY_DSL",
#endif
#ifdef FLECS_SCRIPT
"FLECS_SCRIPT",
#endif
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef NO_ENUM_REFLECTION_H
#define NO_ENUM_REFLECTION_H

/* This generated file contains includes for project dependencies */
#include "no_enum_reflection/bake_config.h"

#ifdef __cplusplus
extern "C" {
#endif

#ifdef __cplusplus
}
#endif

#endif

Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
)
(.)
.|.
| |
_.--| |--._
.-'; ;`-'& ; `&.
\ & ; & &_/
|"""---...---"""|
\ | | | | | | | /
`---.|.|.|.---'

* This file is generated by bake.lang.c for your convenience. Headers of
* dependencies will automatically show up in this file. Include bake_config.h
* in your main project file. Do not edit! */

#ifndef NO_ENUM_REFLECTION_BAKE_CONFIG_H
#define NO_ENUM_REFLECTION_BAKE_CONFIG_H

/* Headers of public dependencies */
#include <flecs.h>

#endif

14 changes: 14 additions & 0 deletions test/custom_builds/cpp/no_enum_reflection/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"id": "no_enum_reflection",
"type": "application",
"value": {
"use": [
"flecs"
],
"language": "c++",
"public": false
},
"lang.cpp": {
"defines": ["FLECS_CPP_NO_ENUM_REFLECTION"]
}
}
29 changes: 29 additions & 0 deletions test/custom_builds/cpp/no_enum_reflection/src/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include <no_enum_reflection.h>
#include <iostream>

enum Color {
Red, Green, Blue
};

int main(int argc, char *argv[]) {
flecs::world world(argc, argv);

auto c = world.component<Color>();

if (c.lookup("Red") != 0) {
printf("enum constant should not be defined\n");
return -1;
}

if (c.lookup("Green") != 0) {
printf("enum constant should not be defined\n");
return -1;
}

if (c.lookup("Blue") != 0) {
printf("enum constant should not be defined\n");
return -1;
}

return 0;
}