@@ -25,8 +25,9 @@ struct ecsact_system_execution_context {
25
25
// templated type. See `system_execution_context<Package, System>`
26
26
ecsact_entt_rt::system_execution_context_base* impl;
27
27
28
- // This is set by the system_execution_context::other method
29
- signed association_index = -1 ;
28
+ // This is set by the system_execution_context::other method. `0` means
29
+ // no association.
30
+ unsigned association_index = 0 ;
30
31
};
31
32
32
33
namespace ecsact_entt_rt {
@@ -38,6 +39,28 @@ struct system_execution_context_base {
38
39
::entt::entity entity;
39
40
const cptr_t parent;
40
41
const void * action;
42
+
43
+ system_execution_context_base (
44
+ ::entt::entity entity,
45
+ cptr_t parent,
46
+ const void * action
47
+ )
48
+ : entity(entity), parent(parent), action(action) {
49
+ }
50
+
51
+ virtual ~system_execution_context_base () {
52
+ }
53
+
54
+ virtual auto other (ecsact_entity_id other_entity)
55
+ -> ecsact_system_execution_context* = 0;
56
+
57
+ virtual auto get_ecsact_entity_id () -> ecsact_entity_id const = 0;
58
+
59
+ virtual auto generate (
60
+ int component_count,
61
+ ecsact_component_id* component_ids,
62
+ const void ** components_data
63
+ ) -> void = 0;
41
64
};
42
65
43
66
namespace detail {}
@@ -57,6 +80,17 @@ struct system_execution_context : system_execution_context_base {
57
80
using association_views_type =
58
81
ecsact::entt::association_views_type<caps_info>;
59
82
83
+ using readonly_components = typename caps_info::readonly_components;
84
+ using readwrite_components = typename caps_info::readwrite_components;
85
+ using adds_components = typename caps_info::adds_components;
86
+ using removes_components = typename caps_info::removes_components;
87
+
88
+ using gettable_components = boost::mp11::mp_assign<
89
+ ::ecsact::mp_list<>,
90
+ boost::mp11::mp_unique<boost::mp11::mp_flatten<
91
+ boost::mp11::mp_push_back<readonly_components, readwrite_components>,
92
+ ::ecsact::mp_list<>>>>;
93
+
60
94
static_assert (
61
95
boost::mp11::mp_size<typename caps_info::associations>::value ==
62
96
std::tuple_size_v<association_views_type>,
@@ -85,7 +119,7 @@ struct system_execution_context : system_execution_context_base {
85
119
const cptr_t parent,
86
120
const void * action
87
121
)
88
- : system_execution_context_base{ entity, parent, action}
122
+ : system_execution_context_base( entity, parent, action)
89
123
, info(info)
90
124
, view(view)
91
125
, assoc_views(assoc_views) {
@@ -141,15 +175,15 @@ struct system_execution_context : system_execution_context_base {
141
175
}
142
176
}
143
177
144
- void add (ecsact_component_like_id component_id, const void * component_data) {
145
- using ecsact::entt::detail::mp_for_each_available_component;
146
-
147
- mp_for_each_available_component<package>([&]<typename C>(const C&) {
148
- if (ecsact_id_cast<ecsact_component_like_id>(C::id) == component_id) {
149
- add<C>(*static_cast <const C*>(component_data));
150
- }
151
- });
152
- }
178
+ // void add(ecsact_component_like_id component_id, const void* component_data)
179
+ // { using ecsact::entt::detail::mp_for_each_available_component;
180
+ //
181
+ // mp_for_each_available_component<package>([&]<typename C>(const C&) {
182
+ // if(ecsact_id_cast<ecsact_component_like_id>(C::id) == component_id) {
183
+ // add<C>(*static_cast<const C*>(component_data));
184
+ // }
185
+ // });
186
+ // }
153
187
154
188
template <typename C>
155
189
void remove () {
@@ -197,15 +231,15 @@ struct system_execution_context : system_execution_context_base {
197
231
info.registry .template emplace_or_replace <pending_remove<C>>(entity);
198
232
}
199
233
200
- void remove (ecsact_component_like_id component_id) {
201
- using ecsact::entt::detail::mp_for_each_available_component;
202
-
203
- mp_for_each_available_component<package>([&]<typename C>(const C&) {
204
- if (ecsact_id_cast<ecsact_component_like_id>(C::id) == component_id) {
205
- remove<C>();
206
- }
207
- });
208
- }
234
+ // void remove(ecsact_component_like_id component_id) {
235
+ // using ecsact::entt::detail::mp_for_each_available_component;
236
+ //
237
+ // mp_for_each_available_component<package>([&]<typename C>(const C&) {
238
+ // if(ecsact_id_cast<ecsact_component_like_id>(C::id) == component_id) {
239
+ // remove<C>();
240
+ // }
241
+ // });
242
+ // }
209
243
210
244
template <typename C>
211
245
requires (!std::is_empty_v<C>)
@@ -221,46 +255,44 @@ struct system_execution_context : system_execution_context_base {
221
255
return view.template get <C>(entity);
222
256
}
223
257
224
- void get (ecsact_component_like_id component_id, void * out_component_data) {
225
- using boost::mp11::mp_assign;
226
- using boost::mp11::mp_flatten;
227
- using boost::mp11::mp_for_each;
228
- using boost::mp11::mp_push_back;
229
- using boost::mp11::mp_unique;
230
- using ecsact::entt_mp11_util::mp_map_find_value_or;
231
-
232
- using readonly_components = typename caps_info::readonly_components;
233
- using readwrite_components = typename caps_info::readwrite_components;
234
- using gettable_components = mp_assign<
235
- ::ecsact::mp_list<>,
236
- mp_unique<mp_flatten<
237
- mp_push_back<readonly_components, readwrite_components>,
238
- ::ecsact::mp_list<>>>>;
239
-
240
- #ifndef NDEBUG
241
- [[maybe_unused]] bool found_gettable_component = false ;
242
- [[maybe_unused]] const char * get_component_name = " " ;
243
- [[maybe_unused]] auto gettable_components_type_name =
244
- typeid (gettable_components).name ();
245
- #endif // NDEBUG
246
-
247
- mp_for_each<gettable_components>([&]<typename C>(C) {
248
- if (ecsact_id_cast<ecsact_component_like_id>(C::id) == component_id) {
249
- if constexpr (!std::is_empty_v<C>) {
250
- C& out_component = *reinterpret_cast <C*>(out_component_data);
251
- out_component = get<C>();
252
- #ifndef NDEBUG
253
- get_component_name = typeid (C).name ();
254
- found_gettable_component = true ;
255
- #endif // NDEBUG
256
- }
257
- }
258
- });
259
-
260
- #ifndef NDEBUG
261
- assert (found_gettable_component);
262
- #endif // NDEBUG
263
- }
258
+ // void get(ecsact_component_like_id component_id, void* out_component_data)
259
+ // { using boost::mp11::mp_assign; using boost::mp11::mp_flatten;
260
+ // using boost::mp11::mp_for_each; using boost::mp11::mp_push_back; using
261
+ // boost::mp11::mp_unique; using
262
+ // ecsact::entt_mp11_util::mp_map_find_value_or;
263
+ //
264
+ // using readonly_components = typename caps_info::readonly_components;
265
+ // using readwrite_components = typename caps_info::readwrite_components;
266
+ // using gettable_components = mp_assign<
267
+ // ::ecsact::mp_list<>,
268
+ // mp_unique<mp_flatten<
269
+ // mp_push_back<readonly_components, readwrite_components>,
270
+ // ::ecsact::mp_list<>>>>;
271
+ //
272
+ // #ifndef NDEBUG
273
+ // [[maybe_unused]] bool found_gettable_component = false;
274
+ // [[maybe_unused]] const char* get_component_name = "";
275
+ // [[maybe_unused]] auto gettable_components_type_name =
276
+ // typeid(gettable_components).name();
277
+ // #endif // NDEBUG
278
+ //
279
+ // mp_for_each<gettable_components>([&]<typename C>(C) {
280
+ // if(ecsact_id_cast<ecsact_component_like_id>(C::id) == component_id) {
281
+ // if constexpr(!std::is_empty_v<C>) {
282
+ // C& out_component = *reinterpret_cast<C*>(out_component_data);
283
+ // out_component = get<C>();
284
+ // #ifndef NDEBUG
285
+ // get_component_name = typeid(C).name();
286
+ // found_gettable_component = true;
287
+ // #endif // NDEBUG
288
+ // }
289
+ // }
290
+ // });
291
+ //
292
+ // #ifndef NDEBUG
293
+ // assert(found_gettable_component);
294
+ // #endif // NDEBUG
295
+ // }
264
296
265
297
template <typename C>
266
298
requires (!std::is_empty_v<C>)
@@ -294,23 +326,23 @@ struct system_execution_context : system_execution_context_base {
294
326
comp = c;
295
327
}
296
328
297
- void update (
298
- ecsact_component_like_id component_id,
299
- const void * component_data
300
- ) {
301
- using boost::mp11::mp_for_each;
302
- using boost::mp11::mp_list;
303
- using boost::mp11::mp_map_find;
304
- using ecsact::entt_mp11_util::mp_map_find_value_or;
305
-
306
- using readwrite_components = typename caps_info::readwrite_components;
307
-
308
- mp_for_each<readwrite_components>([&]<typename C>(C) {
309
- if (ecsact_id_cast<ecsact_component_like_id>(C::id) == component_id) {
310
- update<C>(*reinterpret_cast <const C*>(component_data));
311
- }
312
- });
313
- }
329
+ // void update(
330
+ // ecsact_component_like_id component_id,
331
+ // const void* component_data
332
+ // ) {
333
+ // using boost::mp11::mp_for_each;
334
+ // using boost::mp11::mp_list;
335
+ // using boost::mp11::mp_map_find;
336
+ // using ecsact::entt_mp11_util::mp_map_find_value_or;
337
+ //
338
+ // using readwrite_components = typename caps_info::readwrite_components;
339
+ //
340
+ // mp_for_each<readwrite_components>([&]<typename C>(C) {
341
+ // if(ecsact_id_cast<ecsact_component_like_id>(C::id) == component_id) {
342
+ // update<C>(*reinterpret_cast<const C*>(component_data));
343
+ // }
344
+ // });
345
+ // }
314
346
315
347
template <typename ComponentT>
316
348
bool has () {
@@ -334,11 +366,11 @@ struct system_execution_context : system_execution_context_base {
334
366
return result;
335
367
}
336
368
337
- void generate (
369
+ auto generate (
338
370
int component_count,
339
371
ecsact_component_id* component_ids,
340
372
const void ** components_data
341
- ) {
373
+ ) -> void override {
342
374
using ecsact::entt::component_added;
343
375
using ecsact::entt::detail::created_entity;
344
376
using ecsact::entt::detail::mp_for_each_available_component;
@@ -369,7 +401,8 @@ struct system_execution_context : system_execution_context_base {
369
401
}
370
402
}
371
403
372
- ecsact_system_execution_context* other (ecsact_entity_id other_entity) {
404
+ auto other (ecsact_entity_id other_entity)
405
+ -> ecsact_system_execution_context* override {
373
406
using boost::mp11::mp_first;
374
407
using boost::mp11::mp_for_each;
375
408
using boost::mp11::mp_second;
@@ -422,7 +455,7 @@ struct system_execution_context : system_execution_context_base {
422
455
);
423
456
424
457
other_context->_c_ctx .association_index =
425
- static_cast <signed >(assoc_index);
458
+ static_cast <unsigned >(assoc_index + 1 );
426
459
}
427
460
428
461
return_context = &other_context->_c_ctx ;
@@ -436,7 +469,7 @@ struct system_execution_context : system_execution_context_base {
436
469
return return_context;
437
470
}
438
471
439
- ecsact_entity_id get_ecsact_entity_id () const {
472
+ auto get_ecsact_entity_id () -> ecsact_entity_id const override {
440
473
return info.get_ecsact_entity_id (entity);
441
474
}
442
475
};
0 commit comments