How ci4ic4/life works
Purpose and entry points
This repository implements a watchable spatial-ecology cellular simulation: pine martens suppress invasive grey squirrels, enabling native red squirrels to recover. The active Rust workspace separates application orchestration, simulation logic, GPU stepping, and rendering. Primary executable entry points are crates/life-app/src/main.rs and crates/life-app/src/app.rs. Legacy browser-facing prototypes remain at life-ecology.html, life-ecology-core.js, and related HTML/JS files.
Application orchestration
life-app is the composition layer that initializes and coordinates the simulation, graphics, and user-facing runtime loop. It should be the boundary where the core model, GPU backend, and renderer are selected and connected.
• crates/life-app/src/main.rs
• crates/life-app/src/app.rs
• crates/life-app/Cargo.toml
Core ecology and cellular-state model
life-core defines the domain model independent of graphics: grid state, topology, rules, stochastic probability handling, terrain, and simulation statistics. Its model is an ecology CA rather than conventional B/S Life: prey growth is contact-process-like and predation is conserved/WaTor-style, with marten/red/grey asymmetry central to the rules.
• crates/life-core/src/grid.rs
• crates/life-core/src/rule.rs
• crates/life-core/src/evolve.rs
Simulation evolution and experiments
Core evolution appears split between ordinary stepping, evolved/environmental behavior, detection, and trial execution. This is the natural CPU-side control-flow boundary: initialize a grid and rules, repeatedly evolve state, detect outcomes or stability, and aggregate statistics for presentation or search.
• crates/life-core/src/evolve.rs
• crates/life-core/src/detect.rs
• crates/life-core/src/trial.rs
Spatial environment and topology
Terrain and topology are explicit model inputs rather than renderer-only concerns. They likely control neighborhood/wrapping semantics and habitat effects, supporting the repository’s stated future habitat distinction (conifer favoring reds; broadleaf favoring greys).
• crates/life-core/src/topology.rs
• crates/life-core/src/terrain.rs
• crates/life-core/src/prob.rs
GPU simulation backend
life-gpu provides a GPU implementation or acceleration path for simulation stepping. Rust context/simulation modules manage GPU resources and dispatch; WGSL shaders encode standard, stochastic, and evolutionary step kernels. This is the key boundary between domain state and device-resident buffers/compute execution.
• crates/life-gpu/src/context.rs
• crates/life-gpu/src/sim.rs
• crates/life-gpu/src/step_stoch.wgsl
Rendering and interaction
life-render turns simulation state into a drawable mesh and GPU shaders, with camera and picking support for spatial inspection. It is deliberately separate from evolution, so visualization and interaction should consume state without owning ecological rules.
• crates/life-render/src/lib.rs
• crates/life-render/src/mesh.rs
• crates/life-render/src/pick.rs
Runtime, infrastructure, and migration context
The material runtime is Rust/Cargo, organized as a multi-crate workspace (Cargo.toml), with GPU shader programs in WGSL. CI is defined in .github/workflows/ci.yml. The root HTML/JS assets represent prior Life-suite and ecology implementations; Rust rewrite and ecology design documents indicate an active migration/specification trail rather than a separate service architecture.
• Cargo.toml
• .github/workflows/ci.yml
• docs/superpowers/specs/2026-07-14-life-ecology-design.md
Main entry points: evolve.rs CPU evolution · Cargo.toml Cargo workspace · app.rs Runtime orchestration · sim.rs GPU simulation
Components 17
Application
- Executable entry
crates/life-app/src/main.rs - Runtime orchestration · Selects and connects core stepping, GPU execution, and rendering.
crates/life-app/src/app.rs
Ecology Core
- Grid state
crates/life-core/src/grid.rs - Ecology rules · Encodes asymmetric marten, red squirrel, and grey squirrel dynamics.
crates/life-core/src/rule.rs - CPU evolution
crates/life-core/src/evolve.rs - Detection & trials · Detects outcomes and aggregates repeated simulation runs.
crates/life-core/src/trial.rs - Terrain, topology & probability · Supplies habitat, neighborhood semantics, and stochastic behavior.
crates/life-core/src/terrain.rs
GPU Simulation
- GPU context
crates/life-gpu/src/context.rs - GPU simulation · Manages device-resident state and compute stepping.
crates/life-gpu/src/sim.rs - Stochastic step shader
crates/life-gpu/src/step_stoch.wgsl
Rendering
- Renderer · Visualizes simulation state without owning ecological rules.
crates/life-render/src/lib.rs - State mesh
crates/life-render/src/mesh.rs - Spatial picking
crates/life-render/src/pick.rs
Runtime & Migration
- Cargo workspace · Builds and composes the active multi-crate runtime.
Cargo.toml - CI pipeline
.github/workflows/ci.yml - Legacy browser prototype · Prior browser-facing ecology implementation retained during the Rust migration.
life-ecology.html - Ecology design spec · Records the active ecology model and migration direction.
docs/superpowers/specs/2026-07-14-life-ecology-design.md
Connections 21
- Cargo workspace → Executable entry: builds
- Cargo workspace → CPU evolution: builds
- Cargo workspace → GPU simulation: builds
- Cargo workspace → Renderer: builds
- CI pipeline → Cargo workspace: validates
- Executable entry → Runtime orchestration: starts
- Runtime orchestration → CPU evolution: runs CPU path
- Runtime orchestration → GPU simulation: runs GPU path
- Runtime orchestration → Renderer: drives
- CPU evolution → Grid state: updates
- CPU evolution → Ecology rules: applies
- CPU evolution → Terrain, topology & probability: uses
- Detection & trials → CPU evolution: repeats
- GPU simulation → GPU context: uses
- GPU simulation → Stochastic step shader: dispatches
- GPU simulation → Grid state: uploads/downloads state
- Renderer → State mesh: builds
- Renderer → Spatial picking: supports
- Renderer → Grid state: visualizes
- Ecology design spec → Ecology rules: specifies
- Legacy browser prototype → Runtime orchestration: superseded by