Query
The Query, a way to select and iterate entities
A Query
is a view of the World and targets a specific set of entities. It only consists of a QueryDescription
, which specifies which entities with which structure are being searched for. You can specify which components an entity should definitely have, which it should perhaps have and which it should not have at all. It is also possible to search only for the exclusive structure of an entity. Let's take a look at this!
All
A normal iteration targets entities WITH specific components. In this example, we want to iterate over all entities that have Position
and Velocity
to move them.
The methods of the QueryDescription
can accept up to 25 generic parameters and can be chained together. Can also be created without generics by passing Signature
. There multiple different Query-Variants
. More on this later.
It doesn't matter whether they are dwarves, elves or humans. As long as they have the Position & Velocity components, they move!
Any
But what if we need more filters to have all entities except some specific ones? For example, everyone with a Pickaxe
EXCEPT Elves
to mine ores. It's time to make the queries a little more complex.
You do not necessarily have to pass the entity in a Query
.
None
But there is another important filter. Imagine we are attacked and we now want to call all entities with a weapon to the defense. So we need everyone who has ANY weapon.
Exclusive
There is another case of filters. Sometimes we want to search for entities that have an exclusive set of components. No more and no less than that. In our example, a new type of dwarf that no longer wears pickaxes.
You want to give them an exclusive task. But how do we tell them apart from the rest? With one of those?
No. Both QueryDescriptions
would also target dwarfs that have additional components (e.g. [Dwarf, Position, Velocity, Bow
]). We do not want that.
Instead, we only want to target this one type of dwarf. No more or less components on them.
Next, perhaps we should take a look at what's under the hood of Arch.
Last updated
Was this helpful?