Skip to content

Commit b034c85

Browse files
authored
feat: remove use of variadic arguments in api due to wasm limitation (#264)
1 parent bf7b0d9 commit b034c85

File tree

4 files changed

+108
-58
lines changed

4 files changed

+108
-58
lines changed

ecsact/runtime/async.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,15 +209,16 @@ ECSACT_ASYNC_API_FN(int32_t, ecsact_async_get_current_tick)(void);
209209
* Sends Ecsact stream data to the specified registry. Stream data will be
210210
* applied on the next ecsact_execute_systems call.
211211
*
212-
* @param ... if the component has indexed fields then those fields must be
213-
* supplied to the variadic arguments in declaration order.
212+
* @param indexed_field_values if the component has indexed fields then those
213+
* fields must be supplied as a sequential array in declaration order,
214+
* otherwise may be NULL.
214215
*/
215216
ECSACT_CORE_API_FN(ecsact_async_request_id, ecsact_async_stream)
216217
( //
217218
ecsact_entity_id entity,
218219
ecsact_component_id component_id,
219220
const void* component_data,
220-
...
221+
const void* indexed_field_values
221222
);
222223

223224
#define FOR_EACH_ECSACT_ASYNC_API_FN(fn, ...) \

ecsact/runtime/core.h

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,29 +135,34 @@ ECSACT_CORE_API_FN(ecsact_add_error, ecsact_add_component)
135135

136136
/**
137137
* Checks if a given entity has component with id @p component_id
138-
* @param ... if the component has indexed fields then those fields must be
139-
* supplied to the variadic arguments in declaration order.
138+
*
139+
* @param indexed_field_values if the component has indexed fields then those
140+
* fields must be supplied as a sequential array in declaration order,
141+
* otherwise may be NULL.
140142
*/
141143
ECSACT_CORE_API_FN(bool, ecsact_has_component)
142144
( //
143145
ecsact_registry_id registry_id,
144146
ecsact_entity_id entity_id,
145147
ecsact_component_id component_id,
146-
...
148+
const void* indexed_field_values
147149
);
148150

149151
/**
150-
* @param ... if the component has indexed fields then those fields must be
151-
* supplied to the variadic arguments in declaration order.
152+
* @param indexed_field_values if the component has indexed fields then those
153+
* fields must be supplied as a sequential array in declaration order,
154+
* otherwise may be NULL.
155+
*
152156
* @returns non-owning pointer of the component data
157+
*
153158
* NOTE: This method should be avoided if possible.
154159
*/
155160
ECSACT_CORE_API_FN(const void*, ecsact_get_component)
156161
( //
157162
ecsact_registry_id registry_id,
158163
ecsact_entity_id entity_id,
159164
ecsact_component_id component_id,
160-
...
165+
const void* indexed_field_values
161166
);
162167

163168
/**
@@ -199,8 +204,9 @@ ECSACT_CORE_API_FN(void, ecsact_each_component)
199204
/**
200205
* Update a component for the specified entity.
201206
*
202-
* @param ... if the component has indexed fields then those fields must be
203-
* supplied to the variadic arguments in declaration order.
207+
* @param indexed_field_values if the component has indexed fields then those
208+
* fields must be supplied as a sequential array in declaration order,
209+
* otherwise may be NULL.
204210
*
205211
* NOTE: This method should be avoided if possible. Updating a component in a
206212
* system or system execution options is preferred.
@@ -212,14 +218,15 @@ ECSACT_CORE_API_FN(ecsact_update_error, ecsact_update_component)
212218
ecsact_entity_id entity_id,
213219
ecsact_component_id component_id,
214220
const void* component_data,
215-
...
221+
const void* indexed_field_values
216222
);
217223

218224
/**
219225
* Removes a component from the specified entity.
220226
*
221-
* @param ... if the component has indexed fields then those fields must be
222-
* supplied to the variadic arguments in declaration order.
227+
* @param indexed_field_values if the component has indexed fields then those
228+
* fields must be supplied as a sequential array in declaration order,
229+
* otherwise may be NULL.
223230
*
224231
* NOTE: This method should be avoided if possible. Removing a component in a
225232
* system or system execution options is preferred.
@@ -230,7 +237,7 @@ ECSACT_CORE_API_FN(void, ecsact_remove_component)
230237
ecsact_registry_id registry_id,
231238
ecsact_entity_id entity_id,
232239
ecsact_component_id component_id,
233-
...
240+
const void* indexed_field_values
234241
);
235242

236243
/**
@@ -269,16 +276,17 @@ ECSACT_CORE_API_FN(ecsact_ees, ecsact_get_entity_execution_status)
269276
* applied on the next ecsact_execute_systems call. The last set of stream data
270277
* is always used.
271278
*
272-
* @param ... if the component has indexed fields then those fields must be
273-
* supplied to the variadic arguments in declaration order.
279+
* @param indexed_field_values if the component has indexed fields then those
280+
* fields must be supplied as a sequential array in declaration order,
281+
* otherwise may be NULL.
274282
*/
275283
ECSACT_CORE_API_FN(ecsact_stream_error, ecsact_stream)
276284
( //
277285
ecsact_registry_id registry_id,
278286
ecsact_entity_id entity,
279287
ecsact_component_id component_id,
280288
const void* component_data,
281-
...
289+
const void* indexed_field_values
282290
);
283291

284292
// # BEGIN FOR_EACH_ECSACT_CORE_API_FN

ecsact/runtime/core.hh

Lines changed: 60 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -648,12 +648,19 @@ public:
648648
);
649649
}
650650

