@@ -159,12 +159,11 @@ TEST(AsyncRef, AddUpdateAndRemove) {
159
159
cb_info.entity = entity_id;
160
160
};
161
161
162
- // Declare core execution options
163
- auto options = ecsact::core::execution_options{};
162
+ ecsact::core::execution_options options{};
164
163
165
- ecsact_async_events_collector entity_async_evc {};
166
- entity_async_evc. async_entity_callback = entity_cb;
167
- entity_async_evc. async_entity_callback_user_data = &cb_info;
164
+ auto evc = ecsact_execution_events_collector {};
165
+ evc. entity_created_callback = entity_cb;
166
+ evc. entity_created_callback_user_data = &cb_info;
168
167
169
168
auto my_needed_component = async_test::NeededComponent{};
170
169
@@ -180,18 +179,18 @@ TEST(AsyncRef, AddUpdateAndRemove) {
180
179
ASSERT_LT (tick_diff, 10 );
181
180
}
182
181
182
+ // Reset events collector and options
183
+ evc.entity_created_callback = {};
184
+ evc.entity_created_callback_user_data = nullptr ;
183
185
options.clear ();
184
186
185
187
// Preparing add component data
186
- // auto my_needed_component = async_test::NeededComponent{};
187
188
auto my_update_component = async_test::ComponentUpdate{.value_to_update = 1 };
188
189
189
- // options.add_component(cb_info.entity, &my_needed_component);
190
190
options.add_component (cb_info.entity , &my_update_component);
191
191
192
192
// Adding components
193
193
ecsact_async_enqueue_execution_options (options.c ());
194
- options.clear ();
195
194
196
195
// Prepare the events collector for the flush to make sure we got all the
197
196
// events we expected.
@@ -225,6 +224,7 @@ TEST(AsyncRef, AddUpdateAndRemove) {
225
224
226
225
evc.init_callback = {};
227
226
evc.init_callback_user_data = nullptr ;
227
+ options.clear ();
228
228
229
229
evc.update_callback_user_data = &cb_info;
230
230
evc.update_callback = //
@@ -250,12 +250,9 @@ TEST(AsyncRef, AddUpdateAndRemove) {
250
250
my_update_component.value_to_update += 5 ;
251
251
252
252
// Update components
253
- options.update_component <async_test::ComponentUpdate>(
254
- cb_info.entity ,
255
- &my_update_component
256
- );
253
+ options.update_component (cb_info.entity , &my_update_component);
254
+
257
255
ecsact_async_enqueue_execution_options (options.c ());
258
- options.clear ();
259
256
260
257
start_tick = ecsact_async_get_current_tick ();
261
258
while (!cb_info.update_happened ) {
@@ -265,14 +262,14 @@ TEST(AsyncRef, AddUpdateAndRemove) {
265
262
ASSERT_LT (tick_diff, 10 );
266
263
}
267
264
265
+ options.clear ();
268
266
evc.update_callback = {};
269
267
evc.update_callback_user_data = nullptr ;
270
268
271
269
// Remove component
272
270
options.remove_component <async_test::ComponentUpdate>(cb_info.entity );
273
271
274
272
ecsact_async_enqueue_execution_options (options.c ());
275
- options.clear ();
276
273
277
274
evc.remove_callback_user_data = &cb_info;
278
275
evc.remove_callback = //
@@ -307,6 +304,7 @@ TEST(AsyncRef, AddUpdateAndRemove) {
307
304
<< " remove = " << cb_info.remove_happened << " \n " ;
308
305
}
309
306
307
+ options.clear ();
310
308
ecsact_async_disconnect ();
311
309
}
312
310
@@ -322,17 +320,9 @@ TEST(AsyncRef, TryMergeFailure) {
322
320
323
321
ecsact_async_connect (" good?tick_rate=25" );
324
322
325
- auto my_needed_component = async_test::NeededComponent{};
326
- auto another_my_needed_component = async_test::NeededComponent{};
327
-
328
- ecsact_component needed_component{
329
- .component_id = async_test::NeededComponent::id,
330
- .component_data = &my_needed_component,
331
- };
332
-
333
- ecsact_component another_needed_component{
334
- .component_id = async_test::NeededComponent::id,
335
- .component_data = &another_my_needed_component,
323
+ struct merge_callback_data {
324
+ ecsact_async_request_id request_id;
325
+ bool wait;
336
326
};
337
327
338
328
auto entity_cb = //
@@ -348,56 +338,6 @@ TEST(AsyncRef, TryMergeFailure) {
348
338
entity_info.entity = entity_id;
349
339
};
350
340
351
- entity_cb_info cb_info{};
352
-
353
- // 1D array
354
- std::array<ecsact_component, 2 > entity_components = {
355
- needed_component,
356
- another_needed_component,
357
- };
358
-
359
- // 1D array
360
- std::array<ecsact_component, 1 > another_entity_components = {
361
- needed_component,
362
- };
363
-
364
- // Do I combine both the above arrays to make a 2D array?
365
- auto my_vector = std::vector<ecsact_component*>{};
366
- my_vector.push_back (entity_components.data ());
367
- my_vector.push_back (another_entity_components.data ());
368
-
369
- // Holds above array sizes
370
- std::array<int , 2 > entity_component_lengths = {
371
- entity_components.size (),
372
- another_entity_components.size (),
373
- };
374
-
375
- ecsact_execution_options entity_options{};
376
-
377
- entity_options.create_entities_components = my_vector.data ();
378
- entity_options.create_entities_length = entity_component_lengths.size ();
379
- entity_options.create_entities_components_length =
380
- entity_component_lengths.data ();
381
-
382
- ecsact_async_enqueue_execution_options (entity_options);
383
-
384
- auto evc = ecsact_execution_events_collector{};
385
- evc.entity_created_callback = entity_cb;
386
- evc.entity_created_callback_user_data = &cb_info;
387
-
388
- auto start_tick = ecsact_async_get_current_tick ();
389
- while (cb_info.wait != true ) {
390
- ecsact_async_flush_events (&evc, nullptr );
391
- auto current_tick = ecsact_async_get_current_tick ();
392
- auto tick_diff = current_tick - start_tick;
393
- ASSERT_LT (tick_diff, 10 );
394
- }
395
-
396
- struct merge_callback_data {
397
- ecsact_async_request_id request_id;
398
- bool wait;
399
- };
400
-
401
341
auto async_err_cb = //
402
342
[](
403
343
ecsact_async_error async_err,
@@ -414,36 +354,42 @@ TEST(AsyncRef, TryMergeFailure) {
414
354
cb_data.wait = true ;
415
355
};
416
356
417
- std::array entities{cb_info.entity , cb_info.entity };
418
- std::array components{
419
- needed_component,
420
- another_needed_component,
421
- };
357
+ entity_cb_info cb_info{};
422
358
423
- ecsact_execution_options options{};
424
- options.add_components_entities = entities.data ();
425
- options.add_components = components.data ();
426
- options.add_components_length = entities.size ();
359
+ ecsact::core::execution_options options{};
427
360
428
- auto options_request = ecsact_async_enqueue_execution_options (options);
361
+ auto my_needed_component = async_test::NeededComponent{};
362
+ auto another_my_needed_component = async_test::NeededComponent{};
429
363
430
- merge_callback_data merge_cb_info{
431
- .request_id = options_request,
432
- .wait = false ,
433
- };
364
+ options.create_entity ()
365
+ .add_component (&my_needed_component)
366
+ .add_component (&another_my_needed_component);
367
+
368
+ auto request_id = ecsact_async_enqueue_execution_options (options.c ());
369
+
370
+ auto merge_data = merge_callback_data{};
371
+ merge_data.request_id = request_id;
372
+ merge_data.wait = false ;
373
+
374
+ auto evc = ecsact_execution_events_collector{};
375
+ evc.entity_created_callback = entity_cb;
376
+ evc.entity_created_callback_user_data = &cb_info;
377
+
378
+ auto async_evc = ecsact_async_events_collector{};
434
379
435
- ecsact_async_events_collector async_evc{};
436
380
async_evc.async_error_callback = async_err_cb;
437
- async_evc.async_error_callback_user_data = &merge_cb_info ;
381
+ async_evc.async_error_callback_user_data = &merge_data ;
438
382
439
- start_tick = ecsact_async_get_current_tick ();
440
- while (merge_cb_info .wait != true ) {
441
- ecsact_async_flush_events (nullptr , &async_evc);
383
+ auto start_tick = ecsact_async_get_current_tick ();
384
+ while (merge_data .wait != true ) {
385
+ ecsact_async_flush_events (&evc , &async_evc);
442
386
auto current_tick = ecsact_async_get_current_tick ();
443
387
auto tick_diff = current_tick - start_tick;
444
388
ASSERT_LT (tick_diff, 10 );
445
389
}
446
390
391
+ options.clear ();
392
+
447
393
ecsact_async_disconnect ();
448
394
}
449
395
0 commit comments