-
Notifications
You must be signed in to change notification settings - Fork 2
ChunkQuery
Martin Evans edited this page Aug 13, 2024
·
3 revisions
A chunk query is the same as a Query
and has all the same overloads. However, instead of executing code one entity at a time, entire chunks are passed together. The size of chunks is not fixed to one value, it may be as small as one entity (for example, if there is only one entity that matches the query). Every entity in a chunk has an identical set of components, the structure of all entities in the chunk can be checked using the ChunkHandle
.
This can be faster when dealing with very large numbers of entities.
public struct ExampleQueryType
: IChunkQuery2<Component1, Component2>
{
public void Execute(ChunkHandle chunk, ReadOnlySpan<Entity> e, Span<Component1> c1, Span<Component2> c2) { /* whateever */ }
}
void DoQuery()
{
world.ExecuteChunk<ExampleQueryType, Component1, Component2>();
}
There is a parallel mode of chunk queries available, which will execute all chunks in parallel.
void DoParallelQuery()
{
world.ExecuteChunkParallel<ExampleQueryType, Component1, Component2>();
}