viva_tensor/horde

Horde - Massively Parallel Entity Physics

A Structure-of-Arrays (SoA) physics engine optimized for 10,000+ entities. Data is stored in contiguous buffers (Positions, Velocities) for SIMD acceleration.

Ideal for: particle systems, boids, swarms, and massive game entities.

Types

Horde reference (physics engine state)

pub type Horde =
  ffi.HordeRef

Values

pub fn dampen(
  horde: ffi.HordeRef,
  friction: Float,
) -> ffi.HordeRef

Apply damping (friction)

Velocities *= friction (0.0 to 1.0)

pub fn integrate(horde: ffi.HordeRef, dt: Float) -> ffi.HordeRef

Advance simulation by dt (seconds)

Positions += Velocities * dt

pub fn kinetic_energy(horde: ffi.HordeRef) -> Float

Get total kinetic energy of the system

pub fn new(count: Int, dims: Int) -> ffi.HordeRef

Create a new Horde

  • count: Number of entities
  • dims: Dimensions per entity (1, 2, or 3)
pub fn positions(horde: ffi.HordeRef) -> List(Float)

Get current positions

pub fn set_positions(
  horde: ffi.HordeRef,
  data: List(Float),
) -> ffi.HordeRef

Set positions for all entities

Data must be a flat list: [x0, y0, x1, y1, …]

pub fn set_velocities(
  horde: ffi.HordeRef,
  data: List(Float),
) -> ffi.HordeRef

Set velocities for all entities

pub fn velocities(horde: ffi.HordeRef) -> List(Float)

Get current velocities

pub fn wrap(
  horde: ffi.HordeRef,
  max_bound: Float,
) -> ffi.HordeRef

Wrap positions torus-style

If pos > max, pos -= max

Search Document