Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored Query mechanisn - Nesting mechanics. #111

Merged
merged 13 commits into from Mar 15, 2021

Conversation

AndreaCatania
Copy link
Member

@AndreaCatania AndreaCatania commented Mar 14, 2021

  • Refactored the Query mechanics, so it's now possible to combine the filters for fine-grained result!
  • Removed Without filter in favor of Not.
  • Now the Query return a QueryResultTuple (before it was returning std::tuple).
  • Add QueryResultTuple for a great control over the query unpacking mechanism.
  • Refactored the Any filter: Now it returns all the Components if one filter is satisfied.
  • Add Join filter: Collapse many components to one.
  • Refactored all the Filters to allow nesting.
// Take all entities with transform component
Query<Transform> query;
for( auto [ transform ] : query ) {}


// Take the entities Position, Rotation and Scale, if one of those change.
Query<Any<Changed<Position>, Changed<Rotation>, Changed<Scale>>> query;
for( auto [ position, rotation, scale ] : query ) {}


// Take the enemies and its team.
Query<Enemy, Join<TeamA, TeamB, TeamC>> query;
for( auto [ enemy, team ] : query ) {}


// Take the enemies whom name OR team changed
Query<Enemy, Any<Changed<Name>, Join<Changed<TeamA>, Changed<TeamB>, Changed<TeamC>>> query;
for( auto [ enemy, name, team ] : query ) {}


// Take the player, if its health didn't change.
Query<Player, Not<Changed<Health>>> query;
for( auto [ player, health ] : query ) {}


// Take the Speedups assigned to the character if changed.
Query<Character, Batch<Changed<Speedup>>> query;
for( auto [ charcter, speedups ] : query ) {}


// Take all the EntityID for the crates.
Query<EntityID, Crate> query;
for( auto [ entity, crate ] : query ) {}

The new type `QueryResultTuple_impl` is the new `Query` return type.
It allow to have total control over the `Query` return type, so it's now possible to
nest multiple filters, for fine grained fetching, while keeping the
tuple unwrapping flat and easy to handle.
Can be used to extract the type of a specific query element, by Index.
The query supports all the filters now.
Implemented:
- No filter
- Maybe
- Without
- Changed
- Batch

Need to finish:
- Join
- Any
The new fetching mechanism allow to nest the filters, for a more
fine-grained result.

The new fetching uses the new `QueryResultTuple` instead of `std::tuple`.
The new Any filter, returns all its sub components if at least one
filter is satisfied.

As before, the Any filter allow to nest some filters like `Maybe`,
   `Without`, `Changed`, `Batch`.
Returns the first component that satisfy the sub filters.
The `Not` filter is a negation filter (similar to `!`).
It can be nested, and returns the component if satisfied.
@AndreaCatania
Copy link
Member Author

Wiki updated: https://github.com/GodotECS/godex/wiki/Query

@AndreaCatania AndreaCatania merged commit 3f792ca into GodotECS:main Mar 15, 2021
@AndreaCatania AndreaCatania deleted the pro_query_filters branch March 15, 2021 08:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant