From 54e1a97110420e93cc7c3fc9cd9dc87f54314316 Mon Sep 17 00:00:00 2001 From: Ricardo Antunes Date: Tue, 23 Jan 2024 15:58:54 +0000 Subject: [PATCH] fix(ecs): filter relation tables correctly by type --- core/include/cubos/core/ecs/query/filter.hpp | 3 +++ core/src/cubos/core/ecs/query/filter.cpp | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/core/include/cubos/core/ecs/query/filter.hpp b/core/include/cubos/core/ecs/query/filter.hpp index 23badc6bf..37175b67e 100644 --- a/core/include/cubos/core/ecs/query/filter.hpp +++ b/core/include/cubos/core/ecs/query/filter.hpp @@ -68,6 +68,9 @@ namespace cubos::core::ecs /// @brief Holds the necessary data for each link. struct Link { + /// @brief Relation data type. + DataTypeId dataType; + /// @brief From target index. int fromTarget; diff --git a/core/src/cubos/core/ecs/query/filter.cpp b/core/src/cubos/core/ecs/query/filter.cpp index 31ad03da1..e6516f113 100644 --- a/core/src/cubos/core/ecs/query/filter.cpp +++ b/core/src/cubos/core/ecs/query/filter.cpp @@ -55,6 +55,7 @@ QueryFilter::QueryFilter(World& world, const std::vector& terms) { CUBOS_ASSERT(mLinkCount < MaxLinkCount, "Currently only {} links are supported", MaxLinkCount); mTermCursors.emplace_back(mTargetCount + mLinkCount); + mLinks[mLinkCount].dataType = term.type; mLinks[mLinkCount].fromTarget = term.relation.fromTarget; mLinks[mLinkCount].toTarget = term.relation.toTarget; ++mLinkCount; @@ -146,6 +147,11 @@ void QueryFilter::update() // Collect all tables which match any of the target archetypes. link.seenCount = mWorld.tables().sparseRelation().collect(link.tables, link.seenCount, [&](SparseRelationTableId id) { + if (id.dataType != link.dataType) + { + return false; + } + // The from archetype must be one of the from target archetypes. bool found = false; for (const auto& archetype : mTargets[link.fromTarget].archetypes)