Skip to content

Add query filters#245

Merged
waynemwashuma merged 10 commits into
wimaengine:devfrom
waynemwashuma:query-filter
Sep 10, 2025
Merged

Add query filters#245
waynemwashuma merged 10 commits into
wimaengine:devfrom
waynemwashuma:query-filter

Conversation

@waynemwashuma
Copy link
Copy Markdown
Collaborator

@waynemwashuma waynemwashuma commented Sep 10, 2025

Objective

Introduces query filters to enhance the ECS query capabilities. Query filters add powerful new ways to filter entities arbitrarily e.g based on component presence or absence.

The query system has been enhanced with the following:

  • QueryFilter: The interface which provides a base for other filters to be implemented on.
  • Has filter: Includes entities that have the specified component
  • Without filter: Exclude entities that have the specified component

The filters are composable i.e multiple filters can be combined in a single query.
More filters can be added in the future as this change provides the base for more filters.

Note

The filters work at the archetype level for now but can be adapted to per entity filtering.

Showcase

Using query filters is straightforward:

// Query entities of which we will read/modify `ComponentA` but it should have `ComponentB` and without `ComponentC`.
const query = new Query(world, [ComponentA], [has(ComponentB), without(ComponentC)])

// Count matching entities
const count = query.count()

// Iterate through filtered results
query.each(([componentA]) => {
  // Process filtered entities
})

Migration Guide

Existing queries continue to work unchanged. To use filters, add them as the third parameter to Query constructor.

Checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.

@waynemwashuma waynemwashuma self-assigned this Sep 10, 2025
@waynemwashuma waynemwashuma added type:enhancement New feature or request mod:ecs labels Sep 10, 2025
@waynemwashuma waynemwashuma changed the title Query filter Add query filters Sep 10, 2025
@waynemwashuma waynemwashuma marked this pull request as ready for review September 10, 2025 18:33
@waynemwashuma waynemwashuma merged commit a578b33 into wimaengine:dev Sep 10, 2025
5 checks passed
@waynemwashuma waynemwashuma deleted the query-filter branch September 10, 2025 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:ecs type:enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant