java.lang.Object
technology.sola.engine.physics.utils.SpatialHashMap
The SpatialHashMap class is a spatial hashmap implementation that maps
Entity
into a
bucket with other entities based on its 2D coordinate. This helps reduce the number of collision checks that are
needed during broad phase collision detection.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
BucketId holds the top, left coordinate that identifies a bucket. -
Constructor Summary
ConstructorsConstructorDescriptionSpatialHashMap
(Collection<technology.sola.ecs.view.View2Entry<ColliderComponent, TransformComponent>> viewEntries) Creates a SpatialHashMap with cellSize set to twice the max width/height of the largestEntity
.SpatialHashMap
(Collection<technology.sola.ecs.view.View2Entry<ColliderComponent, TransformComponent>> viewEntries, int cellSize) Creates a SpatialHashMap with desired cell size. -
Method Summary
Modifier and TypeMethodDescriptionint
List<technology.sola.ecs.view.View2Entry<ColliderComponent,
TransformComponent>> getNearbyViewEntries
(technology.sola.ecs.view.View2Entry<ColliderComponent, TransformComponent> viewEntry) Returns a list ofViewEntry
containing an Entity that is in the same bucket as the entity to check.
-
Constructor Details
-
SpatialHashMap
public SpatialHashMap(Collection<technology.sola.ecs.view.View2Entry<ColliderComponent, TransformComponent>> viewEntries) Creates a SpatialHashMap with cellSize set to twice the max width/height of the largestEntity
.- Parameters:
viewEntries
- the list ofView2Entry
ofColliderComponent
andTransformComponent
-
SpatialHashMap
public SpatialHashMap(Collection<technology.sola.ecs.view.View2Entry<ColliderComponent, TransformComponent>> viewEntries, int cellSize) Creates a SpatialHashMap with desired cell size. Ensure that the cellSize is greater than the max width or height of the largestEntity
.- Parameters:
viewEntries
- the list ofView2Entry
ofColliderComponent
andTransformComponent
cellSize
- the cell size of the SpatialHashMap
-
-
Method Details
-
getCellSize
public int getCellSize()- Returns:
- the current cell size of this spatial hashmap
-
getNearbyViewEntries
public List<technology.sola.ecs.view.View2Entry<ColliderComponent,TransformComponent>> getNearbyViewEntries(technology.sola.ecs.view.View2Entry<ColliderComponent, TransformComponent> viewEntry) Returns a list ofViewEntry
containing an Entity that is in the same bucket as the entity to check.- Parameters:
viewEntry
- the view entry containing the entity to check- Returns:
- list of nearby entities
-
getBucketIds
- Returns:
- the set of current
SpatialHashMap.BucketId
s
-