Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove use of variadic arguments in api due to wasm limitation #264

Merged
merged 1 commit into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions ecsact/runtime/async.h
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...) \
Expand Down
38 changes: 23 additions & 15 deletions ecsact/runtime/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,29 +135,34 @@ 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)
( //
ecsact_registry_id registry_id,
ecsact_entity_id entity_id,
ecsact_component_id component_id,
...
const void* indexed_field_values
);

/**
Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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
);

/**
Expand Down Expand Up @@ -269,16 +276,17 @@ 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)
( //
ecsact_registry_id registry_id,
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
Expand Down
85 changes: 60 additions & 25 deletions ecsact/runtime/core.hh
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,19 @@ public:
);
}

return *reinterpret_cast<const Component*>(ecsact_get_component(
_id,
entity_id,
Component::id,
std::forward<AssocFields>(assoc_fields)...
));
if constexpr(sizeof...(AssocFields) > 0) {
const void* assoc_field_values[sizeof...(AssocFields)] = {
&assoc_fields...,
};

return *reinterpret_cast<const Component*>(
ecsact_get_component(_id, entity_id, Component::id, assoc_field_values)
);
} else {
return *reinterpret_cast<const Component*>(
ecsact_get_component(_id, entity_id, Component::id, nullptr)
);
}
}

template<typename Component, typename... AssocFields>
Expand All @@ -668,12 +675,19 @@ public:
);
}

return ecsact_has_component(
_id,
entity_id,
Component::id,
std::forward<AssocFields>(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<typename Component>
Expand Down Expand Up @@ -707,13 +721,26 @@ public:
);
}

return ecsact_update_component(
_id,
entity_id,
Component::id,
&component,
std::forward<AssocFields>(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<typename Component, typename... AssocFields>
Expand All @@ -728,12 +755,20 @@ public:
);
}

return ecsact_remove_component(
_id,
entity_id,
Component::id,
std::forward<AssocFields>(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 {
Expand Down
36 changes: 21 additions & 15 deletions ecsact/runtime/dynamic.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
);

/**
Expand All @@ -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
);

/**
Expand All @@ -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
);

/**
Expand All @@ -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
);

/**
Expand Down
Loading