Skip to content

Commit

Permalink
fix(ecs): filter relation tables correctly by type
Browse files Browse the repository at this point in the history
  • Loading branch information
RiscadoA committed Jan 24, 2024
1 parent f6b365b commit 54e1a97
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions core/include/cubos/core/ecs/query/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions core/src/cubos/core/ecs/query/filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ QueryFilter::QueryFilter(World& world, const std::vector<QueryTerm>& 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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 54e1a97

Please sign in to comment.