Bevy Scoped Queries & Entities proposal. #14918
RylanYancey
started this conversation in
Ideas
Replies: 1 comment
-
Generally I think that spatial partitioning strategies like quad trees are the way to go here :) Indexes (#4513) are currently possible, but not as reliable / well-integrated as I'd like. See that issue for more thoughts on how to improve this. #13464 is also related, as you could use a space filling curve or a similar ordering to speed up checks. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have slowly been building up expertise around ECS for the past few years and contemplating about how I would implement a high-performance sandbox minecraft-like game. However, I run into a major problem.
The Problem
When there are many, many players on a single world, a majority of the checks that occur are between entities that are nowhere near each other. This problem becomes exponentially worse the larger the world and more spread out the players. For example, I have a system where I need to update whether enemies can see the player. This system might look like this:
The problem is that the number of checks is the enemy count times the player count, which is an O(n^2) operation and a major contributor to runtime performance, especially given that a majority of the checks are between enemies and players that are so far away that are too far away to interact with each other.
Minecraft handles this particular check by a combination of infrequently and randomly running visibility checks and basing visibility on whether the player is looking at the enemy, but this can result in strange behaviour where enemies take several seconds to notice a player right next to them, and becomes increasingly apparent the more players exist in a world.
Solution: Scoped Queries
When an entity is spawned, I want to assign it a scope based on its transform. Scope may be defined like so:
I could create a scoped entity with
commands
.The Bevy ECS could then store the scope in the archetype table.
To iterate by scope, there could be a trait 'ScopeFilter', which could be used to implement scoped queries.
Then I could create a system to update the scope based on changed transforms.
With all of this in place, our query can be changed to look like this:
This would drastically reduce the number of checks that have to be done, and allow for many more players, and entities, to exist on a single ECS instance.
Beta Was this translation helpful? Give feedback.
All reactions