Files
settled-reach/server/src/workers/mod.rs
T
jpmschweitzerandClaude Opus 4.6 0098ee5a41 feat(simulation): background worker pool infrastructure (#843 Part C)
Generic BackgroundWorkerPool<Req, Resp> with crossbeam channels, closure
handlers, and 3 delivery strategies (Fallback, GracefulDegrade, ModalLock).

Stub workers registered as Bevy resources:
  - ChunkGenWorker (2 threads) — terrain/props/navmesh generation
  - NpcPrepWorker (1 thread) — pre-compute NPC state for incoming areas
  - OffscreenTickWorker (1 thread) — advance NPCs outside active tier

Tick loop integration:
  - PreInput: poll_worker_results drains completed work
  - PostSnapshot: push_worker_requests queues new work (no-op until Phase 5)

Handlers are stubs — real computation plugs in when the phases that need
them arrive. The infrastructure (channels, threads, push/poll, shutdown)
is real and tested.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 00:15:05 +02:00

29 lines
1.2 KiB
Rust

//! Background worker infrastructure (#843 Part C).
//!
//! Generic thread pool for off-tick computation. Workers run on dedicated
//! threads, separate from the Bevy tick loop. The tick loop pushes requests
//! (non-blocking) and polls for results (non-blocking).
//!
//! Each worker type is a Bevy `Resource` wrapping a typed `BackgroundWorkerPool`.
//! Systems in `TickPhase::PreInput` poll results; systems in `TickPhase::PostSnapshot`
//! push new requests.
//!
//! ## Determinism (D-010)
//!
//! Workers preserve determinism through request-at-tick, deliver-complete:
//! - Inputs come from the deterministic tick loop (same seed → same requests)
//! - Outputs are deterministic per input (seeded RNG, no external state)
//! - The tick loop never incorporates partial results
//! - The only non-deterministic part is latency (when results arrive)
//!
//! ## Delivery strategies
//!
//! Each request declares how the tick loop handles a not-yet-ready result:
//! - `Fallback`: use default/cached value, player never waits
//! - `GracefulDegrade`: area loads partially, elements pop in when ready
//! - `ModalLock`: tick loop pauses until result arrives (rare, diegetic UI)
pub mod pool;
pub mod stubs;
pub mod systems;