651-
return *reinterpret_cast<const Component*>(ecsact_get_component(
652-
_id,
653-
entity_id,
654-
Component::id,
655-
std::forward<AssocFields>(assoc_fields)...
656-
));
651+
if constexpr(sizeof...(AssocFields) > 0) {
652+
const void* assoc_field_values[sizeof...(AssocFields)] = {
653+
&assoc_fields...,
654+
};
655+
656+
return *reinterpret_cast<const Component*>(
657+
ecsact_get_component(_id, entity_id, Component::id, assoc_field_values)
658+
);
659+
} else {
660+
return *reinterpret_cast<const Component*>(
661+
ecsact_get_component(_id, entity_id, Component::id, nullptr)
662+
);
663+
}
657664
}
658665

659666
template<typename Component, typename... AssocFields>
@@ -668,12 +675,19 @@ public:
668675
);
669676
}
670677

671-
return ecsact_has_component(
672-
_id,
673-
entity_id,
674-
Component::id,
675-
std::forward<AssocFields>(assoc_fields)...
676-
);
678+
if constexpr(sizeof...(AssocFields) > 0) {
679+
const void* assoc_field_values[sizeof...(AssocFields)] = {
680+
&assoc_fields...,
681+
};
682+
return ecsact_has_component(
683+
_id,
684+
entity_id,
685+
Component::id,
686+
assoc_field_values
687+
);
688+
} else {
689+
return ecsact_has_component(_id, entity_id, Component::id, nullptr);
690+
}
677691
}
678692

679693
template<typename Component>
@@ -707,13 +721,26 @@ public:
707721
);
708722
}
709723

710-
return ecsact_update_component(
711-
_id,
712-
entity_id,
713-
Component::id,
714-
&component,
715-
std::forward<AssocFields>(assoc_fields)...
716-
);
724+
if constexpr(sizeof...(AssocFields) > 0) {
725+
const void* assoc_field_values[sizeof...(AssocFields)] = {
726+
&assoc_fields...,
727+
};
728+
return ecsact_update_component(
729+
_id,
730+
entity_id,
731+
Component::id,
732+
&component,
733+
assoc_field_values
734+
);
735+
} else {
736+
return ecsact_update_component(
737+
_id,
738+
entity_id,
739+
Component::id,
740+
&component,
741+
nullptr
742+
);
743+
}
717744
}
718745

719746
template<typename Component, typename... AssocFields>
@@ -728,12 +755,20 @@ public:
728755
);
729756
}
730757

731-
return ecsact_remove_component(
732-
_id,
733-
entity_id,
734-
Component::id,
735-
std::forward<AssocFields>(assoc_fields)...
736-
);
758+
if constexpr(sizeof...(AssocFields) > 0) {
759+
const void* assoc_field_values[sizeof...(AssocFields)] = {
760+
&assoc_fields...,
761+
};
762+
763+
return ecsact_remove_component(
764+
_id,
765+
entity_id,
766+
Component::id,
767+
assoc_field_values
768+
);
769+
} else {
770+
return ecsact_remove_component(_id, entity_id, Component::id, nullptr);
771+
}
737772
}
738773

