From 9fe2bf1b804780a85f84ea58bdd9dd4aec65dbfe Mon Sep 17 00:00:00 2001 From: Gaspard-- Date: Tue, 22 Oct 2024 14:17:23 +0200 Subject: [PATCH] Add C++20 module build target Usage in client cmake: ```cmake set(FLECS_M0DULE ON CACHE BOOL "Build flecs module" FORCE) add_subdirectory(path/to/flecs) target_compile_features(flecs-module PUBLIC cxx_std_23) target_link_libraries( someProjectName PRIVATE flecs-module ) ``` In the code, it is then possible to use `import flecs;` to import all the flecs symbols. The current version includes everything in the `flecs` namespace, but avoids including anything in the `_` namespace. Maintainance: - namespaces that contain symbols to exported must be tagged with FLECS_API_NAMESPACE - namespaces that should be excluded should be seperate in order to avoid exporting symbols - static globals must be tagged with `FLECS_STATIC_IN_HEADER`, which becomes `static` in headers, but not in the module - some rare symbols outside namesapces are necessary for compilation, such as operator new / delete, and must be tagged FLECS_API_DEPENDENCY --- CMakeLists.txt | 5 + distr/flecs.h | 622 +++++++++++------- include/flecs/addons/cpp/c_types.hpp | 144 ++-- include/flecs/addons/cpp/component.hpp | 6 +- include/flecs/addons/cpp/delegate.hpp | 6 + include/flecs/addons/cpp/entity.hpp | 2 +- include/flecs/addons/cpp/entity_view.hpp | 2 +- include/flecs/addons/cpp/field.hpp | 2 +- include/flecs/addons/cpp/flecs.hpp | 21 +- include/flecs/addons/cpp/impl/field.hpp | 2 +- include/flecs/addons/cpp/impl/iter.hpp | 2 +- include/flecs/addons/cpp/impl/world.hpp | 2 +- include/flecs/addons/cpp/iter.hpp | 2 +- include/flecs/addons/cpp/lifecycle_traits.hpp | 9 +- include/flecs/addons/cpp/log.hpp | 2 +- .../addons/cpp/mixins/alerts/builder.hpp | 10 +- .../addons/cpp/mixins/alerts/builder_i.hpp | 2 +- .../flecs/addons/cpp/mixins/alerts/decl.hpp | 5 +- .../flecs/addons/cpp/mixins/alerts/impl.hpp | 2 +- .../flecs/addons/cpp/mixins/app/builder.hpp | 3 +- .../addons/cpp/mixins/component/impl.hpp | 2 +- include/flecs/addons/cpp/mixins/doc/decl.hpp | 22 +- include/flecs/addons/cpp/mixins/doc/impl.hpp | 7 +- .../addons/cpp/mixins/entity/builder.hpp | 2 +- .../flecs/addons/cpp/mixins/entity/impl.hpp | 2 +- include/flecs/addons/cpp/mixins/enum/impl.hpp | 2 +- .../flecs/addons/cpp/mixins/event/builder.hpp | 2 +- .../flecs/addons/cpp/mixins/event/decl.hpp | 4 +- .../flecs/addons/cpp/mixins/event/impl.hpp | 5 +- include/flecs/addons/cpp/mixins/id/decl.hpp | 3 +- include/flecs/addons/cpp/mixins/id/impl.hpp | 2 +- include/flecs/addons/cpp/mixins/json/decl.hpp | 2 +- .../flecs/addons/cpp/mixins/meta/cursor.hpp | 2 +- include/flecs/addons/cpp/mixins/meta/decl.hpp | 96 +-- include/flecs/addons/cpp/mixins/meta/impl.hpp | 3 + .../flecs/addons/cpp/mixins/meta/opaque.hpp | 4 +- .../addons/cpp/mixins/metrics/builder.hpp | 2 +- .../flecs/addons/cpp/mixins/metrics/decl.hpp | 3 +- .../flecs/addons/cpp/mixins/metrics/impl.hpp | 2 +- .../flecs/addons/cpp/mixins/module/impl.hpp | 6 +- .../addons/cpp/mixins/observer/builder.hpp | 12 +- .../addons/cpp/mixins/observer/builder_i.hpp | 2 +- .../flecs/addons/cpp/mixins/observer/decl.hpp | 3 +- .../flecs/addons/cpp/mixins/observer/impl.hpp | 2 +- .../addons/cpp/mixins/pipeline/builder.hpp | 10 +- .../addons/cpp/mixins/pipeline/builder_i.hpp | 2 +- .../flecs/addons/cpp/mixins/pipeline/decl.hpp | 24 +- .../flecs/addons/cpp/mixins/pipeline/impl.hpp | 2 +- .../flecs/addons/cpp/mixins/query/builder.hpp | 10 +- .../addons/cpp/mixins/query/builder_i.hpp | 2 +- .../flecs/addons/cpp/mixins/query/decl.hpp | 4 +- .../flecs/addons/cpp/mixins/query/impl.hpp | 9 +- include/flecs/addons/cpp/mixins/rest/decl.hpp | 13 +- .../addons/cpp/mixins/script/builder.hpp | 3 +- .../flecs/addons/cpp/mixins/script/decl.hpp | 2 +- .../flecs/addons/cpp/mixins/script/impl.hpp | 2 +- .../flecs/addons/cpp/mixins/stats/decl.hpp | 6 +- .../flecs/addons/cpp/mixins/stats/impl.hpp | 2 +- .../addons/cpp/mixins/system/builder.hpp | 10 +- .../addons/cpp/mixins/system/builder_i.hpp | 2 +- .../flecs/addons/cpp/mixins/system/decl.hpp | 7 +- .../flecs/addons/cpp/mixins/system/impl.hpp | 5 +- .../addons/cpp/mixins/term/builder_i.hpp | 2 +- include/flecs/addons/cpp/mixins/term/decl.hpp | 2 +- include/flecs/addons/cpp/mixins/term/impl.hpp | 2 +- .../flecs/addons/cpp/mixins/timer/decl.hpp | 4 +- .../flecs/addons/cpp/mixins/timer/impl.hpp | 9 +- .../flecs/addons/cpp/mixins/units/decl.hpp | 4 +- .../flecs/addons/cpp/mixins/units/impl.hpp | 2 +- include/flecs/addons/cpp/pair.hpp | 7 +- include/flecs/addons/cpp/ref.hpp | 2 +- include/flecs/addons/cpp/table.hpp | 2 +- include/flecs/addons/cpp/type.hpp | 2 +- include/flecs/addons/cpp/utils/array.hpp | 2 +- include/flecs/addons/cpp/utils/enum.hpp | 23 +- .../addons/cpp/utils/function_traits.hpp | 4 +- include/flecs/addons/cpp/utils/iterable.hpp | 2 +- include/flecs/addons/cpp/utils/string.hpp | 2 +- .../flecs/addons/cpp/utils/stringstream.hpp | 2 +- include/flecs/addons/cpp/utils/utils.hpp | 11 +- include/flecs/addons/cpp/world.hpp | 2 +- include/flecs/private/addons.h | 5 + module/CMakeLists.txt | 10 + module/flecs-module.cpp | 33 + 84 files changed, 810 insertions(+), 482 deletions(-) create mode 100644 module/CMakeLists.txt create mode 100644 module/flecs-module.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b0a27409b..7a8b358242 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ option(FLECS_STATIC "Build static flecs lib" ON) option(FLECS_SHARED "Build shared flecs lib" ON) option(FLECS_PIC "Compile static flecs lib with position independent code (PIC)" ON) option(FLECS_TESTS "Build flecs tests" OFF) +option(FLECS_M0DULE "Build flecs C++20 module" OFF) include(cmake/target_default_compile_warnings.cmake) include(cmake/target_default_compile_options.cmake) @@ -75,6 +76,10 @@ if(FLECS_TESTS) add_subdirectory(test) endif() +if(FLECS_M0DULE) + add_subdirectory(module) +endif() + message(STATUS "Targets: ${FLECS_TARGETS}") # define the install steps diff --git a/distr/flecs.h b/distr/flecs.h index 5851010739..d51f993a5f 100644 --- a/distr/flecs.h +++ b/distr/flecs.h @@ -16501,6 +16501,7 @@ ecs_entity_t ecs_module_init( #ifdef FLECS_NO_CPP #error "FLECS_NO_CPP failed: CPP is required by other addons" #endif + /** * @file addons/flecs_cpp.h * @brief C++ utility functions @@ -16637,6 +16638,8 @@ const ecs_member_t* ecs_cpp_last_member( #endif // FLECS_CPP +#ifndef FLECS_CPP20_MODULE_HEADER + #ifdef __cplusplus /** * @file addons/cpp/flecs.hpp @@ -16646,14 +16649,28 @@ const ecs_member_t* ecs_cpp_last_member( #pragma once // STL includes +#ifndef FLECS_NO_STD_INCLUDE #include +#endif + +#ifndef FLECS_API_NAMESPACE +#define FLECS_API_NAMESPACE +#endif + +#ifndef FLECS_API_DEPENDENCY +#define FLECS_API_DEPENDENCY +#endif + +#ifndef FLECS_STATIC_IN_HEADER +#define FLECS_STATIC_IN_HEADER static +#endif /** * @defgroup cpp C++ API * @{ */ -namespace flecs +FLECS_API_NAMESPACE namespace flecs { struct world; @@ -16666,12 +16683,17 @@ struct table; struct table_range; struct untyped_component; + template struct component; + template struct ref; +} // namespace flecs + +namespace flecs { namespace _ { template @@ -16691,7 +16713,7 @@ struct each_delegate; #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_globals API Types & Globals @@ -16744,9 +16766,9 @@ enum query_cache_kind_t { }; /** Id bit flags */ -static const flecs::entity_t PAIR = ECS_PAIR; -static const flecs::entity_t AUTO_OVERRIDE = ECS_AUTO_OVERRIDE; -static const flecs::entity_t TOGGLE = ECS_TOGGLE; +FLECS_STATIC_IN_HEADER const flecs::entity_t PAIR = ECS_PAIR; +FLECS_STATIC_IN_HEADER const flecs::entity_t AUTO_OVERRIDE = ECS_AUTO_OVERRIDE; +FLECS_STATIC_IN_HEADER const flecs::entity_t TOGGLE = ECS_TOGGLE; //////////////////////////////////////////////////////////////////////////////// //// Builtin components and tags @@ -16759,96 +16781,96 @@ using Poly = EcsPoly; using DefaultChildComponent = EcsDefaultChildComponent; /* Builtin tags */ -static const flecs::entity_t Query = EcsQuery; -static const flecs::entity_t Observer = EcsObserver; -static const flecs::entity_t Private = EcsPrivate; -static const flecs::entity_t Module = EcsModule; -static const flecs::entity_t Prefab = EcsPrefab; -static const flecs::entity_t Disabled = EcsDisabled; -static const flecs::entity_t Empty = EcsEmpty; -static const flecs::entity_t Monitor = EcsMonitor; -static const flecs::entity_t System = EcsSystem; -static const flecs::entity_t Pipeline = ecs_id(EcsPipeline); -static const flecs::entity_t Phase = EcsPhase; +FLECS_STATIC_IN_HEADER const flecs::entity_t Query = EcsQuery; +FLECS_STATIC_IN_HEADER const flecs::entity_t Observer = EcsObserver; +FLECS_STATIC_IN_HEADER const flecs::entity_t Private = EcsPrivate; +FLECS_STATIC_IN_HEADER const flecs::entity_t Module = EcsModule; +FLECS_STATIC_IN_HEADER const flecs::entity_t Prefab = EcsPrefab; +FLECS_STATIC_IN_HEADER const flecs::entity_t Disabled = EcsDisabled; +FLECS_STATIC_IN_HEADER const flecs::entity_t Empty = EcsEmpty; +FLECS_STATIC_IN_HEADER const flecs::entity_t Monitor = EcsMonitor; +FLECS_STATIC_IN_HEADER const flecs::entity_t System = EcsSystem; +FLECS_STATIC_IN_HEADER const flecs::entity_t Pipeline = ecs_id(EcsPipeline); +FLECS_STATIC_IN_HEADER const flecs::entity_t Phase = EcsPhase; /* Builtin event tags */ -static const flecs::entity_t OnAdd = EcsOnAdd; -static const flecs::entity_t OnRemove = EcsOnRemove; -static const flecs::entity_t OnSet = EcsOnSet; -static const flecs::entity_t OnTableCreate = EcsOnTableCreate; -static const flecs::entity_t OnTableDelete = EcsOnTableDelete; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnAdd = EcsOnAdd; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnRemove = EcsOnRemove; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnSet = EcsOnSet; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnTableCreate = EcsOnTableCreate; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnTableDelete = EcsOnTableDelete; /* Builtin term flags */ -static const uint64_t Self = EcsSelf; -static const uint64_t Up = EcsUp; -static const uint64_t Trav = EcsTrav; -static const uint64_t Cascade = EcsCascade; -static const uint64_t Desc = EcsDesc; -static const uint64_t IsVariable = EcsIsVariable; -static const uint64_t IsEntity = EcsIsEntity; -static const uint64_t IsName = EcsIsName; -static const uint64_t TraverseFlags = EcsTraverseFlags; -static const uint64_t TermRefFlags = EcsTermRefFlags; +FLECS_STATIC_IN_HEADER const uint64_t Self = EcsSelf; +FLECS_STATIC_IN_HEADER const uint64_t Up = EcsUp; +FLECS_STATIC_IN_HEADER const uint64_t Trav = EcsTrav; +FLECS_STATIC_IN_HEADER const uint64_t Cascade = EcsCascade; +FLECS_STATIC_IN_HEADER const uint64_t Desc = EcsDesc; +FLECS_STATIC_IN_HEADER const uint64_t IsVariable = EcsIsVariable; +FLECS_STATIC_IN_HEADER const uint64_t IsEntity = EcsIsEntity; +FLECS_STATIC_IN_HEADER const uint64_t IsName = EcsIsName; +FLECS_STATIC_IN_HEADER const uint64_t TraverseFlags = EcsTraverseFlags; +FLECS_STATIC_IN_HEADER const uint64_t TermRefFlags = EcsTermRefFlags; /* Builtin entity ids */ -static const flecs::entity_t Flecs = EcsFlecs; -static const flecs::entity_t FlecsCore = EcsFlecsCore; -static const flecs::entity_t World = EcsWorld; +FLECS_STATIC_IN_HEADER const flecs::entity_t Flecs = EcsFlecs; +FLECS_STATIC_IN_HEADER const flecs::entity_t FlecsCore = EcsFlecsCore; +FLECS_STATIC_IN_HEADER const flecs::entity_t World = EcsWorld; /* Component traits */ -static const flecs::entity_t Wildcard = EcsWildcard; -static const flecs::entity_t Any = EcsAny; -static const flecs::entity_t This = EcsThis; -static const flecs::entity_t Transitive = EcsTransitive; -static const flecs::entity_t Reflexive = EcsReflexive; -static const flecs::entity_t Final = EcsFinal; -static const flecs::entity_t PairIsTag = EcsPairIsTag; -static const flecs::entity_t Exclusive = EcsExclusive; -static const flecs::entity_t Acyclic = EcsAcyclic; -static const flecs::entity_t Traversable = EcsTraversable; -static const flecs::entity_t Symmetric = EcsSymmetric; -static const flecs::entity_t With = EcsWith; -static const flecs::entity_t OneOf = EcsOneOf; -static const flecs::entity_t Trait = EcsTrait; -static const flecs::entity_t Relationship = EcsRelationship; -static const flecs::entity_t Target = EcsTarget; -static const flecs::entity_t CanToggle = EcsCanToggle; +FLECS_STATIC_IN_HEADER const flecs::entity_t Wildcard = EcsWildcard; +FLECS_STATIC_IN_HEADER const flecs::entity_t Any = EcsAny; +FLECS_STATIC_IN_HEADER const flecs::entity_t This = EcsThis; +FLECS_STATIC_IN_HEADER const flecs::entity_t Transitive = EcsTransitive; +FLECS_STATIC_IN_HEADER const flecs::entity_t Reflexive = EcsReflexive; +FLECS_STATIC_IN_HEADER const flecs::entity_t Final = EcsFinal; +FLECS_STATIC_IN_HEADER const flecs::entity_t PairIsTag = EcsPairIsTag; +FLECS_STATIC_IN_HEADER const flecs::entity_t Exclusive = EcsExclusive; +FLECS_STATIC_IN_HEADER const flecs::entity_t Acyclic = EcsAcyclic; +FLECS_STATIC_IN_HEADER const flecs::entity_t Traversable = EcsTraversable; +FLECS_STATIC_IN_HEADER const flecs::entity_t Symmetric = EcsSymmetric; +FLECS_STATIC_IN_HEADER const flecs::entity_t With = EcsWith; +FLECS_STATIC_IN_HEADER const flecs::entity_t OneOf = EcsOneOf; +FLECS_STATIC_IN_HEADER const flecs::entity_t Trait = EcsTrait; +FLECS_STATIC_IN_HEADER const flecs::entity_t Relationship = EcsRelationship; +FLECS_STATIC_IN_HEADER const flecs::entity_t Target = EcsTarget; +FLECS_STATIC_IN_HEADER const flecs::entity_t CanToggle = EcsCanToggle; /* OnInstantiate trait */ -static const flecs::entity_t OnInstantiate = EcsOnInstantiate; -static const flecs::entity_t Override = EcsOverride; -static const flecs::entity_t Inherit = EcsInherit; -static const flecs::entity_t DontInherit = EcsDontInherit; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnInstantiate = EcsOnInstantiate; +FLECS_STATIC_IN_HEADER const flecs::entity_t Override = EcsOverride; +FLECS_STATIC_IN_HEADER const flecs::entity_t Inherit = EcsInherit; +FLECS_STATIC_IN_HEADER const flecs::entity_t DontInherit = EcsDontInherit; /* OnDelete/OnDeleteTarget traits */ -static const flecs::entity_t OnDelete = EcsOnDelete; -static const flecs::entity_t OnDeleteTarget = EcsOnDeleteTarget; -static const flecs::entity_t Remove = EcsRemove; -static const flecs::entity_t Delete = EcsDelete; -static const flecs::entity_t Panic = EcsPanic; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnDelete = EcsOnDelete; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnDeleteTarget = EcsOnDeleteTarget; +FLECS_STATIC_IN_HEADER const flecs::entity_t Remove = EcsRemove; +FLECS_STATIC_IN_HEADER const flecs::entity_t Delete = EcsDelete; +FLECS_STATIC_IN_HEADER const flecs::entity_t Panic = EcsPanic; /* Builtin relationships */ -static const flecs::entity_t IsA = EcsIsA; -static const flecs::entity_t ChildOf = EcsChildOf; -static const flecs::entity_t DependsOn = EcsDependsOn; -static const flecs::entity_t SlotOf = EcsSlotOf; +FLECS_STATIC_IN_HEADER const flecs::entity_t IsA = EcsIsA; +FLECS_STATIC_IN_HEADER const flecs::entity_t ChildOf = EcsChildOf; +FLECS_STATIC_IN_HEADER const flecs::entity_t DependsOn = EcsDependsOn; +FLECS_STATIC_IN_HEADER const flecs::entity_t SlotOf = EcsSlotOf; /* Builtin identifiers */ -static const flecs::entity_t Name = EcsName; -static const flecs::entity_t Symbol = EcsSymbol; +FLECS_STATIC_IN_HEADER const flecs::entity_t Name = EcsName; +FLECS_STATIC_IN_HEADER const flecs::entity_t Symbol = EcsSymbol; /* Storage */ -static const flecs::entity_t Sparse = EcsSparse; -static const flecs::entity_t Union = EcsUnion; +FLECS_STATIC_IN_HEADER const flecs::entity_t Sparse = EcsSparse; +FLECS_STATIC_IN_HEADER const flecs::entity_t Union = EcsUnion; /* Builtin predicates for comparing entity ids in queries. */ -static const flecs::entity_t PredEq = EcsPredEq; -static const flecs::entity_t PredMatch = EcsPredMatch; -static const flecs::entity_t PredLookup = EcsPredLookup; +FLECS_STATIC_IN_HEADER const flecs::entity_t PredEq = EcsPredEq; +FLECS_STATIC_IN_HEADER const flecs::entity_t PredMatch = EcsPredMatch; +FLECS_STATIC_IN_HEADER const flecs::entity_t PredLookup = EcsPredLookup; /* Builtin marker entities for query scopes */ -static const flecs::entity_t ScopeOpen = EcsScopeOpen; -static const flecs::entity_t ScopeClose = EcsScopeClose; +FLECS_STATIC_IN_HEADER const flecs::entity_t ScopeOpen = EcsScopeOpen; +FLECS_STATIC_IN_HEADER const flecs::entity_t ScopeClose = EcsScopeClose; /** @} */ @@ -16920,10 +16942,10 @@ template inline void free_obj(Ty* _ptr) { #define flecs_static_assert(cond, str) static_assert(cond, str) #endif -inline void* operator new(size_t, flecs::_::placement_new_tag_t, void* _ptr) noexcept { return _ptr; } -inline void operator delete(void*, flecs::_::placement_new_tag_t, void*) noexcept { } +FLECS_API_DEPENDENCY inline void* operator new(size_t, flecs::_::placement_new_tag_t, void* _ptr) noexcept { return _ptr; } +FLECS_API_DEPENDENCY inline void operator delete(void*, flecs::_::placement_new_tag_t, void*) noexcept { } -namespace flecs +FLECS_API_NAMESPACE namespace flecs { // C++11/C++14 convenience template replacements @@ -16990,6 +17012,9 @@ using if_t = enable_if_t; template using if_not_t = enable_if_t; +} // namespace flecs + +namespace flecs { namespace _ { @@ -17004,7 +17029,9 @@ struct always_false { } // namespace flecs +#ifndef FLECS_NO_STD_INCLUDE #include +#endif /** * @file addons/cpp/utils/array.hpp * @brief Array class. @@ -17013,7 +17040,7 @@ struct always_false { * template code where template expansion would lead to an array with size 0. */ -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template struct array_iterator @@ -17123,7 +17150,7 @@ struct array> final { * @brief String utility that doesn't implicitly allocate memory. */ -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { struct string_view; @@ -17278,8 +17305,10 @@ struct string_view : string { * and their names. This is used to automatically register enum constants. */ +#ifndef FLECS_NO_STD_INCLUDE #include #include +#endif #define FLECS_ENUM_MAX(T) _::to_constant::value #define FLECS_ENUM_MAX_COUNT (FLECS_ENUM_MAX(int) + 1) @@ -17316,14 +17345,17 @@ struct to_constant { template Value> constexpr E to_constant::value; -} +} // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs { /** Convenience type with enum reflection data */ template struct enum_data; template -static enum_data enum_type(flecs::world_t *world); +FLECS_STATIC_IN_HEADER enum_data enum_type(flecs::world_t *world); template struct enum_last { @@ -17332,12 +17364,15 @@ struct enum_last { /* Utility macro to override enum_last trait */ #define FLECS_ENUM_LAST(T, Last)\ - namespace flecs {\ + FLECS_API_NAMESPACE namespace flecs {\ template<>\ struct enum_last {\ static constexpr T value = Last;\ };\ } +} // namespace flecs + +namespace flecs { namespace _ { @@ -17653,15 +17688,20 @@ struct enum_type { template enum_data_impl enum_type::data; +FLECS_API_DEPENDENCY template ::value > = 0> -inline static void init_enum(flecs::world_t *world, flecs::entity_t id) { +inline FLECS_STATIC_IN_HEADER void init_enum(flecs::world_t *world, flecs::entity_t id) { _::enum_type::get().init(world, id); } +FLECS_API_DEPENDENCY template ::value > = 0> -inline static void init_enum(flecs::world_t*, flecs::entity_t) { } +inline FLECS_STATIC_IN_HEADER void init_enum(flecs::world_t*, flecs::entity_t) { } } // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs { /** Enumeration type data wrapper with world pointer */ template @@ -17767,7 +17807,7 @@ enum_data enum_type(flecs::world_t *world) { * @brief Wrapper around ecs_strbuf_t that provides a simple stringstream like API. */ -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { struct stringstream { explicit stringstream() @@ -17904,8 +17944,10 @@ template struct function_traits : function_traits_no_cv< decay_t > {}; -} // _ +} // namespace _ +} // namespace flecs +FLECS_API_NAMESPACE namespace flecs { template struct is_callable { @@ -17969,7 +18011,7 @@ using second_arg_t = typename second_arg::type; #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { struct id; struct entity; @@ -17988,6 +18030,7 @@ struct entity; * - pair ids * - entities with id flags set (like flecs::AUTO_OVERRIDE, flecs::TOGGLE) */ + struct id { id() : world_(nullptr) @@ -18122,7 +18165,7 @@ struct id { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @ingroup cpp_core_queries @@ -18144,7 +18187,7 @@ struct term_builder; #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_core_queries Queries @@ -18155,9 +18198,11 @@ namespace flecs { struct query_base; + template struct query; + template struct query_builder; @@ -18181,7 +18226,7 @@ struct query_builder; #define ECS_EVENT_DESC_ID_COUNT_MAX (8) -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @ingroup cpp_addons_event @@ -18359,8 +18404,8 @@ struct event_from_func::value == 2>> { template using event_from_func_t = typename event_from_func::type; -} -} +} // namespace _ +} // namespace flecs /** * @file addons/cpp/mixins/observer/decl.hpp @@ -18369,7 +18414,7 @@ using event_from_func_t = typename event_from_func::type; #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_observers Observers @@ -18381,6 +18426,7 @@ namespace flecs { struct observer; + template struct observer_builder; @@ -18396,7 +18442,7 @@ struct observer_builder; #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_systems Systems @@ -18406,13 +18452,18 @@ namespace flecs { * @{ */ + using TickSource = EcsTickSource; struct system; + template struct system_builder; +} // namespace flecs + +namespace flecs { namespace _ { void system_init(flecs::world& world); @@ -18431,7 +18482,7 @@ void system_init(flecs::world& world); #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_pipelines Pipelines @@ -18448,17 +18499,17 @@ template struct pipeline_builder; /* Builtin pipeline tags */ -static const flecs::entity_t OnStart = EcsOnStart; -static const flecs::entity_t PreFrame = EcsPreFrame; -static const flecs::entity_t OnLoad = EcsOnLoad; -static const flecs::entity_t PostLoad = EcsPostLoad; -static const flecs::entity_t PreUpdate = EcsPreUpdate; -static const flecs::entity_t OnUpdate = EcsOnUpdate; -static const flecs::entity_t OnValidate = EcsOnValidate; -static const flecs::entity_t PostUpdate = EcsPostUpdate; -static const flecs::entity_t PreStore = EcsPreStore; -static const flecs::entity_t OnStore = EcsOnStore; -static const flecs::entity_t PostFrame = EcsPostFrame; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnStart = EcsOnStart; +FLECS_STATIC_IN_HEADER const flecs::entity_t PreFrame = EcsPreFrame; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnLoad = EcsOnLoad; +FLECS_STATIC_IN_HEADER const flecs::entity_t PostLoad = EcsPostLoad; +FLECS_STATIC_IN_HEADER const flecs::entity_t PreUpdate = EcsPreUpdate; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnUpdate = EcsOnUpdate; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnValidate = EcsOnValidate; +FLECS_STATIC_IN_HEADER const flecs::entity_t PostUpdate = EcsPostUpdate; +FLECS_STATIC_IN_HEADER const flecs::entity_t PreStore = EcsPreStore; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnStore = EcsOnStore; +FLECS_STATIC_IN_HEADER const flecs::entity_t PostFrame = EcsPostFrame; /** @} */ @@ -18473,7 +18524,7 @@ static const flecs::entity_t PostFrame = EcsPostFrame; #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_timer Timer @@ -18489,7 +18540,9 @@ using RateFilter = EcsRateFilter; struct timer; /** @} */ +} // namespace flecs +namespace flecs { namespace _ { void timer_init(flecs::world& world); @@ -18506,7 +18559,7 @@ void timer_init(flecs::world& world); #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { namespace doc { /** @@ -18521,19 +18574,25 @@ namespace doc { using Description = EcsDocDescription; /** flecs.doc.Uuid component */ -static const flecs::entity_t Uuid = EcsDocUuid; +FLECS_STATIC_IN_HEADER const flecs::entity_t Uuid = EcsDocUuid; /** flecs.doc.Brief component */ -static const flecs::entity_t Brief = EcsDocBrief; +FLECS_STATIC_IN_HEADER const flecs::entity_t Brief = EcsDocBrief; /** flecs.doc.Detail component */ -static const flecs::entity_t Detail = EcsDocDetail; +FLECS_STATIC_IN_HEADER const flecs::entity_t Detail = EcsDocDetail; /** flecs.doc.Link component */ -static const flecs::entity_t Link = EcsDocLink; +FLECS_STATIC_IN_HEADER const flecs::entity_t Link = EcsDocLink; /** flecs.doc.Color component */ -static const flecs::entity_t Color = EcsDocColor; +FLECS_STATIC_IN_HEADER const flecs::entity_t Color = EcsDocColor; +} // namespace doc +} // namespace flecs + +namespace flecs { + +namespace doc { /** @private */ namespace _ { @@ -18543,8 +18602,8 @@ void init(flecs::world& world); /** @} */ -} -} +} // namespace doc +} // namespace flecs #endif #ifdef FLECS_REST @@ -18555,7 +18614,7 @@ void init(flecs::world& world); #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_rest Rest @@ -18565,20 +18624,23 @@ namespace flecs { * @{ */ + using Rest = EcsRest; -namespace rest { +} // namespace flecs +namespace flecs { +namespace rest { namespace _ { void init(flecs::world& world); -} -} +} // namespace _ +} // namespace rest /** @} */ -} +} // namespace flecs #endif #ifdef FLECS_META @@ -18589,7 +18651,7 @@ void init(flecs::world& world); #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_meta Meta @@ -18639,62 +18701,66 @@ struct bitmask { }; /* Handles to builtin reflection types */ -static const flecs::entity_t Bool = ecs_id(ecs_bool_t); -static const flecs::entity_t Char = ecs_id(ecs_char_t); -static const flecs::entity_t Byte = ecs_id(ecs_byte_t); -static const flecs::entity_t U8 = ecs_id(ecs_u8_t); -static const flecs::entity_t U16 = ecs_id(ecs_u16_t); -static const flecs::entity_t U32 = ecs_id(ecs_u32_t); -static const flecs::entity_t U64 = ecs_id(ecs_u64_t); -static const flecs::entity_t Uptr = ecs_id(ecs_uptr_t); -static const flecs::entity_t I8 = ecs_id(ecs_i8_t); -static const flecs::entity_t I16 = ecs_id(ecs_i16_t); -static const flecs::entity_t I32 = ecs_id(ecs_i32_t); -static const flecs::entity_t I64 = ecs_id(ecs_i64_t); -static const flecs::entity_t Iptr = ecs_id(ecs_iptr_t); -static const flecs::entity_t F32 = ecs_id(ecs_f32_t); -static const flecs::entity_t F64 = ecs_id(ecs_f64_t); -static const flecs::entity_t String = ecs_id(ecs_string_t); -static const flecs::entity_t Entity = ecs_id(ecs_entity_t); -static const flecs::entity_t Constant = EcsConstant; -static const flecs::entity_t Quantity = EcsQuantity; +FLECS_STATIC_IN_HEADER const flecs::entity_t Bool = ecs_id(ecs_bool_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t Char = ecs_id(ecs_char_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t Byte = ecs_id(ecs_byte_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t U8 = ecs_id(ecs_u8_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t U16 = ecs_id(ecs_u16_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t U32 = ecs_id(ecs_u32_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t U64 = ecs_id(ecs_u64_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t Uptr = ecs_id(ecs_uptr_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t I8 = ecs_id(ecs_i8_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t I16 = ecs_id(ecs_i16_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t I32 = ecs_id(ecs_i32_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t I64 = ecs_id(ecs_i64_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t Iptr = ecs_id(ecs_iptr_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t F32 = ecs_id(ecs_f32_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t F64 = ecs_id(ecs_f64_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t String = ecs_id(ecs_string_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t Entity = ecs_id(ecs_entity_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t Constant = EcsConstant; +FLECS_STATIC_IN_HEADER const flecs::entity_t Quantity = EcsQuantity; namespace meta { /* Type kinds supported by reflection system */ using type_kind_t = ecs_type_kind_t; -static const type_kind_t PrimitiveType = EcsPrimitiveType; -static const type_kind_t BitmaskType = EcsBitmaskType; -static const type_kind_t EnumType = EcsEnumType; -static const type_kind_t StructType = EcsStructType; -static const type_kind_t ArrayType = EcsArrayType; -static const type_kind_t VectorType = EcsVectorType; -static const type_kind_t CustomType = EcsOpaqueType; -static const type_kind_t TypeKindLast = EcsTypeKindLast; +FLECS_STATIC_IN_HEADER const type_kind_t PrimitiveType = EcsPrimitiveType; +FLECS_STATIC_IN_HEADER const type_kind_t BitmaskType = EcsBitmaskType; +FLECS_STATIC_IN_HEADER const type_kind_t EnumType = EcsEnumType; +FLECS_STATIC_IN_HEADER const type_kind_t StructType = EcsStructType; +FLECS_STATIC_IN_HEADER const type_kind_t ArrayType = EcsArrayType; +FLECS_STATIC_IN_HEADER const type_kind_t VectorType = EcsVectorType; +FLECS_STATIC_IN_HEADER const type_kind_t CustomType = EcsOpaqueType; +FLECS_STATIC_IN_HEADER const type_kind_t TypeKindLast = EcsTypeKindLast; /* Primitive type kinds supported by reflection system */ using primitive_kind_t = ecs_primitive_kind_t; -static const primitive_kind_t Bool = EcsBool; -static const primitive_kind_t Char = EcsChar; -static const primitive_kind_t Byte = EcsByte; -static const primitive_kind_t U8 = EcsU8; -static const primitive_kind_t U16 = EcsU16; -static const primitive_kind_t U32 = EcsU32; -static const primitive_kind_t U64 = EcsU64; -static const primitive_kind_t I8 = EcsI8; -static const primitive_kind_t I16 = EcsI16; -static const primitive_kind_t I32 = EcsI32; -static const primitive_kind_t I64 = EcsI64; -static const primitive_kind_t F32 = EcsF32; -static const primitive_kind_t F64 = EcsF64; -static const primitive_kind_t UPtr = EcsUPtr; -static const primitive_kind_t IPtr = EcsIPtr; -static const primitive_kind_t String = EcsString; -static const primitive_kind_t Entity = EcsEntity; -static const primitive_kind_t PrimitiveKindLast = EcsPrimitiveKindLast; +FLECS_STATIC_IN_HEADER const primitive_kind_t Bool = EcsBool; +FLECS_STATIC_IN_HEADER const primitive_kind_t Char = EcsChar; +FLECS_STATIC_IN_HEADER const primitive_kind_t Byte = EcsByte; +FLECS_STATIC_IN_HEADER const primitive_kind_t U8 = EcsU8; +FLECS_STATIC_IN_HEADER const primitive_kind_t U16 = EcsU16; +FLECS_STATIC_IN_HEADER const primitive_kind_t U32 = EcsU32; +FLECS_STATIC_IN_HEADER const primitive_kind_t U64 = EcsU64; +FLECS_STATIC_IN_HEADER const primitive_kind_t I8 = EcsI8; +FLECS_STATIC_IN_HEADER const primitive_kind_t I16 = EcsI16; +FLECS_STATIC_IN_HEADER const primitive_kind_t I32 = EcsI32; +FLECS_STATIC_IN_HEADER const primitive_kind_t I64 = EcsI64; +FLECS_STATIC_IN_HEADER const primitive_kind_t F32 = EcsF32; +FLECS_STATIC_IN_HEADER const primitive_kind_t F64 = EcsF64; +FLECS_STATIC_IN_HEADER const primitive_kind_t UPtr = EcsUPtr; +FLECS_STATIC_IN_HEADER const primitive_kind_t IPtr = EcsIPtr; +FLECS_STATIC_IN_HEADER const primitive_kind_t String = EcsString; +FLECS_STATIC_IN_HEADER const primitive_kind_t Entity = EcsEntity; +FLECS_STATIC_IN_HEADER const primitive_kind_t PrimitiveKindLast = EcsPrimitiveKindLast; /** @} */ +} // namespace meta +} // namespace flecs +namespace flecs { +namespace meta { namespace _ { void init(flecs::world& world); @@ -18710,7 +18776,7 @@ void init(flecs::world& world); #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_meta Meta @@ -18875,7 +18941,7 @@ struct cursor { #include -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_meta Meta @@ -18892,10 +18958,12 @@ using serializer = ecs_serializer_t; using serialize_t = ecs_meta_serialize_t; /** Type safe variant of serializer function */ + template using serialize = int(*)(const serializer *, const T*); /** Type safe interface for opaque types */ + template struct opaque { opaque(flecs::world_t *w = nullptr) : world(w) { @@ -19059,7 +19127,9 @@ struct opaque { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { + + struct units { /** @@ -19424,7 +19494,7 @@ units(flecs::world& world); #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_stats Stats @@ -19435,14 +19505,18 @@ namespace flecs { */ /** Component that stores world statistics */ + using WorldStats = EcsWorldStats; /** Component that stores system/pipeline statistics */ + using PipelineStats = EcsPipelineStats; /** Component with world summary stats */ + using WorldSummary = EcsWorldSummary; + struct stats { stats(flecs::world& world); }; @@ -19469,7 +19543,7 @@ struct stats { #define ECS_EVENT_DESC_ID_COUNT_MAX (8) -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @ingroup cpp_addons_metrics @@ -19566,7 +19640,7 @@ struct metric_builder { } -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_metrics Metrics @@ -19577,6 +19651,7 @@ namespace flecs { * @{ */ + struct metrics { using Value = EcsMetricValue; using Source = EcsMetricSource; @@ -19604,7 +19679,7 @@ struct metrics { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_alerts Alerts @@ -19615,6 +19690,7 @@ namespace flecs { */ /** Module */ + struct alerts { using AlertsActive = EcsAlertsActive; using Instance = EcsAlertInstance; @@ -19627,9 +19703,11 @@ struct alerts { alerts(flecs::world& world); }; + template struct alert; + template struct alert_builder; @@ -19646,7 +19724,7 @@ struct alert_builder; #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_json Json @@ -19680,7 +19758,7 @@ using iter_to_json_desc_t = ecs_iter_to_json_desc_t; #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_app App @@ -19691,6 +19769,7 @@ namespace flecs { */ /** App builder interface */ + struct app_builder { app_builder(flecs::world_t *world) : world_(world) @@ -19784,7 +19863,7 @@ struct app_builder { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @ingroup cpp_addons_script @@ -19792,6 +19871,7 @@ namespace flecs { */ /** Script builder interface */ + struct script_builder { script_builder(flecs::world_t *world, const char *name = nullptr) : world_(world) @@ -19826,7 +19906,7 @@ struct script_builder { } -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_script Script @@ -19850,7 +19930,7 @@ struct script_builder; #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { namespace log { /** @@ -19952,9 +20032,12 @@ namespace flecs { namespace _ { struct pair_base { }; -} // _ +} // namespace _ + +} // namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_pair_type Pair type * @ingroup cpp_core @@ -20083,7 +20166,7 @@ struct is_actual { std::is_same >::value && !is_enum::value; }; -} // flecs +} // namespace flecs /** * @file addons/cpp/lifecycle_traits.hpp @@ -20266,7 +20349,11 @@ void move_dtor_impl(void *dst_ptr, void *src_ptr, int32_t count, } } -} // _ +} // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs +{ // Trait to test if type is constructible by flecs template @@ -20275,6 +20362,9 @@ struct is_flecs_constructible { std::is_default_constructible>::value; }; +} // namespace flecs + +namespace flecs { namespace _ { @@ -20467,7 +20557,7 @@ ecs_move_t move_dtor() { #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /* Static helper functions to assign a component value */ @@ -22395,7 +22485,7 @@ struct scoped_world : world { * @{ */ -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Unsafe wrapper class around a field. @@ -22551,7 +22641,7 @@ struct range_iterator } // namespace flecs -namespace flecs +FLECS_API_NAMESPACE namespace flecs { //////////////////////////////////////////////////////////////////////////////// @@ -23002,7 +23092,7 @@ struct iter { * @{ */ -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Entity view. @@ -24105,7 +24195,7 @@ void enqueue(const Evt& payload) const { #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Entity builder. @@ -25430,7 +25520,7 @@ const Self& observe(Func&& callback) const; * @{ */ -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Entity. @@ -25769,7 +25859,9 @@ const char* from_json(const char *json) { #pragma once +#ifndef FLECS_NO_STD_INCLUDE #include // std::declval +#endif namespace flecs { @@ -26656,6 +26748,10 @@ struct entity_with_delegate::value > > }; } // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs +{ // Experimental: allows using the each delegate for use cases outside of flecs template @@ -26670,8 +26766,10 @@ using delegate = _::each_delegate::type, Args...>; #pragma once +#ifndef FLECS_NO_STD_INCLUDE #include #include +#endif /** * @defgroup cpp_components Components @@ -26682,7 +26780,6 @@ using delegate = _::each_delegate::type, Args...>; */ namespace flecs { - namespace _ { // Trick to obtain typename from type, as described here @@ -27006,6 +27103,9 @@ struct type::value >> }; } // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs { /** Untyped component class. * Generic base class for flecs::component. @@ -27611,7 +27711,7 @@ inline void reset() { #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** @@ -27699,7 +27799,7 @@ struct ref { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_types Types @@ -27778,7 +27878,7 @@ struct type { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_tables Tables @@ -28129,7 +28229,7 @@ struct table_range : table { * @brief Base class for iterable objects, like queries. */ -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template struct iter_iterable; @@ -28500,7 +28600,7 @@ worker_iterable iterable::worker( #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { inline flecs::entity id::entity() const { ecs_assert(!is_pair(), ECS_INVALID_OPERATION, NULL); @@ -28610,7 +28710,7 @@ inline flecs::id world::pair(entity_t r, entity_t o) const { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template flecs::entity ref::entity() const { @@ -28842,7 +28942,7 @@ inline flecs::entity world::prefab(const char *name) const { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template inline flecs::component world::component(Args &&... args) const { @@ -28954,7 +29054,7 @@ namespace _ { } // namespace flecs -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Term identifier builder. @@ -29387,7 +29487,7 @@ struct term_builder_i : term_ref_builder_i { } -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** Class that describes a term. * @@ -29595,7 +29695,7 @@ struct builder : IBuilder #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Query builder interface. @@ -29969,12 +30069,14 @@ namespace flecs { namespace _ { template using query_builder_base = builder< - query, ecs_query_desc_t, query_builder, + query, ecs_query_desc_t, query_builder, query_builder_i, Components ...>; -} +} // namespace _ +} // namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Query builder. - * + * * @ingroup cpp_core_queries */ template @@ -30005,10 +30107,10 @@ struct query_builder final : _::query_builder_base { } }; -} +} // namespace flecs -namespace flecs +FLECS_API_NAMESPACE namespace flecs { struct query_base { @@ -30238,8 +30340,10 @@ template inline flecs::query_builder world::query_builder(Args &&... args) const { return flecs::query_builder(world_, FLECS_FWD(args)...); } +} // namespace flecs // world::each +namespace flecs { namespace _ { // Each with entity parameter @@ -30286,7 +30390,10 @@ struct query_delegate, flecs::entity>:: } }; -} +} // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs { template inline void world::each(Func&& func) const { @@ -30420,7 +30527,7 @@ struct node_builder : IBuilder #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** Observer builder interface. * @@ -30499,12 +30606,16 @@ namespace flecs { namespace _ { template using observer_builder_base = node_builder< - observer, ecs_observer_desc_t, observer_builder, + observer, ecs_observer_desc_t, observer_builder, observer_builder_i, Components ...>; -} + +} // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs { /** Observer builder. - * + * * @ingroup cpp_observers */ template @@ -30516,10 +30627,10 @@ struct observer_builder final : _::observer_builder_base { } }; -} +} // namespace flecs -namespace flecs +FLECS_API_NAMESPACE namespace flecs { struct observer final : entity @@ -30569,7 +30680,7 @@ inline observer_builder world::observer(Args &&... args) const { #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { // Mixin implementation @@ -30583,6 +30694,9 @@ inline flecs::event_builder_typed world::event() const { return flecs::event_builder_typed(world_, _::type().id(world_)); } +} // namespace flecs + +namespace flecs { namespace _ { inline void entity_observer_create( flecs::world_t *world, @@ -30675,7 +30789,7 @@ inline void entity_view::enqueue(flecs::entity evt) const { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template inline E entity_view::to_constant() const { @@ -30761,7 +30875,11 @@ flecs::entity import(world& world) { return flecs::entity(world, m); } -} +} // namespace _ +} // namespace flecs + + +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_modules Modules @@ -30832,7 +30950,7 @@ inline flecs::entity world::import() { #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** System builder interface. @@ -30991,12 +31109,14 @@ namespace flecs { namespace _ { template using system_builder_base = node_builder< - system, ecs_system_desc_t, system_builder, + system, ecs_system_desc_t, system_builder, system_builder_i, Components ...>; -} +} // namespace _ +} // namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** System builder. - * + * * @ingroup cpp_addons_systems */ template @@ -31013,10 +31133,10 @@ struct system_builder final : _::system_builder_base { } }; -} +} // namespace flecs -namespace flecs +FLECS_API_NAMESPACE namespace flecs { struct system_runner_fluent { @@ -31188,6 +31308,9 @@ inline system_builder world::system(Args &&... args) const { return flecs::system_builder(world_, FLECS_FWD(args)...); } +} // namespace flecs + +namespace flecs { namespace _ { inline void system_init(flecs::world& world) { @@ -31221,7 +31344,7 @@ inline void system_init(flecs::world& world) { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** Pipeline builder interface. * @@ -31244,12 +31367,14 @@ namespace flecs { namespace _ { template using pipeline_builder_base = builder< - pipeline, ecs_pipeline_desc_t, pipeline_builder, + pipeline, ecs_pipeline_desc_t, pipeline_builder, pipeline_builder_i, Components ...>; -} +} // namespace _ +} // namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Pipeline builder. - * + * * @ingroup cpp_pipelines */ template @@ -31262,10 +31387,10 @@ struct pipeline_builder final : _::pipeline_builder_base { } }; -} +} // namespace flecs -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template struct pipeline : entity { @@ -31354,7 +31479,7 @@ inline bool world::using_task_threads() const { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { // Timer class struct timer final : entity { @@ -31443,6 +31568,9 @@ inline void system::set_tick_source(flecs::entity e) { ecs_set_tick_source(world_, id_, e); } +} // namespace flecs + +namespace flecs { namespace _ { inline void timer_init(flecs::world& world) { @@ -31450,8 +31578,8 @@ inline void timer_init(flecs::world& world) { world.component("flecs::timer::Timer"); } -} -} +} // namespace _ +} // namespace flecs #endif #ifdef FLECS_DOC @@ -31462,7 +31590,7 @@ inline void timer_init(flecs::world& world) { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { namespace doc { /** Get UUID for an entity. @@ -31608,7 +31736,12 @@ inline void set_link(flecs::entity& e, const char *link) { inline void set_color(flecs::entity& e, const char *color) { ecs_doc_set_color(e.world(), e, color); } +} // namespace doc +} // namespace flecs +namespace flecs { + +namespace doc { /** @private */ namespace _ { @@ -31796,6 +31929,8 @@ inline flecs::entity world::vector() { } // namespace flecs +extern "C++" { + inline int ecs_serializer_t::value(ecs_entity_t type, const void *v) const { return this->value_(this, type, v); } @@ -31809,6 +31944,7 @@ inline int ecs_serializer_t::value(const T& v) const { inline int ecs_serializer_t::member(const char *name) const { return this->member_(this, name); } +} #endif #ifdef FLECS_UNITS @@ -31819,7 +31955,7 @@ inline int ecs_serializer_t::member(const char *name) const { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { inline units::units(flecs::world& world) { /* Import C module */ @@ -32042,7 +32178,7 @@ inline units::units(flecs::world& world) { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { inline stats::stats(flecs::world& world) { #ifdef FLECS_UNITS @@ -32068,7 +32204,7 @@ inline stats::stats(flecs::world& world) { #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { inline metrics::metrics(flecs::world& world) { world.import(); @@ -32211,7 +32347,7 @@ inline untyped_component& untyped_component::metric( #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** Alert builder interface. * @@ -32370,12 +32506,14 @@ namespace flecs { namespace _ { template using alert_builder_base = builder< - alert, ecs_alert_desc_t, alert_builder, + alert, ecs_alert_desc_t, alert_builder, alert_builder_i, Components ...>; -} +} // namespace _ +} // namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Alert builder. - * + * * @ingroup cpp_addons_alerts */ template @@ -32394,10 +32532,10 @@ struct alert_builder final : _::alert_builder_base { } }; -} +} // namespace flecs -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template struct alert final : entity @@ -32447,7 +32585,7 @@ inline flecs::alert_builder world::alert(Args &&... args) const { #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { inline flecs::entity script_builder::run() const { @@ -32466,7 +32604,7 @@ inline flecs::entity script_builder::run() const { #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { template @@ -32527,7 +32665,7 @@ T* field::operator->() const { #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { inline flecs::entity iter::system() const { @@ -32649,7 +32787,7 @@ void iter::targets(int8_t index, const Func& func) { #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { inline void world::init_builtin_components() { @@ -32990,6 +33128,8 @@ inline flecs::scoped_world world::scope(const char* name) const { #endif // __cplusplus +#endif // !FLECS_CPP20_MODULE_HEADER + #endif // FLECS_CPP #endif diff --git a/include/flecs/addons/cpp/c_types.hpp b/include/flecs/addons/cpp/c_types.hpp index 1016c1fb8f..8f71bd6371 100644 --- a/include/flecs/addons/cpp/c_types.hpp +++ b/include/flecs/addons/cpp/c_types.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_globals API Types & Globals @@ -58,9 +58,9 @@ enum query_cache_kind_t { }; /** Id bit flags */ -static const flecs::entity_t PAIR = ECS_PAIR; -static const flecs::entity_t AUTO_OVERRIDE = ECS_AUTO_OVERRIDE; -static const flecs::entity_t TOGGLE = ECS_TOGGLE; +FLECS_STATIC_IN_HEADER const flecs::entity_t PAIR = ECS_PAIR; +FLECS_STATIC_IN_HEADER const flecs::entity_t AUTO_OVERRIDE = ECS_AUTO_OVERRIDE; +FLECS_STATIC_IN_HEADER const flecs::entity_t TOGGLE = ECS_TOGGLE; //////////////////////////////////////////////////////////////////////////////// //// Builtin components and tags @@ -73,96 +73,96 @@ using Poly = EcsPoly; using DefaultChildComponent = EcsDefaultChildComponent; /* Builtin tags */ -static const flecs::entity_t Query = EcsQuery; -static const flecs::entity_t Observer = EcsObserver; -static const flecs::entity_t Private = EcsPrivate; -static const flecs::entity_t Module = EcsModule; -static const flecs::entity_t Prefab = EcsPrefab; -static const flecs::entity_t Disabled = EcsDisabled; -static const flecs::entity_t Empty = EcsEmpty; -static const flecs::entity_t Monitor = EcsMonitor; -static const flecs::entity_t System = EcsSystem; -static const flecs::entity_t Pipeline = ecs_id(EcsPipeline); -static const flecs::entity_t Phase = EcsPhase; +FLECS_STATIC_IN_HEADER const flecs::entity_t Query = EcsQuery; +FLECS_STATIC_IN_HEADER const flecs::entity_t Observer = EcsObserver; +FLECS_STATIC_IN_HEADER const flecs::entity_t Private = EcsPrivate; +FLECS_STATIC_IN_HEADER const flecs::entity_t Module = EcsModule; +FLECS_STATIC_IN_HEADER const flecs::entity_t Prefab = EcsPrefab; +FLECS_STATIC_IN_HEADER const flecs::entity_t Disabled = EcsDisabled; +FLECS_STATIC_IN_HEADER const flecs::entity_t Empty = EcsEmpty; +FLECS_STATIC_IN_HEADER const flecs::entity_t Monitor = EcsMonitor; +FLECS_STATIC_IN_HEADER const flecs::entity_t System = EcsSystem; +FLECS_STATIC_IN_HEADER const flecs::entity_t Pipeline = ecs_id(EcsPipeline); +FLECS_STATIC_IN_HEADER const flecs::entity_t Phase = EcsPhase; /* Builtin event tags */ -static const flecs::entity_t OnAdd = EcsOnAdd; -static const flecs::entity_t OnRemove = EcsOnRemove; -static const flecs::entity_t OnSet = EcsOnSet; -static const flecs::entity_t OnTableCreate = EcsOnTableCreate; -static const flecs::entity_t OnTableDelete = EcsOnTableDelete; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnAdd = EcsOnAdd; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnRemove = EcsOnRemove; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnSet = EcsOnSet; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnTableCreate = EcsOnTableCreate; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnTableDelete = EcsOnTableDelete; /* Builtin term flags */ -static const uint64_t Self = EcsSelf; -static const uint64_t Up = EcsUp; -static const uint64_t Trav = EcsTrav; -static const uint64_t Cascade = EcsCascade; -static const uint64_t Desc = EcsDesc; -static const uint64_t IsVariable = EcsIsVariable; -static const uint64_t IsEntity = EcsIsEntity; -static const uint64_t IsName = EcsIsName; -static const uint64_t TraverseFlags = EcsTraverseFlags; -static const uint64_t TermRefFlags = EcsTermRefFlags; +FLECS_STATIC_IN_HEADER const uint64_t Self = EcsSelf; +FLECS_STATIC_IN_HEADER const uint64_t Up = EcsUp; +FLECS_STATIC_IN_HEADER const uint64_t Trav = EcsTrav; +FLECS_STATIC_IN_HEADER const uint64_t Cascade = EcsCascade; +FLECS_STATIC_IN_HEADER const uint64_t Desc = EcsDesc; +FLECS_STATIC_IN_HEADER const uint64_t IsVariable = EcsIsVariable; +FLECS_STATIC_IN_HEADER const uint64_t IsEntity = EcsIsEntity; +FLECS_STATIC_IN_HEADER const uint64_t IsName = EcsIsName; +FLECS_STATIC_IN_HEADER const uint64_t TraverseFlags = EcsTraverseFlags; +FLECS_STATIC_IN_HEADER const uint64_t TermRefFlags = EcsTermRefFlags; /* Builtin entity ids */ -static const flecs::entity_t Flecs = EcsFlecs; -static const flecs::entity_t FlecsCore = EcsFlecsCore; -static const flecs::entity_t World = EcsWorld; +FLECS_STATIC_IN_HEADER const flecs::entity_t Flecs = EcsFlecs; +FLECS_STATIC_IN_HEADER const flecs::entity_t FlecsCore = EcsFlecsCore; +FLECS_STATIC_IN_HEADER const flecs::entity_t World = EcsWorld; /* Component traits */ -static const flecs::entity_t Wildcard = EcsWildcard; -static const flecs::entity_t Any = EcsAny; -static const flecs::entity_t This = EcsThis; -static const flecs::entity_t Transitive = EcsTransitive; -static const flecs::entity_t Reflexive = EcsReflexive; -static const flecs::entity_t Final = EcsFinal; -static const flecs::entity_t PairIsTag = EcsPairIsTag; -static const flecs::entity_t Exclusive = EcsExclusive; -static const flecs::entity_t Acyclic = EcsAcyclic; -static const flecs::entity_t Traversable = EcsTraversable; -static const flecs::entity_t Symmetric = EcsSymmetric; -static const flecs::entity_t With = EcsWith; -static const flecs::entity_t OneOf = EcsOneOf; -static const flecs::entity_t Trait = EcsTrait; -static const flecs::entity_t Relationship = EcsRelationship; -static const flecs::entity_t Target = EcsTarget; -static const flecs::entity_t CanToggle = EcsCanToggle; +FLECS_STATIC_IN_HEADER const flecs::entity_t Wildcard = EcsWildcard; +FLECS_STATIC_IN_HEADER const flecs::entity_t Any = EcsAny; +FLECS_STATIC_IN_HEADER const flecs::entity_t This = EcsThis; +FLECS_STATIC_IN_HEADER const flecs::entity_t Transitive = EcsTransitive; +FLECS_STATIC_IN_HEADER const flecs::entity_t Reflexive = EcsReflexive; +FLECS_STATIC_IN_HEADER const flecs::entity_t Final = EcsFinal; +FLECS_STATIC_IN_HEADER const flecs::entity_t PairIsTag = EcsPairIsTag; +FLECS_STATIC_IN_HEADER const flecs::entity_t Exclusive = EcsExclusive; +FLECS_STATIC_IN_HEADER const flecs::entity_t Acyclic = EcsAcyclic; +FLECS_STATIC_IN_HEADER const flecs::entity_t Traversable = EcsTraversable; +FLECS_STATIC_IN_HEADER const flecs::entity_t Symmetric = EcsSymmetric; +FLECS_STATIC_IN_HEADER const flecs::entity_t With = EcsWith; +FLECS_STATIC_IN_HEADER const flecs::entity_t OneOf = EcsOneOf; +FLECS_STATIC_IN_HEADER const flecs::entity_t Trait = EcsTrait; +FLECS_STATIC_IN_HEADER const flecs::entity_t Relationship = EcsRelationship; +FLECS_STATIC_IN_HEADER const flecs::entity_t Target = EcsTarget; +FLECS_STATIC_IN_HEADER const flecs::entity_t CanToggle = EcsCanToggle; /* OnInstantiate trait */ -static const flecs::entity_t OnInstantiate = EcsOnInstantiate; -static const flecs::entity_t Override = EcsOverride; -static const flecs::entity_t Inherit = EcsInherit; -static const flecs::entity_t DontInherit = EcsDontInherit; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnInstantiate = EcsOnInstantiate; +FLECS_STATIC_IN_HEADER const flecs::entity_t Override = EcsOverride; +FLECS_STATIC_IN_HEADER const flecs::entity_t Inherit = EcsInherit; +FLECS_STATIC_IN_HEADER const flecs::entity_t DontInherit = EcsDontInherit; /* OnDelete/OnDeleteTarget traits */ -static const flecs::entity_t OnDelete = EcsOnDelete; -static const flecs::entity_t OnDeleteTarget = EcsOnDeleteTarget; -static const flecs::entity_t Remove = EcsRemove; -static const flecs::entity_t Delete = EcsDelete; -static const flecs::entity_t Panic = EcsPanic; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnDelete = EcsOnDelete; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnDeleteTarget = EcsOnDeleteTarget; +FLECS_STATIC_IN_HEADER const flecs::entity_t Remove = EcsRemove; +FLECS_STATIC_IN_HEADER const flecs::entity_t Delete = EcsDelete; +FLECS_STATIC_IN_HEADER const flecs::entity_t Panic = EcsPanic; /* Builtin relationships */ -static const flecs::entity_t IsA = EcsIsA; -static const flecs::entity_t ChildOf = EcsChildOf; -static const flecs::entity_t DependsOn = EcsDependsOn; -static const flecs::entity_t SlotOf = EcsSlotOf; +FLECS_STATIC_IN_HEADER const flecs::entity_t IsA = EcsIsA; +FLECS_STATIC_IN_HEADER const flecs::entity_t ChildOf = EcsChildOf; +FLECS_STATIC_IN_HEADER const flecs::entity_t DependsOn = EcsDependsOn; +FLECS_STATIC_IN_HEADER const flecs::entity_t SlotOf = EcsSlotOf; /* Builtin identifiers */ -static const flecs::entity_t Name = EcsName; -static const flecs::entity_t Symbol = EcsSymbol; +FLECS_STATIC_IN_HEADER const flecs::entity_t Name = EcsName; +FLECS_STATIC_IN_HEADER const flecs::entity_t Symbol = EcsSymbol; /* Storage */ -static const flecs::entity_t Sparse = EcsSparse; -static const flecs::entity_t Union = EcsUnion; +FLECS_STATIC_IN_HEADER const flecs::entity_t Sparse = EcsSparse; +FLECS_STATIC_IN_HEADER const flecs::entity_t Union = EcsUnion; /* Builtin predicates for comparing entity ids in queries. */ -static const flecs::entity_t PredEq = EcsPredEq; -static const flecs::entity_t PredMatch = EcsPredMatch; -static const flecs::entity_t PredLookup = EcsPredLookup; +FLECS_STATIC_IN_HEADER const flecs::entity_t PredEq = EcsPredEq; +FLECS_STATIC_IN_HEADER const flecs::entity_t PredMatch = EcsPredMatch; +FLECS_STATIC_IN_HEADER const flecs::entity_t PredLookup = EcsPredLookup; /* Builtin marker entities for query scopes */ -static const flecs::entity_t ScopeOpen = EcsScopeOpen; -static const flecs::entity_t ScopeClose = EcsScopeClose; +FLECS_STATIC_IN_HEADER const flecs::entity_t ScopeOpen = EcsScopeOpen; +FLECS_STATIC_IN_HEADER const flecs::entity_t ScopeClose = EcsScopeClose; /** @} */ diff --git a/include/flecs/addons/cpp/component.hpp b/include/flecs/addons/cpp/component.hpp index 58e82739ff..ac666b6797 100644 --- a/include/flecs/addons/cpp/component.hpp +++ b/include/flecs/addons/cpp/component.hpp @@ -5,8 +5,10 @@ #pragma once +#ifndef FLECS_NO_STD_INCLUDE #include #include +#endif /** * @defgroup cpp_components Components @@ -17,7 +19,6 @@ */ namespace flecs { - namespace _ { // Trick to obtain typename from type, as described here @@ -341,6 +342,9 @@ struct type::value >> }; } // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs { /** Untyped component class. * Generic base class for flecs::component. diff --git a/include/flecs/addons/cpp/delegate.hpp b/include/flecs/addons/cpp/delegate.hpp index 42b22c9c75..c30c9fb3a7 100644 --- a/include/flecs/addons/cpp/delegate.hpp +++ b/include/flecs/addons/cpp/delegate.hpp @@ -5,7 +5,9 @@ #pragma once +#ifndef FLECS_NO_STD_INCLUDE #include // std::declval +#endif namespace flecs { @@ -892,6 +894,10 @@ struct entity_with_delegate::value > > }; } // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs +{ // Experimental: allows using the each delegate for use cases outside of flecs template diff --git a/include/flecs/addons/cpp/entity.hpp b/include/flecs/addons/cpp/entity.hpp index a8cce4dffa..14e7d936b9 100644 --- a/include/flecs/addons/cpp/entity.hpp +++ b/include/flecs/addons/cpp/entity.hpp @@ -18,7 +18,7 @@ * @{ */ -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Entity. diff --git a/include/flecs/addons/cpp/entity_view.hpp b/include/flecs/addons/cpp/entity_view.hpp index c54ea7dc9f..ffbc2529a9 100644 --- a/include/flecs/addons/cpp/entity_view.hpp +++ b/include/flecs/addons/cpp/entity_view.hpp @@ -17,7 +17,7 @@ * @{ */ -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Entity view. diff --git a/include/flecs/addons/cpp/field.hpp b/include/flecs/addons/cpp/field.hpp index 7248f1427d..1629bc5a52 100644 --- a/include/flecs/addons/cpp/field.hpp +++ b/include/flecs/addons/cpp/field.hpp @@ -14,7 +14,7 @@ * @{ */ -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Unsafe wrapper class around a field. diff --git a/include/flecs/addons/cpp/flecs.hpp b/include/flecs/addons/cpp/flecs.hpp index 8d7c542e86..2b50ddf2e8 100644 --- a/include/flecs/addons/cpp/flecs.hpp +++ b/include/flecs/addons/cpp/flecs.hpp @@ -6,14 +6,28 @@ #pragma once // STL includes +#ifndef FLECS_NO_STD_INCLUDE #include +#endif + +#ifndef FLECS_API_NAMESPACE +#define FLECS_API_NAMESPACE +#endif + +#ifndef FLECS_API_DEPENDENCY +#define FLECS_API_DEPENDENCY +#endif + +#ifndef FLECS_STATIC_IN_HEADER +#define FLECS_STATIC_IN_HEADER static +#endif /** * @defgroup cpp C++ API * @{ */ -namespace flecs +FLECS_API_NAMESPACE namespace flecs { struct world; @@ -26,12 +40,17 @@ struct table; struct table_range; struct untyped_component; + template struct component; + template struct ref; +} // namespace flecs + +namespace flecs { namespace _ { template diff --git a/include/flecs/addons/cpp/impl/field.hpp b/include/flecs/addons/cpp/impl/field.hpp index 3957a56a31..af005ac824 100644 --- a/include/flecs/addons/cpp/impl/field.hpp +++ b/include/flecs/addons/cpp/impl/field.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { template diff --git a/include/flecs/addons/cpp/impl/iter.hpp b/include/flecs/addons/cpp/impl/iter.hpp index 3e0dd50d12..7d7eeb83ba 100644 --- a/include/flecs/addons/cpp/impl/iter.hpp +++ b/include/flecs/addons/cpp/impl/iter.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { inline flecs::entity iter::system() const { diff --git a/include/flecs/addons/cpp/impl/world.hpp b/include/flecs/addons/cpp/impl/world.hpp index 18a53751d7..a9cb2d2344 100644 --- a/include/flecs/addons/cpp/impl/world.hpp +++ b/include/flecs/addons/cpp/impl/world.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { inline void world::init_builtin_components() { diff --git a/include/flecs/addons/cpp/iter.hpp b/include/flecs/addons/cpp/iter.hpp index a9d45bd9bb..dea81da26a 100644 --- a/include/flecs/addons/cpp/iter.hpp +++ b/include/flecs/addons/cpp/iter.hpp @@ -56,7 +56,7 @@ struct range_iterator } // namespace flecs -namespace flecs +FLECS_API_NAMESPACE namespace flecs { //////////////////////////////////////////////////////////////////////////////// diff --git a/include/flecs/addons/cpp/lifecycle_traits.hpp b/include/flecs/addons/cpp/lifecycle_traits.hpp index 1ea94b1fce..3a51ba7ff2 100644 --- a/include/flecs/addons/cpp/lifecycle_traits.hpp +++ b/include/flecs/addons/cpp/lifecycle_traits.hpp @@ -179,7 +179,11 @@ void move_dtor_impl(void *dst_ptr, void *src_ptr, int32_t count, } } -} // _ +} // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs +{ // Trait to test if type is constructible by flecs template @@ -188,6 +192,9 @@ struct is_flecs_constructible { std::is_default_constructible>::value; }; +} // namespace flecs + +namespace flecs { namespace _ { diff --git a/include/flecs/addons/cpp/log.hpp b/include/flecs/addons/cpp/log.hpp index b9cdf42ce1..7cb113f1ee 100644 --- a/include/flecs/addons/cpp/log.hpp +++ b/include/flecs/addons/cpp/log.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { namespace log { /** diff --git a/include/flecs/addons/cpp/mixins/alerts/builder.hpp b/include/flecs/addons/cpp/mixins/alerts/builder.hpp index 9c525b496c..9f66bc9d93 100644 --- a/include/flecs/addons/cpp/mixins/alerts/builder.hpp +++ b/include/flecs/addons/cpp/mixins/alerts/builder.hpp @@ -12,12 +12,14 @@ namespace flecs { namespace _ { template using alert_builder_base = builder< - alert, ecs_alert_desc_t, alert_builder, + alert, ecs_alert_desc_t, alert_builder, alert_builder_i, Components ...>; -} +} // namespace _ +} // namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Alert builder. - * + * * @ingroup cpp_addons_alerts */ template @@ -36,4 +38,4 @@ struct alert_builder final : _::alert_builder_base { } }; -} +} // namespace flecs diff --git a/include/flecs/addons/cpp/mixins/alerts/builder_i.hpp b/include/flecs/addons/cpp/mixins/alerts/builder_i.hpp index 47d521edf5..223218b106 100644 --- a/include/flecs/addons/cpp/mixins/alerts/builder_i.hpp +++ b/include/flecs/addons/cpp/mixins/alerts/builder_i.hpp @@ -7,7 +7,7 @@ #include "../query/builder_i.hpp" -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** Alert builder interface. * diff --git a/include/flecs/addons/cpp/mixins/alerts/decl.hpp b/include/flecs/addons/cpp/mixins/alerts/decl.hpp index d5b8b5f63c..1af666ef14 100644 --- a/include/flecs/addons/cpp/mixins/alerts/decl.hpp +++ b/include/flecs/addons/cpp/mixins/alerts/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_alerts Alerts @@ -16,6 +16,7 @@ namespace flecs { */ /** Module */ + struct alerts { using AlertsActive = EcsAlertsActive; using Instance = EcsAlertInstance; @@ -28,9 +29,11 @@ struct alerts { alerts(flecs::world& world); }; + template struct alert; + template struct alert_builder; diff --git a/include/flecs/addons/cpp/mixins/alerts/impl.hpp b/include/flecs/addons/cpp/mixins/alerts/impl.hpp index b01c4dd6c8..fd4cbbd66f 100644 --- a/include/flecs/addons/cpp/mixins/alerts/impl.hpp +++ b/include/flecs/addons/cpp/mixins/alerts/impl.hpp @@ -7,7 +7,7 @@ #include "builder.hpp" -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template struct alert final : entity diff --git a/include/flecs/addons/cpp/mixins/app/builder.hpp b/include/flecs/addons/cpp/mixins/app/builder.hpp index 9bcd1fae87..8a8fd4ee31 100644 --- a/include/flecs/addons/cpp/mixins/app/builder.hpp +++ b/include/flecs/addons/cpp/mixins/app/builder.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_app App @@ -16,6 +16,7 @@ namespace flecs { */ /** App builder interface */ + struct app_builder { app_builder(flecs::world_t *world) : world_(world) diff --git a/include/flecs/addons/cpp/mixins/component/impl.hpp b/include/flecs/addons/cpp/mixins/component/impl.hpp index fe77fcc57c..688206f7ef 100644 --- a/include/flecs/addons/cpp/mixins/component/impl.hpp +++ b/include/flecs/addons/cpp/mixins/component/impl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template inline flecs::component world::component(Args &&... args) const { diff --git a/include/flecs/addons/cpp/mixins/doc/decl.hpp b/include/flecs/addons/cpp/mixins/doc/decl.hpp index 6a87ae436e..87efd9bc45 100644 --- a/include/flecs/addons/cpp/mixins/doc/decl.hpp +++ b/include/flecs/addons/cpp/mixins/doc/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { namespace doc { /** @@ -20,19 +20,25 @@ namespace doc { using Description = EcsDocDescription; /** flecs.doc.Uuid component */ -static const flecs::entity_t Uuid = EcsDocUuid; +FLECS_STATIC_IN_HEADER const flecs::entity_t Uuid = EcsDocUuid; /** flecs.doc.Brief component */ -static const flecs::entity_t Brief = EcsDocBrief; +FLECS_STATIC_IN_HEADER const flecs::entity_t Brief = EcsDocBrief; /** flecs.doc.Detail component */ -static const flecs::entity_t Detail = EcsDocDetail; +FLECS_STATIC_IN_HEADER const flecs::entity_t Detail = EcsDocDetail; /** flecs.doc.Link component */ -static const flecs::entity_t Link = EcsDocLink; +FLECS_STATIC_IN_HEADER const flecs::entity_t Link = EcsDocLink; /** flecs.doc.Color component */ -static const flecs::entity_t Color = EcsDocColor; +FLECS_STATIC_IN_HEADER const flecs::entity_t Color = EcsDocColor; +} // namespace doc +} // namespace flecs + +namespace flecs { + +namespace doc { /** @private */ namespace _ { @@ -42,5 +48,5 @@ void init(flecs::world& world); /** @} */ -} -} +} // namespace doc +} // namespace flecs diff --git a/include/flecs/addons/cpp/mixins/doc/impl.hpp b/include/flecs/addons/cpp/mixins/doc/impl.hpp index abcc77adf6..4873346850 100644 --- a/include/flecs/addons/cpp/mixins/doc/impl.hpp +++ b/include/flecs/addons/cpp/mixins/doc/impl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { namespace doc { /** Get UUID for an entity. @@ -151,7 +151,12 @@ inline void set_link(flecs::entity& e, const char *link) { inline void set_color(flecs::entity& e, const char *color) { ecs_doc_set_color(e.world(), e, color); } +} // namespace doc +} // namespace flecs +namespace flecs { + +namespace doc { /** @private */ namespace _ { diff --git a/include/flecs/addons/cpp/mixins/entity/builder.hpp b/include/flecs/addons/cpp/mixins/entity/builder.hpp index b963a97d52..d97196016b 100644 --- a/include/flecs/addons/cpp/mixins/entity/builder.hpp +++ b/include/flecs/addons/cpp/mixins/entity/builder.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Entity builder. diff --git a/include/flecs/addons/cpp/mixins/entity/impl.hpp b/include/flecs/addons/cpp/mixins/entity/impl.hpp index 47ec8c3fd1..065d837e8f 100644 --- a/include/flecs/addons/cpp/mixins/entity/impl.hpp +++ b/include/flecs/addons/cpp/mixins/entity/impl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template flecs::entity ref::entity() const { diff --git a/include/flecs/addons/cpp/mixins/enum/impl.hpp b/include/flecs/addons/cpp/mixins/enum/impl.hpp index b3523487ce..c473eea034 100644 --- a/include/flecs/addons/cpp/mixins/enum/impl.hpp +++ b/include/flecs/addons/cpp/mixins/enum/impl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template inline E entity_view::to_constant() const { diff --git a/include/flecs/addons/cpp/mixins/event/builder.hpp b/include/flecs/addons/cpp/mixins/event/builder.hpp index 00ba00d35d..aadb17b742 100644 --- a/include/flecs/addons/cpp/mixins/event/builder.hpp +++ b/include/flecs/addons/cpp/mixins/event/builder.hpp @@ -7,7 +7,7 @@ #define ECS_EVENT_DESC_ID_COUNT_MAX (8) -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @ingroup cpp_addons_event diff --git a/include/flecs/addons/cpp/mixins/event/decl.hpp b/include/flecs/addons/cpp/mixins/event/decl.hpp index 3208171009..5857491619 100644 --- a/include/flecs/addons/cpp/mixins/event/decl.hpp +++ b/include/flecs/addons/cpp/mixins/event/decl.hpp @@ -29,5 +29,5 @@ struct event_from_func::value == 2>> { template using event_from_func_t = typename event_from_func::type; -} -} +} // namespace _ +} // namespace flecs diff --git a/include/flecs/addons/cpp/mixins/event/impl.hpp b/include/flecs/addons/cpp/mixins/event/impl.hpp index 785e0070b1..2103d61dbb 100644 --- a/include/flecs/addons/cpp/mixins/event/impl.hpp +++ b/include/flecs/addons/cpp/mixins/event/impl.hpp @@ -7,7 +7,7 @@ #include "builder.hpp" -namespace flecs +FLECS_API_NAMESPACE namespace flecs { // Mixin implementation @@ -21,6 +21,9 @@ inline flecs::event_builder_typed world::event() const { return flecs::event_builder_typed(world_, _::type().id(world_)); } +} // namespace flecs + +namespace flecs { namespace _ { inline void entity_observer_create( flecs::world_t *world, diff --git a/include/flecs/addons/cpp/mixins/id/decl.hpp b/include/flecs/addons/cpp/mixins/id/decl.hpp index f9850dea63..ce431471f4 100644 --- a/include/flecs/addons/cpp/mixins/id/decl.hpp +++ b/include/flecs/addons/cpp/mixins/id/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { struct id; struct entity; @@ -24,6 +24,7 @@ struct entity; * - pair ids * - entities with id flags set (like flecs::AUTO_OVERRIDE, flecs::TOGGLE) */ + struct id { id() : world_(nullptr) diff --git a/include/flecs/addons/cpp/mixins/id/impl.hpp b/include/flecs/addons/cpp/mixins/id/impl.hpp index 3e37366610..360177f593 100644 --- a/include/flecs/addons/cpp/mixins/id/impl.hpp +++ b/include/flecs/addons/cpp/mixins/id/impl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { inline flecs::entity id::entity() const { ecs_assert(!is_pair(), ECS_INVALID_OPERATION, NULL); diff --git a/include/flecs/addons/cpp/mixins/json/decl.hpp b/include/flecs/addons/cpp/mixins/json/decl.hpp index bfa18d361c..c0def516b5 100644 --- a/include/flecs/addons/cpp/mixins/json/decl.hpp +++ b/include/flecs/addons/cpp/mixins/json/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_json Json diff --git a/include/flecs/addons/cpp/mixins/meta/cursor.hpp b/include/flecs/addons/cpp/mixins/meta/cursor.hpp index 868621c2db..8ec62d6ffd 100644 --- a/include/flecs/addons/cpp/mixins/meta/cursor.hpp +++ b/include/flecs/addons/cpp/mixins/meta/cursor.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_meta Meta diff --git a/include/flecs/addons/cpp/mixins/meta/decl.hpp b/include/flecs/addons/cpp/mixins/meta/decl.hpp index 0e7c93debc..620c6d2199 100644 --- a/include/flecs/addons/cpp/mixins/meta/decl.hpp +++ b/include/flecs/addons/cpp/mixins/meta/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_meta Meta @@ -55,62 +55,66 @@ struct bitmask { }; /* Handles to builtin reflection types */ -static const flecs::entity_t Bool = ecs_id(ecs_bool_t); -static const flecs::entity_t Char = ecs_id(ecs_char_t); -static const flecs::entity_t Byte = ecs_id(ecs_byte_t); -static const flecs::entity_t U8 = ecs_id(ecs_u8_t); -static const flecs::entity_t U16 = ecs_id(ecs_u16_t); -static const flecs::entity_t U32 = ecs_id(ecs_u32_t); -static const flecs::entity_t U64 = ecs_id(ecs_u64_t); -static const flecs::entity_t Uptr = ecs_id(ecs_uptr_t); -static const flecs::entity_t I8 = ecs_id(ecs_i8_t); -static const flecs::entity_t I16 = ecs_id(ecs_i16_t); -static const flecs::entity_t I32 = ecs_id(ecs_i32_t); -static const flecs::entity_t I64 = ecs_id(ecs_i64_t); -static const flecs::entity_t Iptr = ecs_id(ecs_iptr_t); -static const flecs::entity_t F32 = ecs_id(ecs_f32_t); -static const flecs::entity_t F64 = ecs_id(ecs_f64_t); -static const flecs::entity_t String = ecs_id(ecs_string_t); -static const flecs::entity_t Entity = ecs_id(ecs_entity_t); -static const flecs::entity_t Constant = EcsConstant; -static const flecs::entity_t Quantity = EcsQuantity; +FLECS_STATIC_IN_HEADER const flecs::entity_t Bool = ecs_id(ecs_bool_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t Char = ecs_id(ecs_char_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t Byte = ecs_id(ecs_byte_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t U8 = ecs_id(ecs_u8_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t U16 = ecs_id(ecs_u16_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t U32 = ecs_id(ecs_u32_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t U64 = ecs_id(ecs_u64_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t Uptr = ecs_id(ecs_uptr_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t I8 = ecs_id(ecs_i8_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t I16 = ecs_id(ecs_i16_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t I32 = ecs_id(ecs_i32_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t I64 = ecs_id(ecs_i64_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t Iptr = ecs_id(ecs_iptr_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t F32 = ecs_id(ecs_f32_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t F64 = ecs_id(ecs_f64_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t String = ecs_id(ecs_string_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t Entity = ecs_id(ecs_entity_t); +FLECS_STATIC_IN_HEADER const flecs::entity_t Constant = EcsConstant; +FLECS_STATIC_IN_HEADER const flecs::entity_t Quantity = EcsQuantity; namespace meta { /* Type kinds supported by reflection system */ using type_kind_t = ecs_type_kind_t; -static const type_kind_t PrimitiveType = EcsPrimitiveType; -static const type_kind_t BitmaskType = EcsBitmaskType; -static const type_kind_t EnumType = EcsEnumType; -static const type_kind_t StructType = EcsStructType; -static const type_kind_t ArrayType = EcsArrayType; -static const type_kind_t VectorType = EcsVectorType; -static const type_kind_t CustomType = EcsOpaqueType; -static const type_kind_t TypeKindLast = EcsTypeKindLast; +FLECS_STATIC_IN_HEADER const type_kind_t PrimitiveType = EcsPrimitiveType; +FLECS_STATIC_IN_HEADER const type_kind_t BitmaskType = EcsBitmaskType; +FLECS_STATIC_IN_HEADER const type_kind_t EnumType = EcsEnumType; +FLECS_STATIC_IN_HEADER const type_kind_t StructType = EcsStructType; +FLECS_STATIC_IN_HEADER const type_kind_t ArrayType = EcsArrayType; +FLECS_STATIC_IN_HEADER const type_kind_t VectorType = EcsVectorType; +FLECS_STATIC_IN_HEADER const type_kind_t CustomType = EcsOpaqueType; +FLECS_STATIC_IN_HEADER const type_kind_t TypeKindLast = EcsTypeKindLast; /* Primitive type kinds supported by reflection system */ using primitive_kind_t = ecs_primitive_kind_t; -static const primitive_kind_t Bool = EcsBool; -static const primitive_kind_t Char = EcsChar; -static const primitive_kind_t Byte = EcsByte; -static const primitive_kind_t U8 = EcsU8; -static const primitive_kind_t U16 = EcsU16; -static const primitive_kind_t U32 = EcsU32; -static const primitive_kind_t U64 = EcsU64; -static const primitive_kind_t I8 = EcsI8; -static const primitive_kind_t I16 = EcsI16; -static const primitive_kind_t I32 = EcsI32; -static const primitive_kind_t I64 = EcsI64; -static const primitive_kind_t F32 = EcsF32; -static const primitive_kind_t F64 = EcsF64; -static const primitive_kind_t UPtr = EcsUPtr; -static const primitive_kind_t IPtr = EcsIPtr; -static const primitive_kind_t String = EcsString; -static const primitive_kind_t Entity = EcsEntity; -static const primitive_kind_t PrimitiveKindLast = EcsPrimitiveKindLast; +FLECS_STATIC_IN_HEADER const primitive_kind_t Bool = EcsBool; +FLECS_STATIC_IN_HEADER const primitive_kind_t Char = EcsChar; +FLECS_STATIC_IN_HEADER const primitive_kind_t Byte = EcsByte; +FLECS_STATIC_IN_HEADER const primitive_kind_t U8 = EcsU8; +FLECS_STATIC_IN_HEADER const primitive_kind_t U16 = EcsU16; +FLECS_STATIC_IN_HEADER const primitive_kind_t U32 = EcsU32; +FLECS_STATIC_IN_HEADER const primitive_kind_t U64 = EcsU64; +FLECS_STATIC_IN_HEADER const primitive_kind_t I8 = EcsI8; +FLECS_STATIC_IN_HEADER const primitive_kind_t I16 = EcsI16; +FLECS_STATIC_IN_HEADER const primitive_kind_t I32 = EcsI32; +FLECS_STATIC_IN_HEADER const primitive_kind_t I64 = EcsI64; +FLECS_STATIC_IN_HEADER const primitive_kind_t F32 = EcsF32; +FLECS_STATIC_IN_HEADER const primitive_kind_t F64 = EcsF64; +FLECS_STATIC_IN_HEADER const primitive_kind_t UPtr = EcsUPtr; +FLECS_STATIC_IN_HEADER const primitive_kind_t IPtr = EcsIPtr; +FLECS_STATIC_IN_HEADER const primitive_kind_t String = EcsString; +FLECS_STATIC_IN_HEADER const primitive_kind_t Entity = EcsEntity; +FLECS_STATIC_IN_HEADER const primitive_kind_t PrimitiveKindLast = EcsPrimitiveKindLast; /** @} */ +} // namespace meta +} // namespace flecs +namespace flecs { +namespace meta { namespace _ { void init(flecs::world& world); diff --git a/include/flecs/addons/cpp/mixins/meta/impl.hpp b/include/flecs/addons/cpp/mixins/meta/impl.hpp index e6f18a8431..8ab1f62204 100644 --- a/include/flecs/addons/cpp/mixins/meta/impl.hpp +++ b/include/flecs/addons/cpp/mixins/meta/impl.hpp @@ -148,6 +148,8 @@ inline flecs::entity world::vector() { } // namespace flecs +extern "C++" { + inline int ecs_serializer_t::value(ecs_entity_t type, const void *v) const { return this->value_(this, type, v); } @@ -161,3 +163,4 @@ inline int ecs_serializer_t::value(const T& v) const { inline int ecs_serializer_t::member(const char *name) const { return this->member_(this, name); } +} diff --git a/include/flecs/addons/cpp/mixins/meta/opaque.hpp b/include/flecs/addons/cpp/mixins/meta/opaque.hpp index d1f23803cf..d579554a99 100644 --- a/include/flecs/addons/cpp/mixins/meta/opaque.hpp +++ b/include/flecs/addons/cpp/mixins/meta/opaque.hpp @@ -7,7 +7,7 @@ #include -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_meta Meta @@ -24,10 +24,12 @@ using serializer = ecs_serializer_t; using serialize_t = ecs_meta_serialize_t; /** Type safe variant of serializer function */ + template using serialize = int(*)(const serializer *, const T*); /** Type safe interface for opaque types */ + template struct opaque { opaque(flecs::world_t *w = nullptr) : world(w) { diff --git a/include/flecs/addons/cpp/mixins/metrics/builder.hpp b/include/flecs/addons/cpp/mixins/metrics/builder.hpp index b8cc961b19..c4215194c3 100644 --- a/include/flecs/addons/cpp/mixins/metrics/builder.hpp +++ b/include/flecs/addons/cpp/mixins/metrics/builder.hpp @@ -7,7 +7,7 @@ #define ECS_EVENT_DESC_ID_COUNT_MAX (8) -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @ingroup cpp_addons_metrics diff --git a/include/flecs/addons/cpp/mixins/metrics/decl.hpp b/include/flecs/addons/cpp/mixins/metrics/decl.hpp index 0a394395c6..753370e27e 100644 --- a/include/flecs/addons/cpp/mixins/metrics/decl.hpp +++ b/include/flecs/addons/cpp/mixins/metrics/decl.hpp @@ -7,7 +7,7 @@ #include "builder.hpp" -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_metrics Metrics @@ -18,6 +18,7 @@ namespace flecs { * @{ */ + struct metrics { using Value = EcsMetricValue; using Source = EcsMetricSource; diff --git a/include/flecs/addons/cpp/mixins/metrics/impl.hpp b/include/flecs/addons/cpp/mixins/metrics/impl.hpp index e8b5b61320..9e271c6793 100644 --- a/include/flecs/addons/cpp/mixins/metrics/impl.hpp +++ b/include/flecs/addons/cpp/mixins/metrics/impl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { inline metrics::metrics(flecs::world& world) { world.import(); diff --git a/include/flecs/addons/cpp/mixins/module/impl.hpp b/include/flecs/addons/cpp/mixins/module/impl.hpp index 4954403879..8ff9182f3d 100644 --- a/include/flecs/addons/cpp/mixins/module/impl.hpp +++ b/include/flecs/addons/cpp/mixins/module/impl.hpp @@ -67,7 +67,11 @@ flecs::entity import(world& world) { return flecs::entity(world, m); } -} +} // namespace _ +} // namespace flecs + + +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_modules Modules diff --git a/include/flecs/addons/cpp/mixins/observer/builder.hpp b/include/flecs/addons/cpp/mixins/observer/builder.hpp index 74d1440de7..554f97ba83 100644 --- a/include/flecs/addons/cpp/mixins/observer/builder.hpp +++ b/include/flecs/addons/cpp/mixins/observer/builder.hpp @@ -12,12 +12,16 @@ namespace flecs { namespace _ { template using observer_builder_base = node_builder< - observer, ecs_observer_desc_t, observer_builder, + observer, ecs_observer_desc_t, observer_builder, observer_builder_i, Components ...>; -} + +} // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs { /** Observer builder. - * + * * @ingroup cpp_observers */ template @@ -29,4 +33,4 @@ struct observer_builder final : _::observer_builder_base { } }; -} +} // namespace flecs diff --git a/include/flecs/addons/cpp/mixins/observer/builder_i.hpp b/include/flecs/addons/cpp/mixins/observer/builder_i.hpp index 533d58ad87..63acc024c2 100644 --- a/include/flecs/addons/cpp/mixins/observer/builder_i.hpp +++ b/include/flecs/addons/cpp/mixins/observer/builder_i.hpp @@ -7,7 +7,7 @@ #include "../query/builder_i.hpp" -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** Observer builder interface. * diff --git a/include/flecs/addons/cpp/mixins/observer/decl.hpp b/include/flecs/addons/cpp/mixins/observer/decl.hpp index ebf3f20615..e4ee28d69b 100644 --- a/include/flecs/addons/cpp/mixins/observer/decl.hpp +++ b/include/flecs/addons/cpp/mixins/observer/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_observers Observers @@ -17,6 +17,7 @@ namespace flecs { struct observer; + template struct observer_builder; diff --git a/include/flecs/addons/cpp/mixins/observer/impl.hpp b/include/flecs/addons/cpp/mixins/observer/impl.hpp index 6b0e05d1bc..18b20d7892 100644 --- a/include/flecs/addons/cpp/mixins/observer/impl.hpp +++ b/include/flecs/addons/cpp/mixins/observer/impl.hpp @@ -7,7 +7,7 @@ #include "builder.hpp" -namespace flecs +FLECS_API_NAMESPACE namespace flecs { struct observer final : entity diff --git a/include/flecs/addons/cpp/mixins/pipeline/builder.hpp b/include/flecs/addons/cpp/mixins/pipeline/builder.hpp index 4e99fc00d4..dd0f2d6af6 100644 --- a/include/flecs/addons/cpp/mixins/pipeline/builder.hpp +++ b/include/flecs/addons/cpp/mixins/pipeline/builder.hpp @@ -12,12 +12,14 @@ namespace flecs { namespace _ { template using pipeline_builder_base = builder< - pipeline, ecs_pipeline_desc_t, pipeline_builder, + pipeline, ecs_pipeline_desc_t, pipeline_builder, pipeline_builder_i, Components ...>; -} +} // namespace _ +} // namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Pipeline builder. - * + * * @ingroup cpp_pipelines */ template @@ -30,4 +32,4 @@ struct pipeline_builder final : _::pipeline_builder_base { } }; -} +} // namespace flecs diff --git a/include/flecs/addons/cpp/mixins/pipeline/builder_i.hpp b/include/flecs/addons/cpp/mixins/pipeline/builder_i.hpp index e3349da136..236f1a6318 100644 --- a/include/flecs/addons/cpp/mixins/pipeline/builder_i.hpp +++ b/include/flecs/addons/cpp/mixins/pipeline/builder_i.hpp @@ -7,7 +7,7 @@ #include "../query/builder_i.hpp" -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** Pipeline builder interface. * diff --git a/include/flecs/addons/cpp/mixins/pipeline/decl.hpp b/include/flecs/addons/cpp/mixins/pipeline/decl.hpp index 0ea1f6f248..98cabbd21c 100644 --- a/include/flecs/addons/cpp/mixins/pipeline/decl.hpp +++ b/include/flecs/addons/cpp/mixins/pipeline/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_pipelines Pipelines @@ -22,17 +22,17 @@ template struct pipeline_builder; /* Builtin pipeline tags */ -static const flecs::entity_t OnStart = EcsOnStart; -static const flecs::entity_t PreFrame = EcsPreFrame; -static const flecs::entity_t OnLoad = EcsOnLoad; -static const flecs::entity_t PostLoad = EcsPostLoad; -static const flecs::entity_t PreUpdate = EcsPreUpdate; -static const flecs::entity_t OnUpdate = EcsOnUpdate; -static const flecs::entity_t OnValidate = EcsOnValidate; -static const flecs::entity_t PostUpdate = EcsPostUpdate; -static const flecs::entity_t PreStore = EcsPreStore; -static const flecs::entity_t OnStore = EcsOnStore; -static const flecs::entity_t PostFrame = EcsPostFrame; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnStart = EcsOnStart; +FLECS_STATIC_IN_HEADER const flecs::entity_t PreFrame = EcsPreFrame; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnLoad = EcsOnLoad; +FLECS_STATIC_IN_HEADER const flecs::entity_t PostLoad = EcsPostLoad; +FLECS_STATIC_IN_HEADER const flecs::entity_t PreUpdate = EcsPreUpdate; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnUpdate = EcsOnUpdate; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnValidate = EcsOnValidate; +FLECS_STATIC_IN_HEADER const flecs::entity_t PostUpdate = EcsPostUpdate; +FLECS_STATIC_IN_HEADER const flecs::entity_t PreStore = EcsPreStore; +FLECS_STATIC_IN_HEADER const flecs::entity_t OnStore = EcsOnStore; +FLECS_STATIC_IN_HEADER const flecs::entity_t PostFrame = EcsPostFrame; /** @} */ diff --git a/include/flecs/addons/cpp/mixins/pipeline/impl.hpp b/include/flecs/addons/cpp/mixins/pipeline/impl.hpp index e75b208803..6bc80182d2 100644 --- a/include/flecs/addons/cpp/mixins/pipeline/impl.hpp +++ b/include/flecs/addons/cpp/mixins/pipeline/impl.hpp @@ -7,7 +7,7 @@ #include "builder.hpp" -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template struct pipeline : entity { diff --git a/include/flecs/addons/cpp/mixins/query/builder.hpp b/include/flecs/addons/cpp/mixins/query/builder.hpp index 7cbd2cfa9b..6d6e3de266 100644 --- a/include/flecs/addons/cpp/mixins/query/builder.hpp +++ b/include/flecs/addons/cpp/mixins/query/builder.hpp @@ -12,12 +12,14 @@ namespace flecs { namespace _ { template using query_builder_base = builder< - query, ecs_query_desc_t, query_builder, + query, ecs_query_desc_t, query_builder, query_builder_i, Components ...>; -} +} // namespace _ +} // namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Query builder. - * + * * @ingroup cpp_core_queries */ template @@ -48,4 +50,4 @@ struct query_builder final : _::query_builder_base { } }; -} +} // namespace flecs diff --git a/include/flecs/addons/cpp/mixins/query/builder_i.hpp b/include/flecs/addons/cpp/mixins/query/builder_i.hpp index c5e7258e22..4f8aaddf4c 100644 --- a/include/flecs/addons/cpp/mixins/query/builder_i.hpp +++ b/include/flecs/addons/cpp/mixins/query/builder_i.hpp @@ -7,7 +7,7 @@ #include "../term/builder_i.hpp" -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Query builder interface. diff --git a/include/flecs/addons/cpp/mixins/query/decl.hpp b/include/flecs/addons/cpp/mixins/query/decl.hpp index a89e88a353..8d56d321eb 100644 --- a/include/flecs/addons/cpp/mixins/query/decl.hpp +++ b/include/flecs/addons/cpp/mixins/query/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_core_queries Queries @@ -16,9 +16,11 @@ namespace flecs { struct query_base; + template struct query; + template struct query_builder; diff --git a/include/flecs/addons/cpp/mixins/query/impl.hpp b/include/flecs/addons/cpp/mixins/query/impl.hpp index c0c874bc3d..653c3367a0 100644 --- a/include/flecs/addons/cpp/mixins/query/impl.hpp +++ b/include/flecs/addons/cpp/mixins/query/impl.hpp @@ -7,7 +7,7 @@ #include "builder.hpp" -namespace flecs +FLECS_API_NAMESPACE namespace flecs { struct query_base { @@ -237,8 +237,10 @@ template inline flecs::query_builder world::query_builder(Args &&... args) const { return flecs::query_builder(world_, FLECS_FWD(args)...); } +} // namespace flecs // world::each +namespace flecs { namespace _ { // Each with entity parameter @@ -285,7 +287,10 @@ struct query_delegate, flecs::entity>:: } }; -} +} // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs { template inline void world::each(Func&& func) const { diff --git a/include/flecs/addons/cpp/mixins/rest/decl.hpp b/include/flecs/addons/cpp/mixins/rest/decl.hpp index fac86b2de1..5c947c1cda 100644 --- a/include/flecs/addons/cpp/mixins/rest/decl.hpp +++ b/include/flecs/addons/cpp/mixins/rest/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_rest Rest @@ -15,17 +15,20 @@ namespace flecs { * @{ */ + using Rest = EcsRest; -namespace rest { +} // namespace flecs +namespace flecs { +namespace rest { namespace _ { void init(flecs::world& world); -} -} +} // namespace _ +} // namespace rest /** @} */ -} +} // namespace flecs diff --git a/include/flecs/addons/cpp/mixins/script/builder.hpp b/include/flecs/addons/cpp/mixins/script/builder.hpp index 1a244b7545..acd649d188 100644 --- a/include/flecs/addons/cpp/mixins/script/builder.hpp +++ b/include/flecs/addons/cpp/mixins/script/builder.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @ingroup cpp_addons_script @@ -13,6 +13,7 @@ namespace flecs { */ /** Script builder interface */ + struct script_builder { script_builder(flecs::world_t *world, const char *name = nullptr) : world_(world) diff --git a/include/flecs/addons/cpp/mixins/script/decl.hpp b/include/flecs/addons/cpp/mixins/script/decl.hpp index 21d789acfa..ced9eaf39b 100644 --- a/include/flecs/addons/cpp/mixins/script/decl.hpp +++ b/include/flecs/addons/cpp/mixins/script/decl.hpp @@ -7,7 +7,7 @@ #include "builder.hpp" -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_script Script diff --git a/include/flecs/addons/cpp/mixins/script/impl.hpp b/include/flecs/addons/cpp/mixins/script/impl.hpp index 6c98076b40..0568c23d55 100644 --- a/include/flecs/addons/cpp/mixins/script/impl.hpp +++ b/include/flecs/addons/cpp/mixins/script/impl.hpp @@ -7,7 +7,7 @@ #include "builder.hpp" -namespace flecs +FLECS_API_NAMESPACE namespace flecs { inline flecs::entity script_builder::run() const { diff --git a/include/flecs/addons/cpp/mixins/stats/decl.hpp b/include/flecs/addons/cpp/mixins/stats/decl.hpp index 2435aa3a64..2d5ca7e91b 100644 --- a/include/flecs/addons/cpp/mixins/stats/decl.hpp +++ b/include/flecs/addons/cpp/mixins/stats/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_stats Stats @@ -16,14 +16,18 @@ namespace flecs { */ /** Component that stores world statistics */ + using WorldStats = EcsWorldStats; /** Component that stores system/pipeline statistics */ + using PipelineStats = EcsPipelineStats; /** Component with world summary stats */ + using WorldSummary = EcsWorldSummary; + struct stats { stats(flecs::world& world); }; diff --git a/include/flecs/addons/cpp/mixins/stats/impl.hpp b/include/flecs/addons/cpp/mixins/stats/impl.hpp index 8b7da3a7db..3d3396c41d 100644 --- a/include/flecs/addons/cpp/mixins/stats/impl.hpp +++ b/include/flecs/addons/cpp/mixins/stats/impl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { inline stats::stats(flecs::world& world) { #ifdef FLECS_UNITS diff --git a/include/flecs/addons/cpp/mixins/system/builder.hpp b/include/flecs/addons/cpp/mixins/system/builder.hpp index e819cadb7a..b9cc942e3f 100644 --- a/include/flecs/addons/cpp/mixins/system/builder.hpp +++ b/include/flecs/addons/cpp/mixins/system/builder.hpp @@ -12,12 +12,14 @@ namespace flecs { namespace _ { template using system_builder_base = node_builder< - system, ecs_system_desc_t, system_builder, + system, ecs_system_desc_t, system_builder, system_builder_i, Components ...>; -} +} // namespace _ +} // namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** System builder. - * + * * @ingroup cpp_addons_systems */ template @@ -34,4 +36,4 @@ struct system_builder final : _::system_builder_base { } }; -} +} // namespace flecs diff --git a/include/flecs/addons/cpp/mixins/system/builder_i.hpp b/include/flecs/addons/cpp/mixins/system/builder_i.hpp index 58634cc057..bdc00979e4 100644 --- a/include/flecs/addons/cpp/mixins/system/builder_i.hpp +++ b/include/flecs/addons/cpp/mixins/system/builder_i.hpp @@ -7,7 +7,7 @@ #include "../query/builder_i.hpp" -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** System builder interface. diff --git a/include/flecs/addons/cpp/mixins/system/decl.hpp b/include/flecs/addons/cpp/mixins/system/decl.hpp index d8203c6879..1651fec87b 100644 --- a/include/flecs/addons/cpp/mixins/system/decl.hpp +++ b/include/flecs/addons/cpp/mixins/system/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_systems Systems @@ -15,13 +15,18 @@ namespace flecs { * @{ */ + using TickSource = EcsTickSource; struct system; + template struct system_builder; +} // namespace flecs + +namespace flecs { namespace _ { void system_init(flecs::world& world); diff --git a/include/flecs/addons/cpp/mixins/system/impl.hpp b/include/flecs/addons/cpp/mixins/system/impl.hpp index 26d6c1f044..32206ea799 100644 --- a/include/flecs/addons/cpp/mixins/system/impl.hpp +++ b/include/flecs/addons/cpp/mixins/system/impl.hpp @@ -7,7 +7,7 @@ #include "builder.hpp" -namespace flecs +FLECS_API_NAMESPACE namespace flecs { struct system_runner_fluent { @@ -120,6 +120,9 @@ inline system_builder world::system(Args &&... args) const { return flecs::system_builder(world_, FLECS_FWD(args)...); } +} // namespace flecs + +namespace flecs { namespace _ { inline void system_init(flecs::world& world) { diff --git a/include/flecs/addons/cpp/mixins/term/builder_i.hpp b/include/flecs/addons/cpp/mixins/term/builder_i.hpp index be8a333fd3..465d0b6327 100644 --- a/include/flecs/addons/cpp/mixins/term/builder_i.hpp +++ b/include/flecs/addons/cpp/mixins/term/builder_i.hpp @@ -7,7 +7,7 @@ #include "../../utils/signature.hpp" -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** Term identifier builder. diff --git a/include/flecs/addons/cpp/mixins/term/decl.hpp b/include/flecs/addons/cpp/mixins/term/decl.hpp index b5a1bdbd54..83731920a2 100644 --- a/include/flecs/addons/cpp/mixins/term/decl.hpp +++ b/include/flecs/addons/cpp/mixins/term/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @ingroup cpp_core_queries diff --git a/include/flecs/addons/cpp/mixins/term/impl.hpp b/include/flecs/addons/cpp/mixins/term/impl.hpp index 347fb6f389..db8888f610 100644 --- a/include/flecs/addons/cpp/mixins/term/impl.hpp +++ b/include/flecs/addons/cpp/mixins/term/impl.hpp @@ -7,7 +7,7 @@ #include "builder_i.hpp" -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** Class that describes a term. * diff --git a/include/flecs/addons/cpp/mixins/timer/decl.hpp b/include/flecs/addons/cpp/mixins/timer/decl.hpp index ccdf879901..f434a5e0c4 100644 --- a/include/flecs/addons/cpp/mixins/timer/decl.hpp +++ b/include/flecs/addons/cpp/mixins/timer/decl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_addons_timer Timer @@ -21,7 +21,9 @@ using RateFilter = EcsRateFilter; struct timer; /** @} */ +} // namespace flecs +namespace flecs { namespace _ { void timer_init(flecs::world& world); diff --git a/include/flecs/addons/cpp/mixins/timer/impl.hpp b/include/flecs/addons/cpp/mixins/timer/impl.hpp index e26c19db85..8cd76258c8 100644 --- a/include/flecs/addons/cpp/mixins/timer/impl.hpp +++ b/include/flecs/addons/cpp/mixins/timer/impl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { // Timer class struct timer final : entity { @@ -94,6 +94,9 @@ inline void system::set_tick_source(flecs::entity e) { ecs_set_tick_source(world_, id_, e); } +} // namespace flecs + +namespace flecs { namespace _ { inline void timer_init(flecs::world& world) { @@ -101,5 +104,5 @@ inline void timer_init(flecs::world& world) { world.component("flecs::timer::Timer"); } -} -} +} // namespace _ +} // namespace flecs diff --git a/include/flecs/addons/cpp/mixins/units/decl.hpp b/include/flecs/addons/cpp/mixins/units/decl.hpp index 05592bcfd5..d96db1ae46 100644 --- a/include/flecs/addons/cpp/mixins/units/decl.hpp +++ b/include/flecs/addons/cpp/mixins/units/decl.hpp @@ -5,7 +5,9 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { + + struct units { /** diff --git a/include/flecs/addons/cpp/mixins/units/impl.hpp b/include/flecs/addons/cpp/mixins/units/impl.hpp index 596e8b781f..1f23f93c6e 100644 --- a/include/flecs/addons/cpp/mixins/units/impl.hpp +++ b/include/flecs/addons/cpp/mixins/units/impl.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { inline units::units(flecs::world& world) { /* Import C module */ diff --git a/include/flecs/addons/cpp/pair.hpp b/include/flecs/addons/cpp/pair.hpp index 67259c8e82..3e544fc0b9 100644 --- a/include/flecs/addons/cpp/pair.hpp +++ b/include/flecs/addons/cpp/pair.hpp @@ -9,9 +9,12 @@ namespace flecs { namespace _ { struct pair_base { }; -} // _ +} // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_pair_type Pair type * @ingroup cpp_core @@ -140,4 +143,4 @@ struct is_actual { std::is_same >::value && !is_enum::value; }; -} // flecs +} // namespace flecs diff --git a/include/flecs/addons/cpp/ref.hpp b/include/flecs/addons/cpp/ref.hpp index 00eddf7d13..8243133b1e 100644 --- a/include/flecs/addons/cpp/ref.hpp +++ b/include/flecs/addons/cpp/ref.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /** diff --git a/include/flecs/addons/cpp/table.hpp b/include/flecs/addons/cpp/table.hpp index 0b3d81c0a5..44134b0b6c 100644 --- a/include/flecs/addons/cpp/table.hpp +++ b/include/flecs/addons/cpp/table.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_tables Tables diff --git a/include/flecs/addons/cpp/type.hpp b/include/flecs/addons/cpp/type.hpp index 8a903fc4cb..746ef08e3a 100644 --- a/include/flecs/addons/cpp/type.hpp +++ b/include/flecs/addons/cpp/type.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { /** * @defgroup cpp_types Types diff --git a/include/flecs/addons/cpp/utils/array.hpp b/include/flecs/addons/cpp/utils/array.hpp index b90579788d..ba6ed841f4 100644 --- a/include/flecs/addons/cpp/utils/array.hpp +++ b/include/flecs/addons/cpp/utils/array.hpp @@ -6,7 +6,7 @@ * template code where template expansion would lead to an array with size 0. */ -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template struct array_iterator diff --git a/include/flecs/addons/cpp/utils/enum.hpp b/include/flecs/addons/cpp/utils/enum.hpp index 7399646518..a800dd09c3 100644 --- a/include/flecs/addons/cpp/utils/enum.hpp +++ b/include/flecs/addons/cpp/utils/enum.hpp @@ -6,8 +6,10 @@ * and their names. This is used to automatically register enum constants. */ +#ifndef FLECS_NO_STD_INCLUDE #include #include +#endif #define FLECS_ENUM_MAX(T) _::to_constant::value #define FLECS_ENUM_MAX_COUNT (FLECS_ENUM_MAX(int) + 1) @@ -44,14 +46,17 @@ struct to_constant { template Value> constexpr E to_constant::value; -} +} // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs { /** Convenience type with enum reflection data */ template struct enum_data; template -static enum_data enum_type(flecs::world_t *world); +FLECS_STATIC_IN_HEADER enum_data enum_type(flecs::world_t *world); template struct enum_last { @@ -60,12 +65,15 @@ struct enum_last { /* Utility macro to override enum_last trait */ #define FLECS_ENUM_LAST(T, Last)\ - namespace flecs {\ + FLECS_API_NAMESPACE namespace flecs {\ template<>\ struct enum_last {\ static constexpr T value = Last;\ };\ } +} // namespace flecs + +namespace flecs { namespace _ { @@ -381,15 +389,20 @@ struct enum_type { template enum_data_impl enum_type::data; +FLECS_API_DEPENDENCY template ::value > = 0> -inline static void init_enum(flecs::world_t *world, flecs::entity_t id) { +inline FLECS_STATIC_IN_HEADER void init_enum(flecs::world_t *world, flecs::entity_t id) { _::enum_type::get().init(world, id); } +FLECS_API_DEPENDENCY template ::value > = 0> -inline static void init_enum(flecs::world_t*, flecs::entity_t) { } +inline FLECS_STATIC_IN_HEADER void init_enum(flecs::world_t*, flecs::entity_t) { } } // namespace _ +} // namespace flecs + +FLECS_API_NAMESPACE namespace flecs { /** Enumeration type data wrapper with world pointer */ template diff --git a/include/flecs/addons/cpp/utils/function_traits.hpp b/include/flecs/addons/cpp/utils/function_traits.hpp index 0a922ad787..755f215dea 100644 --- a/include/flecs/addons/cpp/utils/function_traits.hpp +++ b/include/flecs/addons/cpp/utils/function_traits.hpp @@ -93,8 +93,10 @@ template struct function_traits : function_traits_no_cv< decay_t > {}; -} // _ +} // namespace _ +} // namespace flecs +FLECS_API_NAMESPACE namespace flecs { template struct is_callable { diff --git a/include/flecs/addons/cpp/utils/iterable.hpp b/include/flecs/addons/cpp/utils/iterable.hpp index 8f202875cc..d792861e3d 100644 --- a/include/flecs/addons/cpp/utils/iterable.hpp +++ b/include/flecs/addons/cpp/utils/iterable.hpp @@ -3,7 +3,7 @@ * @brief Base class for iterable objects, like queries. */ -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { template struct iter_iterable; diff --git a/include/flecs/addons/cpp/utils/string.hpp b/include/flecs/addons/cpp/utils/string.hpp index 41c8a5d9ea..ce2b27f7b7 100644 --- a/include/flecs/addons/cpp/utils/string.hpp +++ b/include/flecs/addons/cpp/utils/string.hpp @@ -3,7 +3,7 @@ * @brief String utility that doesn't implicitly allocate memory. */ -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { struct string_view; diff --git a/include/flecs/addons/cpp/utils/stringstream.hpp b/include/flecs/addons/cpp/utils/stringstream.hpp index 964d516989..d2a219570c 100644 --- a/include/flecs/addons/cpp/utils/stringstream.hpp +++ b/include/flecs/addons/cpp/utils/stringstream.hpp @@ -3,7 +3,7 @@ * @brief Wrapper around ecs_strbuf_t that provides a simple stringstream like API. */ -namespace flecs { +FLECS_API_NAMESPACE namespace flecs { struct stringstream { explicit stringstream() diff --git a/include/flecs/addons/cpp/utils/utils.hpp b/include/flecs/addons/cpp/utils/utils.hpp index 5c48534f5f..af99962b04 100644 --- a/include/flecs/addons/cpp/utils/utils.hpp +++ b/include/flecs/addons/cpp/utils/utils.hpp @@ -62,10 +62,10 @@ template inline void free_obj(Ty* _ptr) { #define flecs_static_assert(cond, str) static_assert(cond, str) #endif -inline void* operator new(size_t, flecs::_::placement_new_tag_t, void* _ptr) noexcept { return _ptr; } -inline void operator delete(void*, flecs::_::placement_new_tag_t, void*) noexcept { } +FLECS_API_DEPENDENCY inline void* operator new(size_t, flecs::_::placement_new_tag_t, void* _ptr) noexcept { return _ptr; } +FLECS_API_DEPENDENCY inline void operator delete(void*, flecs::_::placement_new_tag_t, void*) noexcept { } -namespace flecs +FLECS_API_NAMESPACE namespace flecs { // C++11/C++14 convenience template replacements @@ -132,6 +132,9 @@ using if_t = enable_if_t; template using if_not_t = enable_if_t; +} // namespace flecs + +namespace flecs { namespace _ { @@ -146,7 +149,9 @@ struct always_false { } // namespace flecs +#ifndef FLECS_NO_STD_INCLUDE #include +#endif #include "array.hpp" #include "string.hpp" #include "enum.hpp" diff --git a/include/flecs/addons/cpp/world.hpp b/include/flecs/addons/cpp/world.hpp index 6f076d740f..c065530be7 100644 --- a/include/flecs/addons/cpp/world.hpp +++ b/include/flecs/addons/cpp/world.hpp @@ -5,7 +5,7 @@ #pragma once -namespace flecs +FLECS_API_NAMESPACE namespace flecs { /* Static helper functions to assign a component value */ diff --git a/include/flecs/private/addons.h b/include/flecs/private/addons.h index 6f2775bef6..7e9689d9d5 100644 --- a/include/flecs/private/addons.h +++ b/include/flecs/private/addons.h @@ -200,12 +200,17 @@ #ifdef FLECS_NO_CPP #error "FLECS_NO_CPP failed: CPP is required by other addons" #endif + #include "../addons/flecs_cpp.h" +#ifndef FLECS_CPP20_MODULE_HEADER + #ifdef __cplusplus #include "../addons/cpp/flecs.hpp" #endif // __cplusplus +#endif // !FLECS_CPP20_MODULE_HEADER + #endif // FLECS_CPP #endif diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt new file mode 100644 index 0000000000..0c72336200 --- /dev/null +++ b/module/CMakeLists.txt @@ -0,0 +1,10 @@ +add_library(flecs-module) + +target_sources(flecs-module PUBLIC + FILE_SET CXX_MODULES + BASE_DIRS ${PROJECT_SOURCE_DIR}/module + FILES flecs-module.cpp +) + +target_compile_features(flecs-module PUBLIC cxx_std_20) +target_link_libraries(flecs-module PRIVATE flecs) diff --git a/module/flecs-module.cpp b/module/flecs-module.cpp new file mode 100644 index 0000000000..248863182d --- /dev/null +++ b/module/flecs-module.cpp @@ -0,0 +1,33 @@ +module; + +// Include flecs, but do not include c++ api, while still including things which need to be available for the c++ api to compile +#define FLECS_CPP20_MODULE_HEADER +#include "flecs.h" +#undef FLECS_CPP20_MODULE_HEADER + +// Manually include needed std headers +#include +#include +#include +#include +#include +#include +#include + +export module flecs; + +// Disable std includes +#define FLECS_NO_STD_INCLUDE + +// Include all symbols tagged with FLECS_API +#undef FLECS_API +#define FLECS_API export + +// Namespaces must be marked with export to be included in the module +#define FLECS_API_NAMESPACE export +// Definitions that need to be visible, but aren't actually part of the API +#define FLECS_API_DEPENDENCY export +// Disable static declarations in some places +#define FLECS_STATIC_IN_HEADER + +#include "flecs/addons/cpp/flecs.hpp"