diff --git a/ecsact/runtime/common.h b/ecsact/runtime/common.h index 7c323df9..c9fe0af2 100644 --- a/ecsact/runtime/common.h +++ b/ecsact/runtime/common.h @@ -74,10 +74,27 @@ ECSACT_ALWAYS_INLINE To ecsact_id_cast(From) { ); } +template +constexpr auto ecsact_id_castable() -> bool { + return false; +} + # define ECSACT_CAST_ID_FN(From, To) \ template<> \ ECSACT_ALWAYS_INLINE To ecsact_id_cast(From id) { \ return (To)id; \ + } \ + template<> \ + constexpr auto ecsact_id_castable() -> bool { \ + return true; \ + } + +# define ECSACT_COMPARE_ID_FN(From, To) \ + ECSACT_ALWAYS_INLINE bool operator==(const From& a, const To& b) { \ + return ecsact_id_cast(a) == b; \ + } \ + ECSACT_ALWAYS_INLINE bool operator!=(const From& a, const To& b) { \ + return ecsact_id_cast(a) != b; \ } #else ECSACT_ALWAYS_INLINE int32_t ecsact_id_cast(int32_t id) { @@ -85,6 +102,7 @@ ECSACT_ALWAYS_INLINE int32_t ecsact_id_cast(int32_t id) { } # define ECSACT_CAST_ID_FN(From, To) +# define ECSACT_COMPARE_ID_FN(From, To) #endif ECSACT_CAST_ID_FN(ecsact_system_id, ecsact_system_like_id) @@ -122,8 +140,28 @@ ECSACT_CAST_ID_FN(ecsact_system_like_id, ecsact_system_like_id) ECSACT_CAST_ID_FN(ecsact_transient_id, ecsact_transient_id) ECSACT_CAST_ID_FN(ecsact_component_like_id, ecsact_component_like_id) +ECSACT_COMPARE_ID_FN(ecsact_system_id, ecsact_system_like_id) +ECSACT_COMPARE_ID_FN(ecsact_action_id, ecsact_system_like_id) +ECSACT_COMPARE_ID_FN(ecsact_action_id, ecsact_composite_id) +ECSACT_COMPARE_ID_FN(ecsact_component_id, ecsact_composite_id) +ECSACT_COMPARE_ID_FN(ecsact_transient_id, ecsact_composite_id) +ECSACT_COMPARE_ID_FN(ecsact_component_like_id, ecsact_composite_id) + +ECSACT_COMPARE_ID_FN(ecsact_component_id, ecsact_decl_id) +ECSACT_COMPARE_ID_FN(ecsact_transient_id, ecsact_decl_id) +ECSACT_COMPARE_ID_FN(ecsact_system_id, ecsact_decl_id) +ECSACT_COMPARE_ID_FN(ecsact_action_id, ecsact_decl_id) +ECSACT_COMPARE_ID_FN(ecsact_variant_id, ecsact_decl_id) +ECSACT_COMPARE_ID_FN(ecsact_system_like_id, ecsact_decl_id) +ECSACT_COMPARE_ID_FN(ecsact_composite_id, ecsact_decl_id) +ECSACT_COMPARE_ID_FN(ecsact_component_like_id, ecsact_decl_id) + +ECSACT_COMPARE_ID_FN(ecsact_component_id, ecsact_component_like_id) +ECSACT_COMPARE_ID_FN(ecsact_transient_id, ecsact_component_like_id) + #undef ECSACT_TYPED_ID #undef ECSACT_CAST_ID_FN +#undef ECSACT_COMPARE_ID_FN #if defined(_WIN32) && (!defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL) # define ECSACT_MSVC_TRADITIONAL diff --git a/ecsact/runtime/dynamic.h b/ecsact/runtime/dynamic.h index 7a8431bc..4e2e5592 100644 --- a/ecsact/runtime/dynamic.h +++ b/ecsact/runtime/dynamic.h @@ -404,10 +404,11 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_remove_system_assoc_field) ecsact_field_id ); -ECSACT_DYNAMIC_API_FN(void, ecsact_set_system_assoc_capbility) +ECSACT_DYNAMIC_API_FN(void, ecsact_set_system_assoc_capability) ( // ecsact_system_like_id, ecsact_system_assoc_id, + ecsact_component_like_id, ecsact_system_capability ); @@ -543,7 +544,7 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_set_system_notify_component_setting) fn(ecsact_remove_system_assoc, __VA_ARGS__); \ fn(ecsact_add_system_assoc_field, __VA_ARGS__); \ fn(ecsact_remove_system_assoc_field, __VA_ARGS__); \ - fn(ecsact_set_system_assoc_capbility, __VA_ARGS__); \ + fn(ecsact_set_system_assoc_capability, __VA_ARGS__); \ fn(ecsact_set_system_association_capability, __VA_ARGS__); \ fn(ecsact_unset_system_association_capability, __VA_ARGS__); \ fn(ecsact_add_system_generates, __VA_ARGS__); \ diff --git a/ecsact/runtime/meta.hh b/ecsact/runtime/meta.hh index fa8cd2bb..f9050d26 100644 --- a/ecsact/runtime/meta.hh +++ b/ecsact/runtime/meta.hh @@ -5,6 +5,7 @@ #include #include #include +#include "ecsact/runtime/common.h" #include "ecsact/runtime/meta.h" namespace ecsact::meta { @@ -179,6 +180,17 @@ ECSACT_ALWAYS_INLINE std::vector get_field_ids( return field_ids; } +template +ECSACT_ALWAYS_INLINE auto get_field_type( + CompositeID id, + ecsact_field_id field_id +) -> ecsact_field_type { + return ecsact_meta_field_type( + ecsact_id_cast(id), + field_id + ); +} + ECSACT_ALWAYS_INLINE std::vector get_system_ids( ecsact_package_id package_id ) { @@ -484,56 +496,74 @@ ECSACT_ALWAYS_INLINE auto get_system_generates_components( return result; } -template -ECSACT_ALWAYS_INLINE auto system_association_fields( - SystemLikeID system_id, - ComponentLikeID component_id -) { - auto sys_like_id = ecsact_id_cast(system_id); - auto comp_like_id = ecsact_id_cast(component_id); - - std::vector field_ids; - field_ids.resize( - ecsact_meta_system_association_fields_count(sys_like_id, comp_like_id) +template +ECSACT_ALWAYS_INLINE auto system_assoc_ids( // + SystemLikeID system_id +) -> std::vector { + auto result = std::vector{}; + result.resize(32); + auto assoc_count = int32_t{}; + + ecsact_meta_system_assoc_ids( + ecsact_id_cast(system_id), + static_cast(result.size()), + result.data(), + &assoc_count ); - ecsact_meta_system_association_fields( - sys_like_id, - comp_like_id, - static_cast(field_ids.size()), - field_ids.data(), - nullptr + result.resize(assoc_count); + + return result; +} + +template +ECSACT_ALWAYS_INLINE auto system_assoc_component_id( // + SystemLikeID system_id, + ecsact_system_assoc_id assoc_id +) -> ecsact_component_like_id { + return ecsact_meta_system_assoc_component_id( + ecsact_id_cast(system_id), + assoc_id ); +} - return field_ids; +template +ECSACT_ALWAYS_INLINE auto system_assoc_fields( + SystemLikeID system_id, + ecsact_system_assoc_id assoc_id +) -> std::vector { + auto result = std::vector{}; + result.resize(32); + auto fields_count = int32_t{}; + ecsact_meta_system_assoc_fields( + system_id, + assoc_id, + result.size(), + result.data(), + &fields_count + ); + result.resize(fields_count); + return result; } -template -ECSACT_ALWAYS_INLINE auto system_association_capabilities( - SystemLikeID system_id, - ComponentLikeID component_id, - ecsact_field_id field_id +template +ECSACT_ALWAYS_INLINE auto system_assoc_capabilities( + SystemLikeID id, + ecsact_system_assoc_id assoc_id ) { using result_t = - std::unordered_map; - - auto sys_like_id = ecsact_id_cast(system_id); - auto comp_like_id = ecsact_id_cast(component_id); + std::vector>; - auto count = ecsact_meta_system_association_capabilities_count( - sys_like_id, - comp_like_id, - field_id - ); + const auto sys_like_id = ecsact_id_cast(id); + auto count = ecsact_meta_system_capabilities_count(sys_like_id); std::vector components; std::vector capabilities; components.resize(count); capabilities.resize(count); - ecsact_meta_system_association_capabilities( + ecsact_meta_system_assoc_capabilities( sys_like_id, - comp_like_id, - field_id, + assoc_id, count, components.data(), capabilities.data(), @@ -541,10 +571,10 @@ ECSACT_ALWAYS_INLINE auto system_association_capabilities( ); result_t result; - result.reserve(count); + result.resize(count); for(decltype(count) i = 0; count > i; ++i) { - result[components[i]] = capabilities[i]; + result[i] = {components[i], capabilities[i]}; } return result; @@ -592,6 +622,17 @@ auto system_notify_settings( // return result; } +template +ECSACT_ALWAYS_INLINE auto field_name( // + CompositeID id, + ecsact_field_id field_id +) -> std::string { + return ecsact_meta_field_name( + ecsact_id_cast(id), + field_id + ); +} + ECSACT_ALWAYS_INLINE auto main_package() -> std::optional { auto main_pkg_id = ecsact_meta_main_package(); if(main_pkg_id == static_cast(-1)) {