739774
ECSACT_ALWAYS_INLINE auto count_entities() const -> int32_t {

ecsact/runtime/dynamic.h

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,15 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_add)
6464
* Only available if has one of these capabilities:
6565
* - `ECSACT_SYS_CAP_REMOVES`
6666
*
67-
* @param ... if the component has indexed fields then those fields must be
68-
* supplied to the variadic arguments in declaration order.
67+
* @param indexed_field_values if the component has indexed fields then those
68+
* fields must be supplied as a sequential array in declaration order,
69+
* otherwise may be NULL.
6970
*/
7071
ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_remove)
7172
( //
7273
struct ecsact_system_execution_context* context,
7374
ecsact_component_like_id component_id,
74-
...
75+
const void* indexed_field_values
7576
);
7677

7778
/**
@@ -87,15 +88,16 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_remove)
8788
* - `ECSACT_SYS_CAP_OPTIONAL_READONLY`
8889
* - `ECSACT_SYS_CAP_OPTIONAL_READWRITE`
8990
*
90-
* @param ... if the component has indexed fields then those fields must be
91-
* supplied to the variadic arguments in declaration order.
91+
* @param indexed_field_values if the component has indexed fields then those
92+
* fields must be supplied as a sequential array in declaration order,
93+
* otherwise may be NULL.
9294
*/
9395
ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_get)
9496
( //
9597
struct ecsact_system_execution_context* context,
9698
ecsact_component_like_id component_id,
9799
void* out_component_data,
98-
...
100+
const void* indexed_field_values
99101
);
100102

101103
/**
@@ -105,15 +107,16 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_get)
105107
* - `ECSACT_SYS_CAP_OPTIONAL_WRITEONLY`
106108
* - `ECSACT_SYS_CAP_OPTIONAL_READWRITE`
107109
*
108-
* @param ... if the component has indexed fields then those fields must be
109-
* supplied to the variadic arguments in declaration order.
110+
* @param indexed_field_values if the component has indexed fields then those
111+
* fields must be supplied as a sequential array in declaration order,
112+
* otherwise may be NULL.
110113
*/
111114
ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_update)
112115
( //
113116
struct ecsact_system_execution_context* context,
114117
ecsact_component_like_id component_id,
115118
const void* component_data,
116-
...
119+
const void* indexed_field_values
117120
);
118121

119122
/**
@@ -125,27 +128,30 @@ ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_update)
125128
* - `ECSACT_SYS_CAP_OPTIONAL_WRITEONLY`
126129
* - `ECSACT_SYS_CAP_OPTIONAL_READWRITE`
127130
*
128-
* @param ... if the component has indexed fields then those fields must be
129-
* supplied to the variadic arguments in declaration order.
131+
* @param indexed_field_values if the component has indexed fields then those
132+
* fields must be supplied as a sequential array in declaration order,
133+
* otherwise may be NULL.
130134
*/
131135
ECSACT_DYNAMIC_API_FN(bool, ecsact_system_execution_context_has)
132136
( //
133137
struct ecsact_system_execution_context* context,
134138
ecsact_component_like_id component_id,
135-
...
139+
const void* indexed_field_values
136140
);
137141

138142
/**
139143
* Enable or disable streaming data for the given component.
140-
* @param ... if the component has indexed fields then those fields must be
141-
* supplied to the variadic arguments in declaration order.
144+
*
145+
* @param indexed_field_values if the component has indexed fields then those
146+
* fields must be supplied as a sequential array in declaration order,
147+
* otherwise may be NULL.
142148
*/
143149
ECSACT_DYNAMIC_API_FN(void, ecsact_system_execution_context_stream_toggle)
144150
( //
145151
struct ecsact_system_execution_context* context,
146152
ecsact_component_id component_id,
147153
bool streaming_enabled,
148-
...
154+
const void* indexed_field_values
149155
);
150156

151157
/**

0 commit comments

Comments
 (0)