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

Spatial Hashing #31

Merged
merged 52 commits into from
Dec 24, 2024
Merged

Spatial Hashing #31

merged 52 commits into from
Dec 24, 2024

Conversation

aevyrie
Copy link
Owner

@aevyrie aevyrie commented Jul 16, 2024

Implements spatial hashing, to performantly run distance checks, find all entities located in the same cell, or neighboring cells.

Finding all entities in a GridCell is a single pre-hashed lookup, so it only takes ~ns. Finding all entities in a cell and its 26 neighbors takes only ~100ns. You can query for neighbors within any radius, but this becomes exponentially more expensive. This also provides a neighbors_flood to find all contiguous cells that have entities in them, recursively. This is useful to find islands of occupied cells, intended to be used for placing physics simulation instances. Neighbor flood is extremely dependent on the amount of objects and their arrangement in the scene, in this case it takes 1.6ms.

The numbers above come from the added benchmarks, running on a MPB M3 Max, with 10,000 entities moving around a cube of 50 cells^3.

@aevyrie
Copy link
Owner Author

aevyrie commented Dec 17, 2024

Partitioning:
image

@aevyrie aevyrie enabled auto-merge (squash) December 24, 2024 02:26
@aevyrie aevyrie merged commit 6629594 into main Dec 24, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant