Skip to content

feat: nonlinear deposit curve (lever 4) - #39

Merged
tamirelazar merged 10 commits into
devfrom
feat/nonlinear-deposit
Jun 18, 2026
Merged

feat: nonlinear deposit curve (lever 4)#39
tamirelazar merged 10 commits into
devfrom
feat/nonlinear-deposit

Conversation

@tamirelazar

Copy link
Copy Markdown
Owner

Lever 4 — Nonlinear deposit

Adds a per-frame deposit-accumulation buffer with a selectable nonlinear curve so density spikes compress into filaments instead of blowing out to flat blobs. Fully off by default — byte-identical to current behavior.

How it works

Agents accumulate their existing per-agent unit (deposit_amount · dt) into a per-TrailMap scratch buffer (mirrors the lever-7 blend_src pattern). Once per frame, before diffuse/decay, a fold pass applies curve(accum) · scale, an optional clamp cap, adds the result to the trail, and zeros the buffer.

The accumulation path is gated: when curve=linear && scale=1 && cap=0, the buffer is never touched and deposits go straight to the trail (the existing code path) — so the off case is byte-identical by construction, avoiding the float-reassociation drift a naive accumulate-then-fold would introduce.

Curves

  • linearx (identity, default)
  • sqrtx.sqrt() (compresses density → filaments)
  • logln(1 + x) (log1p; 0 at 0, guards log(0))
  • powx.powf(gamma) (--deposit-gamma is the exponent)

Knobs

--deposit-curve <linear|sqrt|log|pow>, --deposit-scale, --deposit-gamma, --deposit-cap (0 = off). All on SimConfig (mirrors lever-7 decay_gamma/diffuse_weight); CLI flags + saved-config round-trip (serde(default) back-compat). Buffer is per-TrailMap, giving per-species structure in separate-trails mode for free. Per-preset tuning is intentionally deferred to the showcase-preset work.

Testing

  • Unit tests per curve; deposit_off_path_is_deterministic and a linear-accum fp-equivalence test (active identity config matches the direct path within a magnitude-relative tolerance, accounting for float reassociation); deposit_sqrt_curve_changes_output.
  • Saved-config round-trip + old-TOML-loads-with-defaults back-compat.
  • cargo test 800 pass · cargo test --all-features --lib 812 pass · cargo clippy --all-targets --all-features -- -D warnings clean.
  • 47/47 visual-regression goldens unchanged (defaults are the off path).
  • Empirical same-seed capture: linear and pow γ=1 identical to baseline; sqrt/log/pow γ=0.5 differ sensibly.
  • Added bench_fold_deposits_sqrt.

Closes #31.

@tamirelazar
tamirelazar merged commit 4ca30b4 into dev Jun 18, 2026
3 checks passed
@tamirelazar
tamirelazar deleted the feat/nonlinear-deposit branch June 18, 2026 17:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant