Skip to content

Commit

Permalink
More iteration testing
Browse files Browse the repository at this point in the history
  • Loading branch information
jadebenn committed Jan 22, 2024
1 parent ff60255 commit 0107076
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
9 changes: 7 additions & 2 deletions dGame/dEntity/EntitySystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ class EntitySystem final {
struct ArchetypeVariants final {
std::vector<ArchetypeVariantPtr> data;

template <typename T>
std::vector<T>& begin() { return &data[0]; }
auto begin() {
return data.begin();
}

auto end() {
return data.end();
}

};

Expand Down
24 changes: 23 additions & 1 deletion tests/dGameTests/dEntitiesTests/ArchetypeTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <gtest/gtest.h>

#include <algorithm>
#include <ranges>

Check failure on line 5 in tests/dGameTests/dEntitiesTests/ArchetypeTests.cpp

View workflow job for this annotation

GitHub Actions / Build & Test (macos-11)

'ranges' file not found
#include <typeindex>
#include <unordered_set>

Expand Down Expand Up @@ -283,6 +284,16 @@ namespace {
}
}
};

template <typename T>
struct TestContainerVisitor2 {
std::vector<T>* const operator()(auto&& archetype) {
using ArchetypeType = std::remove_pointer_t<std::remove_reference_t<decltype(*archetype)>>; // Needed to fix a MacOS issue

if constexpr (!ArchetypeType::template HasComponent<T>()) return nullptr;
else return &archetype->template Container<T>();
}
};
}

TEST_F(ArchetypeTest, IterateOverArchetypesTest) {
Expand Down Expand Up @@ -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<DestroyableComponent>(), archetypeVariantPtr); // Does the update loop test
}*/

for (const auto& archetypeVariantPtr : archetypes) {
auto&& destCompCont = std::visit(TestContainerVisitor2<DestroyableComponent>(), 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
Expand Down

0 comments on commit 0107076

Please sign in to comment.