From 57e2b9f277c895924ac509e44d674b5bad660ffd Mon Sep 17 00:00:00 2001 From: Ezekiel Warren Date: Mon, 14 Oct 2024 12:43:55 -0700 Subject: [PATCH] feat: remove use of variadic arguments in api due to wasm limitation --- ecsact/runtime/async.h | 7 ++-- ecsact/runtime/core.h | 38 +++++++++++------- ecsact/runtime/core.hh | 85 ++++++++++++++++++++++++++++------------ ecsact/runtime/dynamic.h | 36 ++++++++++------- 4 files changed, 108 insertions(+), 58 deletions(-) diff --git a/ecsact/runtime/async.h b/ecsact/runtime/async.h index 9dc72452..9437b94e 100644 --- a/ecsact/runtime/async.h +++ b/ecsact/runtime/async.h @@ -209,15 +209,16 @@ ECSACT_ASYNC_API_FN(int32_t, ecsact_async_get_current_tick)(void); * Sends Ecsact stream data to the specified registry. Stream data will be * applied on the next ecsact_execute_systems call. * - * @param ... if the component has indexed fields then those fields must be - * supplied to the variadic arguments in declaration order. + * @param indexed_field_values if the component has indexed fields then those + * fields must be supplied as a sequential array in declaration order, + * otherwise may be NULL. */ ECSACT_CORE_API_FN(ecsact_async_request_id, ecsact_async_stream) ( // ecsact_entity_id entity, ecsact_component_id component_id, const void* component_data, - ... + const void* indexed_field_values ); #define FOR_EACH_ECSACT_ASYNC_API_FN(fn, ...) \ diff --git a/ecsact/runtime/core.h b/ecsact/runtime/core.h index af4a05d1..c392b4c7 100644 --- a/ecsact/runtime/core.h +++ b/ecsact/runtime/core.h @@ -135,21 +135,26 @@ ECSACT_CORE_API_FN(ecsact_add_error, ecsact_add_component) /** * Checks if a given entity has component with id @p component_id - * @param ... if the component has indexed fields then those fields must be - * supplied to the variadic arguments in declaration order. + * + * @param indexed_field_values if the component has indexed fields then those + * fields must be supplied as a sequential array in declaration order, + * otherwise may be NULL. */ ECSACT_CORE_API_FN(bool, ecsact_has_component) ( // ecsact_registry_id registry_id, ecsact_entity_id entity_id, ecsact_component_id component_id, - ... + const void* indexed_field_values ); /** - * @param ... if the component has indexed fields then those fields must be - * supplied to the variadic arguments in declaration order. + * @param indexed_field_values if the component has indexed fields then those + * fields must be supplied as a sequential array in declaration order, + * otherwise may be NULL. + * * @returns non-owning pointer of the component data + * * NOTE: This method should be avoided if possible. */ ECSACT_CORE_API_FN(const void*, ecsact_get_component) @@ -157,7 +162,7 @@ ECSACT_CORE_API_FN(const void*, ecsact_get_component) ecsact_registry_id registry_id, ecsact_entity_id entity_id, ecsact_component_id component_id, - ... + const void* indexed_field_values ); /** @@ -199,8 +204,9 @@ ECSACT_CORE_API_FN(void, ecsact_each_component) /** * Update a component for the specified entity. * - * @param ... if the component has indexed fields then those fields must be - * supplied to the variadic arguments in declaration order. + * @param indexed_field_values if the component has indexed fields then those + * fields must be supplied as a sequential array in declaration order, + * otherwise may be NULL. * * NOTE: This method should be avoided if possible. Updating a component in a * system or system execution options is preferred. @@ -212,14 +218,15 @@ ECSACT_CORE_API_FN(ecsact_update_error, ecsact_update_component) ecsact_entity_id entity_id, ecsact_component_id component_id, const void* component_data, - ... + const void* indexed_field_values ); /** * Removes a component from the specified entity. * - * @param ... if the component has indexed fields then those fields must be - * supplied to the variadic arguments in declaration order. + * @param indexed_field_values if the component has indexed fields then those + * fields must be supplied as a sequential array in declaration order, + * otherwise may be NULL. * * NOTE: This method should be avoided if possible. Removing a component in a * system or system execution options is preferred. @@ -230,7 +237,7 @@ ECSACT_CORE_API_FN(void, ecsact_remove_component) ecsact_registry_id registry_id, ecsact_entity_id entity_id, ecsact_component_id component_id, - ... + const void* indexed_field_values ); /** @@ -269,8 +276,9 @@ ECSACT_CORE_API_FN(ecsact_ees, ecsact_get_entity_execution_status) * applied on the next ecsact_execute_systems call. The last set of stream data * is always used. * - * @param ... if the component has indexed fields then those fields must be - * supplied to the variadic arguments in declaration order. + * @param indexed_field_values if the component has indexed fields then those + * fields must be supplied as a sequential array in declaration order, + * otherwise may be NULL. */ ECSACT_CORE_API_FN(ecsact_stream_error, ecsact_stream) ( // @@ -278,7 +286,7 @@ ECSACT_CORE_API_FN(ecsact_stream_error, ecsact_stream) ecsact_entity_id entity, ecsact_component_id component_id, const void* component_data, - ... + const void* indexed_field_values ); // # BEGIN FOR_EACH_ECSACT_CORE_API_FN diff --git a/ecsact/runtime/core.hh b/ecsact/runtime/core.hh index 01f8104a..b427303e 100644 --- a/ecsact/runtime/core.hh +++ b/ecsact/runtime/core.hh @@ -648,12 +648,19 @@ public: ); } - return *reinterpret_cast(ecsact_get_component( - _id, - entity_id, - Component::id, - std::forward(assoc_fields)... - )); + if constexpr(sizeof...(AssocFields) > 0) { + const void* assoc_field_values[sizeof...(AssocFields)] = { + &assoc_fields..., + }; + + return *reinterpret_cast( + ecsact_get_component(_id, entity_id, Component::id, assoc_field_values) + ); + } else { + return *reinterpret_cast( + ecsact_get_component(_id, entity_id, Component::id, nullptr) + ); + } } template @@ -668,12 +675,19 @@ public: ); } - return ecsact_has_component( - _id, - entity_id, - Component::id, - std::forward(assoc_fields)... - ); + if constexpr(sizeof...(AssocFields) > 0) { + const void* assoc_field_values[sizeof...(AssocFields)] = { + &assoc_fields..., + }; + return ecsact_has_component( + _id, + entity_id, + Component::id, + assoc_field_values + ); + } else { + return ecsact_has_component(_id, entity_id, Component::id, nullptr); + } } template @@ -707,13 +721,26 @@ public: ); } - return ecsact_update_component( - _id, - entity_id, - Component::id, - &component, - std::forward(assoc_fields)... - ); + if constexpr(sizeof...(AssocFields) > 0) { + const void* assoc_field_values[sizeof...(AssocFields)] = { + &assoc_fields..., + }; + return ecsact_update_component( + _id, + entity_id, + Component::id, + &component, + assoc_field_values + ); + } else { + return ecsact_update_component( + _id, + entity_id, + Component::id, + &component, + nullptr + ); + } } template @@ -728,12 +755,20 @@ public: ); } - return ecsact_remove_component( - _id, - entity_id, - Component::id, - std::forward(assoc_fields)... - ); + if constexpr(sizeof...(AssocFields) > 0) { + const void* assoc_field_values[sizeof...(AssocFields)] = { + &assoc_fields..., + }; + + return ecsact_remove_component( + _id, + entity_id, + Component::id, + assoc_field_values + ); + } else { + return ecsact_remove_component(_id, entity_id, Component::id, nullptr); + } } ECSACT_ALWAYS_INLINE auto count_entities() const -> int32_t { diff --git a/ecsact/runtime/dynamic.h b/ecsact/runtime/dynamic.h index a3aabae9..0cd0bd26 100644 --- a/ecsact/runtime/dynamic.h +++ b/ecsact/runtime/dynamic.h @@ -64,14 +64,15 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_add) * Only available if has one of these capabilities: * - `ECSACT_SYS_CAP_REMOVES` * - * @param ... if the component has indexed fields then those fields must be - * supplied to the variadic arguments in declaration order. + * @param indexed_field_values if the component has indexed fields then those + * fields must be supplied as a sequential array in declaration order, + * otherwise may be NULL. */ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_remove) ( // struct ecsact_system_execution_context* context, ecsact_component_like_id component_id, - ... + const void* indexed_field_values ); /** @@ -87,15 +88,16 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_remove) * - `ECSACT_SYS_CAP_OPTIONAL_READONLY` * - `ECSACT_SYS_CAP_OPTIONAL_READWRITE` * - * @param ... if the component has indexed fields then those fields must be - * supplied to the variadic arguments in declaration order. + * @param indexed_field_values if the component has indexed fields then those + * fields must be supplied as a sequential array in declaration order, + * otherwise may be NULL. */ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_get) ( // struct ecsact_system_execution_context* context, ecsact_component_like_id component_id, void* out_component_data, - ... + const void* indexed_field_values ); /** @@ -105,15 +107,16 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_get) * - `ECSACT_SYS_CAP_OPTIONAL_WRITEONLY` * - `ECSACT_SYS_CAP_OPTIONAL_READWRITE` * - * @param ... if the component has indexed fields then those fields must be - * supplied to the variadic arguments in declaration order. + * @param indexed_field_values if the component has indexed fields then those + * fields must be supplied as a sequential array in declaration order, + * otherwise may be NULL. */ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_update) ( // struct ecsact_system_execution_context* context, ecsact_component_like_id component_id, const void* component_data, - ... + const void* indexed_field_values ); /** @@ -125,27 +128,30 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_update) * - `ECSACT_SYS_CAP_OPTIONAL_WRITEONLY` * - `ECSACT_SYS_CAP_OPTIONAL_READWRITE` * - * @param ... if the component has indexed fields then those fields must be - * supplied to the variadic arguments in declaration order. + * @param indexed_field_values if the component has indexed fields then those + * fields must be supplied as a sequential array in declaration order, + * otherwise may be NULL. */ ECSACT_DYNAMIC_API_FN(bool, ecsact_system_execution_context_has) ( // struct ecsact_system_execution_context* context, ecsact_component_like_id component_id, - ... + const void* indexed_field_values ); /** * Enable or disable streaming data for the given component. - * @param ... if the component has indexed fields then those fields must be - * supplied to the variadic arguments in declaration order. + * + * @param indexed_field_values if the component has indexed fields then those + * fields must be supplied as a sequential array in declaration order, + * otherwise may be NULL. */ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_stream_toggle) ( // struct ecsact_system_execution_context* context, ecsact_component_id component_id, bool streaming_enabled, - ... + const void* indexed_field_values ); /**