Skip to content

Commit 2154101

Browse files
committed
Add actions to options, update all tests with execution_options. Tests are all working!
1 parent b366976 commit 2154101

File tree

2 files changed

+26
-46
lines changed

2 files changed

+26
-46
lines changed

ecsact/runtime/core.hh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ public:
159159
destroy_entities.push_back(entity_id);
160160
}
161161

162+
inline void push_action(const ecsact_action& action) {
163+
actions.push_back(action);
164+
}
165+
162166
inline void clear() {
163167
options = {};
164168

@@ -176,6 +180,8 @@ public:
176180

177181
create_entities.clear();
178182
destroy_entities.clear();
183+
184+
actions.clear();
179185
}
180186

181187
inline ecsact_execution_options c() {
@@ -204,6 +210,9 @@ public:
204210
options.destroy_entities = destroy_entities.data();
205211
options.destroy_entities_length = destroy_entities.size();
206212

213+
options.actions = actions.data();
214+
options.actions_length = actions.size();
215+
207216
return options;
208217
}
209218

@@ -223,6 +232,8 @@ private:
223232
std::vector<int> entities_component_lengths;
224233
std::vector<ecsact_component*> entities_components;
225234

235+
std::vector<ecsact_action> actions;
236+
226237
ecsact_execution_options options;
227238
};
228239

tests/async/async_ref_test.cc

Lines changed: 15 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -400,21 +400,15 @@ TEST(AsyncRef, ReceiveMultipleEntities) {
400400

401401
auto connect_req_id = ecsact_async_connect("good?tick_rate=25");
402402

403-
auto entity_options = ecsact_execution_options{};
403+
auto options = ecsact::core::execution_options{};
404404

405-
entity_options.create_entities_components = {nullptr};
406-
entity_options.create_entities_length = 0;
407-
entity_options.create_entities_components_length = nullptr;
405+
options.create_entity();
408406

409407
for(int i = 0; i < 10; i++) {
410-
ecsact_async_enqueue_execution_options(entity_options);
408+
ecsact_async_enqueue_execution_options(options.c());
411409
}
412410

413-
int counter = 0;
414-
ecsact_entity_id entity;
415-
416411
struct entity_cb_info {
417-
ecsact_entity_id& entity;
418412
std::array<int, 10> entity_request_ids;
419413
int& counter;
420414
};
@@ -431,17 +425,14 @@ TEST(AsyncRef, ReceiveMultipleEntities) {
431425
entity_info.counter++;
432426
};
433427

434-
entity_cb_info entity_info{
435-
.entity = entity,
436-
.entity_request_ids = {},
437-
.counter = counter};
428+
int counter = 0;
429+
430+
entity_cb_info entity_info{.entity_request_ids = {}, .counter = counter};
438431

439432
auto evc = ecsact_execution_events_collector{};
440433
evc.entity_created_callback = entity_cb;
441434
evc.entity_created_callback_user_data = &entity_info;
442435

443-
ecsact_async_enqueue_execution_options(entity_options);
444-
445436
auto start_tick = ecsact_async_get_current_tick();
446437
while(counter < 10) {
447438
ecsact_async_flush_events(&evc, nullptr);
@@ -488,31 +479,13 @@ TEST(AsyncRef, TryAction) {
488479

489480
async_test::ComponentUpdate my_update_component{.value_to_update = 1};
490481

491-
auto needed_component = ecsact_component{
492-
.component_id = async_test::NeededComponent::id,
493-
.component_data = &my_needed_component,
494-
};
495-
auto update_component = ecsact_component{
496-
.component_id = async_test::ComponentUpdate::id,
497-
.component_data = &my_update_component,
498-
};
499-
500-
// Add components to an array
501-
std::array<ecsact_component*, 2> add_components{
502-
&needed_component,
503-
&update_component,
504-
};
505-
506-
int component_length = 2;
507-
int* component_length_ptr = &component_length;
508-
509-
auto options = ecsact_execution_options{};
482+
auto options = ecsact::core::execution_options{};
510483

511-
options.create_entities_components = {add_components.data()};
512-
options.create_entities_length = 2;
513-
options.create_entities_components_length = component_length_ptr;
484+
options.create_entity()
485+
.add_component(&my_needed_component)
486+
.add_component(&my_update_component);
514487

515-
ecsact_async_enqueue_execution_options(options);
488+
ecsact_async_enqueue_execution_options(options.c());
516489

517490
auto evc = ecsact_execution_events_collector{};
518491
evc.entity_created_callback = entity_cb;
@@ -526,6 +499,8 @@ TEST(AsyncRef, TryAction) {
526499
ASSERT_LT(tick_diff, 10);
527500
}
528501

502+
options.clear();
503+
529504
async_test::TryEntity my_try_entity;
530505

531506
my_try_entity.my_entity = cb_info.entity;
@@ -542,20 +517,14 @@ TEST(AsyncRef, TryAction) {
542517
}
543518
);
544519

545-
std::vector<ecsact_action> actions{};
546-
547520
ecsact_action my_action{
548521
.action_id = async_test::TryEntity::id,
549522
.action_data = &my_try_entity,
550523
};
551524

552-
actions.push_back(my_action);
553-
options = {};
525+
options.push_action(my_action);
554526

555-
options.actions = actions.data();
556-
options.actions_length = actions.size();
557-
558-
ecsact_async_enqueue_execution_options(options);
527+
ecsact_async_enqueue_execution_options(options.c());
559528

560529
start_tick = ecsact_async_get_current_tick();
561530
while(reached_system != true) {

0 commit comments

Comments
 (0)