Simulation runtime for the Unstable Kernel ecosystem. Provides the foundational infrastructure that all other simulation crates build on.
graph LR
subgraph "kernel-sim"
C[components<br/>Position, Velocity, Energy]
S[spatial<br/>hash grid, neighbor queries]
M[movement<br/>toroidal wrapping]
E[environment<br/>obstacles, food sources]
end
S --> C
M --> C
E --> C
| Module | Responsibility |
|---|---|
components |
Core data types: Position, Velocity, Species, Energy |
spatial |
Spatial hash grid for O(1) neighbor lookups on toroidal domains |
movement |
Position update with velocity integration and edge wrapping |
environment |
Static world elements: obstacles, food sources, terrain |
use kernel_sim::{components::*, spatial::SpatialHash, movement::movement_system};
let mut positions = vec![Position { x: 100.0, y: 200.0 }];
let velocities = vec![Velocity { x: 1.5, y: -0.8 }];
// Move agents
movement_system(&mut positions, &velocities, 1200.0, 800.0, 1.0/60.0);
// Query neighbors
let mut grid = SpatialHash::new(1200.0, 800.0, 50.0);
grid.rebuild(&positions);
let nearby = grid.query_radius(&positions, 0, 50.0);The spatial hash divides the world into cells of size equal to the query radius. Neighbor lookups check only adjacent cells, giving O(1) amortized performance for uniform distributions.
Supports toroidal (wrap-around) distance calculations for seamless edge behavior.
cargo testMIT