component.spatialsystem
Keeps track of spatial relations between objects with volumes.
- class SpatialSystem: component.system.System;
Keeps track of spatial relations between objects with volumes.
Implemented as a simple grid that keeps track of which entities are in which cells.
- this(EntitySystem entitySystem, const(Vector2!(float)) center, const(float) cellSize, const(ubyte) gridSize);
Construct a SpatialSystem.
Parameters:EntitySystem entitySystem EntitySystem whose entities we're processing. const(Vector2!(float)) center Center of the grid in world space. const(float) cellSize Size of a single cell of the grid (both x and y). const(ubyte) gridSize Size of the grid in cells (both x and y). Must be > 0 and <= 254 (yes, 254, not 255). - void update();
Determine spatial relations between entities.
- final auto neighbors(ref PhysicsComponent physics, ref VolumeComponent volume);
Iterate over all neighbors of entity with specified physics and volume component.
This iterates over a ref Entity, ref PhysicsComponent and ref VolumeComponent.
Examples:
Note that if physics and volume belong to an entity, that entity will be iterated as well.//spatial is our SpatialSystem //ourPhysics is our PhysicsComponent //ourVolume is our VolumeComponent foreach(ref Entity entity, ref PhysicsComponent physics, ref VolumeComponent volume; spatial.neighbors(ourPhysics, ourVolume)) { //do stuff }