diff --git a/dGame/dEntity/EntitySystem.h b/dGame/dEntity/EntitySystem.h index 7d57b5c54..7fc64a340 100644 --- a/dGame/dEntity/EntitySystem.h +++ b/dGame/dEntity/EntitySystem.h @@ -69,8 +69,13 @@ class EntitySystem final { struct ArchetypeVariants final { std::vector data; - template - std::vector& begin() { return &data[0]; } + auto begin() { + return data.begin(); + } + + auto end() { + return data.end(); + } }; diff --git a/tests/dGameTests/dEntitiesTests/ArchetypeTests.cpp b/tests/dGameTests/dEntitiesTests/ArchetypeTests.cpp index 539c1270d..d86386f61 100644 --- a/tests/dGameTests/dEntitiesTests/ArchetypeTests.cpp +++ b/tests/dGameTests/dEntitiesTests/ArchetypeTests.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -283,6 +284,16 @@ namespace { } } }; + + template + struct TestContainerVisitor2 { + std::vector* const operator()(auto&& archetype) { + using ArchetypeType = std::remove_pointer_t>; // Needed to fix a MacOS issue + + if constexpr (!ArchetypeType::template HasComponent()) return nullptr; + else return &archetype->template Container(); + } + }; } TEST_F(ArchetypeTest, IterateOverArchetypesTest) { @@ -318,8 +329,19 @@ TEST_F(ArchetypeTest, IterateOverArchetypesTest) { //ContainerVisitor const auto& archetypes = entitySystem->m_Archetypes; - for (auto& archetypeVariantPtr : archetypes) { + /*for (auto& archetypeVariantPtr : archetypes) { std::visit(TestContainerVisitor(), archetypeVariantPtr); // Does the update loop test + }*/ + + for (const auto& archetypeVariantPtr : archetypes) { + auto&& destCompCont = std::visit(TestContainerVisitor2(), archetypeVariantPtr); + if (!destCompCont) continue; + + for (auto& destComp : *destCompCont) { + const auto randNum = rand(); + destComp.SetArmor(randNum); + ASSERT_EQ(randNum, destComp.GetArmor()); + } } /*for (auto& archetypeVariantPtr : archetypes) { // For the archetypes in m_Archetypes