@@ -789,7 +789,8 @@ TEST(Core, CreateAndDestroyEntity) {
789
789
ecsact_placeholder_entity_id placeholder_entity_id;
790
790
};
791
791
792
- auto info = callback_info{};
792
+ auto created_entity = ecsact_invalid_entity_id;
793
+ auto info = std::optional<callback_info>{};
793
794
auto options = ecsact::core::execution_options{};
794
795
auto evc = ecsact::core::execution_events_collector<>{};
795
796
@@ -798,42 +799,55 @@ TEST(Core, CreateAndDestroyEntity) {
798
799
ecsact_entity_id entity_id,
799
800
ecsact_placeholder_entity_id placeholder_entity_id
800
801
) {
801
- info.entity_created = true ;
802
- info.entity_id = entity_id;
803
- info.placeholder_entity_id = placeholder_entity_id;
802
+ info = callback_info{};
803
+ info->entity_created = true ;
804
+ info->entity_id = entity_id;
805
+ info->placeholder_entity_id = placeholder_entity_id;
806
+ created_entity = entity_id;
804
807
}
805
808
);
806
809
807
810
evc.set_entity_destroyed_callback ([&](ecsact_entity_id entity_id) {
808
- info.entity_destroyed = true ;
809
- info.entity_id = entity_id;
811
+ info = callback_info{};
812
+ info->entity_destroyed = true ;
813
+ info->entity_id = entity_id;
810
814
});
811
815
812
816
options.create_entity (static_cast <ecsact_placeholder_entity_id>(42 ))
813
817
.add_component (&component_a);
814
818
auto exec_err = reg.execute_systems (std::array{options}, evc);
815
819
EXPECT_EQ (exec_err, ECSACT_EXEC_SYS_OK);
816
820
817
- ASSERT_TRUE (info.entity_created );
818
- ASSERT_FALSE (info.entity_destroyed );
821
+ ASSERT_TRUE (info.has_value ());
822
+ ASSERT_TRUE (info->entity_created );
823
+ ASSERT_FALSE (info->entity_destroyed );
824
+ ASSERT_EQ (info->entity_id , created_entity);
819
825
ASSERT_EQ (reg.count_entities (), 1 );
820
826
821
827
EXPECT_EQ (
822
- info. placeholder_entity_id ,
828
+ info-> placeholder_entity_id ,
823
829
static_cast <ecsact_placeholder_entity_id>(42 )
824
830
);
825
831
826
- auto comp = reg.get_component <runtime_test::EntityTesting>(info. entity_id );
832
+ auto comp = reg.get_component <runtime_test::EntityTesting>(info-> entity_id );
827
833
828
834
ASSERT_EQ (comp.a , 6 );
829
835
830
836
options.clear ();
831
- options. destroy_entity ( info. entity_id ) ;
837
+ info = std::nullopt ;
832
838
839
+ // Make sure create doesn't get called again
840
+ exec_err = reg.execute_systems (std::array{options}, evc);
841
+ ASSERT_EQ (exec_err, ECSACT_EXEC_SYS_OK);
842
+ ASSERT_FALSE (info.has_value ());
843
+
844
+ options.destroy_entity (created_entity);
845
+ info = std::nullopt;
833
846
exec_err = reg.execute_systems (std::array{options}, evc);
834
847
ASSERT_EQ (exec_err, ECSACT_EXEC_SYS_OK);
835
848
ASSERT_EQ (reg.count_entities (), 0 );
836
- ASSERT_TRUE (info.entity_destroyed );
849
+ ASSERT_TRUE (info.has_value ());
850
+ ASSERT_TRUE (info->entity_destroyed );
837
851
}
838
852
839
853
TEST (Core, MultiPkgUpdate) {
0 commit comments