@@ -49,7 +49,10 @@ void runtime_test::TrivialRemove::impl(context& ctx) {
49
49
std::abort ();
50
50
}
51
51
52
+ static std::atomic_bool AssocTestAction_ran = false ;
53
+
52
54
void runtime_test::AssocTestAction::impl (context& ctx) {
55
+ AssocTestAction_ran = true ;
53
56
ctx.add (OtherEntityComponent{
54
57
.num = 42 ,
55
58
.target = ctx.action ().assoc_entity ,
@@ -73,6 +76,17 @@ void runtime_test::AttackDamageWeakened::impl(context& ctx) {
73
76
// target_ctx.update(target_health);
74
77
}
75
78
79
+ static std::atomic_bool AddAssocTest_ran = false ;
80
+
81
+ void runtime_test::AddAssocTest::impl (context& ctx) {
82
+ AddAssocTest_ran = true ;
83
+ auto other_entity = ctx.get <OtherEntityComponent>();
84
+
85
+ // Get Target other context from OtherEntityComponent
86
+ auto target_ctx = ctx._ctx .other (other_entity.target );
87
+ target_ctx.add (AddAssocTestComponent{.num = 10 });
88
+ }
89
+
76
90
TEST (Core, CreateRegistry) {
77
91
auto reg_id = ecsact_create_registry (" CreateRegistry" );
78
92
EXPECT_NE (reg_id, ecsact_invalid_registry_id);
@@ -393,51 +407,6 @@ TEST(Core, EventCollector) {
393
407
}
394
408
}
395
409
396
- TEST (Core, DynamicSystemImpl) {
397
- auto reg = ecsact::core::registry (" DynamicSystemImpl" );
398
- auto entity = reg.create_entity ();
399
- auto other_entity = reg.create_entity ();
400
-
401
- ComponentA comp{.a = 42 };
402
- reg.add_component (entity, comp);
403
- reg.add_component (other_entity, comp);
404
-
405
- OtherEntityComponent other_comp{.num = 3 , .target = other_entity};
406
- ASSERT_EQ (reg.add_component (entity, other_comp), ECSACT_ADD_OK);
407
-
408
- // Sanity check
409
- ASSERT_TRUE (reg.has_component <ComponentA>(entity));
410
- ASSERT_EQ (reg.get_component <ComponentA>(entity), comp);
411
- ASSERT_TRUE (reg.has_component <ComponentA>(other_entity));
412
- ASSERT_EQ (reg.get_component <ComponentA>(other_entity), comp);
413
- ASSERT_TRUE (reg.has_component <OtherEntityComponent>(entity));
414
- ASSERT_EQ (reg.get_component <OtherEntityComponent>(entity), other_comp);
415
-
416
- ecsact_set_system_execution_impl (
417
- ecsact_id_cast<ecsact_system_like_id>(runtime_test::SimpleSystem::id),
418
- &runtime_test__SimpleSystem
419
- );
420
-
421
- ecsact_set_system_execution_impl (
422
- ecsact_id_cast<ecsact_system_like_id>(runtime_test::OtherEntitySystem::id),
423
- &runtime_test__OtherEntitySystem
424
- );
425
-
426
- auto exec_err = ecsact_execute_systems (reg.id (), 1 , nullptr , nullptr );
427
- ASSERT_EQ (exec_err, ECSACT_EXEC_SYS_OK);
428
-
429
- // Sanity check
430
- ASSERT_TRUE (reg.has_component <ComponentA>(entity));
431
-
432
- auto comp_get = reg.get_component <ComponentA>(entity);
433
-
434
- EXPECT_NE (comp_get.a , comp.a );
435
-
436
- // Simulate what the system should be doing.
437
- comp.a += 2 ;
438
- EXPECT_EQ (comp_get.a , comp.a );
439
- }
440
-
441
410
TEST (Core, ExecuteSystemsErrors) {
442
411
auto reg = ecsact::core::registry (" ExecuteSystemsErrors" );
443
412
auto options = ecsact_execution_options{};
@@ -476,6 +445,50 @@ TEST(Core, ExecuteSystemsAssocActionOk) {
476
445
EXPECT_EQ (exec_err, ECSACT_EXEC_SYS_OK);
477
446
}
478
447
448
+ TEST (Core, AddAssocOk) {
449
+ ecsact_set_system_execution_impl (
450
+ ecsact_id_cast<ecsact_system_like_id>(runtime_test::AssocTestAction::id),
451
+ &runtime_test__AssocTestAction
452
+ );
453
+ ecsact_set_system_execution_impl (
454
+ ecsact_id_cast<ecsact_system_like_id>(runtime_test::AddAssocTest::id),
455
+ &runtime_test__AddAssocTest
456
+ );
457
+
458
+ auto reg = ecsact::core::registry (" AddAssocOk" );
459
+ auto test_entity1 = reg.create_entity ();
460
+ reg.add_component (
461
+ test_entity1,
462
+ runtime_test::ComponentA{
463
+ .a = 42 ,
464
+ }
465
+ );
466
+
467
+ auto test_entity2 = reg.create_entity ();
468
+ reg.add_component <runtime_test::AddAssocTestTag>(test_entity2);
469
+
470
+ auto options = ecsact_execution_options{};
471
+ auto test_action = runtime_test::AssocTestAction{
472
+ .assoc_entity = test_entity2,
473
+ };
474
+ auto test_action_c = ecsact_action{
475
+ .action_id = runtime_test::AssocTestAction::id,
476
+ .action_data = &test_action,
477
+ };
478
+
479
+ options.actions_length = 1 ;
480
+ options.actions = &test_action_c;
481
+ AddAssocTest_ran = false ;
482
+ AssocTestAction_ran = false ;
483
+ auto exec_err = ecsact_execute_systems (reg.id (), 1 , &options, nullptr );
484
+ EXPECT_TRUE (AddAssocTest_ran) << " AddAssocTest Impl Didn't Executed" ;
485
+ EXPECT_TRUE (AssocTestAction_ran) << " AssocTestAction Impl Didn't Executed" ;
486
+ EXPECT_EQ (exec_err, ECSACT_EXEC_SYS_OK);
487
+
488
+ exec_err = ecsact_execute_systems (reg.id (), 1 , nullptr , nullptr );
489
+ EXPECT_EQ (exec_err, ECSACT_EXEC_SYS_OK);
490
+ }
491
+
479
492
TEST (Core, AssociationEntityCorrectness) {
480
493
using runtime_test::AttackDamage;
481
494
using runtime_test::AttackDamageWeakened;
@@ -585,6 +598,51 @@ TEST(Core, AssociationEntityCorrectness) {
585
598
}
586
599
}
587
600
601
+ TEST (Core, DynamicSystemImpl) {
602
+ auto reg = ecsact::core::registry (" DynamicSystemImpl" );
603
+ auto entity = reg.create_entity ();
604
+ auto other_entity = reg.create_entity ();
605
+
606
+ ComponentA comp{.a = 42 };
607
+ reg.add_component (entity, comp);
608
+ reg.add_component (other_entity, comp);
609
+
610
+ OtherEntityComponent other_comp{.num = 3 , .target = other_entity};
611
+ ASSERT_EQ (reg.add_component (entity, other_comp), ECSACT_ADD_OK);
612
+
613
+ // Sanity check
614
+ ASSERT_TRUE (reg.has_component <ComponentA>(entity));
615
+ ASSERT_EQ (reg.get_component <ComponentA>(entity), comp);
616
+ ASSERT_TRUE (reg.has_component <ComponentA>(other_entity));
617
+ ASSERT_EQ (reg.get_component <ComponentA>(other_entity), comp);
618
+ ASSERT_TRUE (reg.has_component <OtherEntityComponent>(entity));
619
+ ASSERT_EQ (reg.get_component <OtherEntityComponent>(entity), other_comp);
620
+
621
+ ecsact_set_system_execution_impl (
622
+ ecsact_id_cast<ecsact_system_like_id>(runtime_test::SimpleSystem::id),
623
+ &runtime_test__SimpleSystem
624
+ );
625
+
626
+ ecsact_set_system_execution_impl (
627
+ ecsact_id_cast<ecsact_system_like_id>(runtime_test::OtherEntitySystem::id),
628
+ &runtime_test__OtherEntitySystem
629
+ );
630
+
631
+ auto exec_err = ecsact_execute_systems (reg.id (), 1 , nullptr , nullptr );
632
+ ASSERT_EQ (exec_err, ECSACT_EXEC_SYS_OK);
633
+
634
+ // Sanity check
635
+ ASSERT_TRUE (reg.has_component <ComponentA>(entity));
636
+
637
+ auto comp_get = reg.get_component <ComponentA>(entity);
638
+
639
+ EXPECT_NE (comp_get.a , comp.a );
640
+
641
+ // Simulate what the system should be doing.
642
+ comp.a += 2 ;
643
+ EXPECT_EQ (comp_get.a , comp.a );
644
+ }
645
+
588
646
#ifdef ECSACT_ENTT_TEST_STATIC_SYSTEM_IMPL
589
647
TEST (Core, StaticSystemImpl) {
590
648
auto reg_id = ecsact_create_registry (" StaticSystemImpl" );
0 commit comments