Files
settled-reach/server/src/workers/stubs.rs
T
jpmschweitzerandClaude Fable 5 0bd895fcac chore(engine): server hygiene batch — workers tests, surname dedup, save pin (T-1063, T-1064)
- workers/pool.rs: 5 new tests; catch_unwind keeps worker threads alive on
  handler panic (in-flight request loss unchanged, pinned by test + #843
  docs); stubs.rs no longer falsely claims the pool is tested
- save/load: execute_save_load pinned .after(Storyteller) so the scheduler
  cannot legally save pre-Input state; exclusive-system exception recorded
  in tick_phases.rs rules
- surname corpus extracted to bin/shared/surname_corpus.rs (both economy
  generators import it; byte-identical output verified on 23.6MB+1.45MB
  TOMLs); all three stamp/watch registries updated
- generator_spike gated behind non-default 'generator-spike' feature
- economy.rs: 11 new D-181 signal-derivation tests on the new
  econ_sim Simulation::from_economy in-memory constructor
- perception exemption comments now state the consumer sort contract;
  unused bytemuck removed; rayon comment corrected; the 22 allow(dead_code)
  documented as serde schema enforcement

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-06-12 16:22:28 +02:00

138 lines
4.4 KiB
Rust

//! Stub worker resources (#843 Part C).
//!
//! Each worker type is a Bevy Resource wrapping a typed `BackgroundWorkerPool`.
//! The actual computation logic is a no-op placeholder — implementations
//! plug in when the phases that need them arrive (Phase 5+).
//!
//! The infrastructure (channels, threads, push/poll) is real — unit tests
//! live in `pool.rs` (T-1063). Known limitation (#843): a handler panic
//! loses the in-flight request (no result is ever delivered, no re-enqueue);
//! see the crash-behavior notes in `pool.rs`.
use bevy_ecs::prelude::*;
use super::pool::BackgroundWorkerPool;
// ---------------------------------------------------------------------------
// ChunkGen — terrain, buildings, props, navmesh for a world chunk
// ---------------------------------------------------------------------------
/// Request to generate a chunk at the given coordinates.
#[derive(Debug, Clone)]
pub struct ChunkGenRequest {
pub chunk_x: i32,
pub chunk_y: i32,
pub chunk_z: i32,
pub world_seed: u64,
}
/// Generated chunk data (placeholder — real struct will hold terrain, props, navmesh).
#[derive(Debug)]
pub struct ChunkGenResult {
pub chunk_x: i32,
pub chunk_y: i32,
pub chunk_z: i32,
/// Placeholder: real result holds terrain heightfield, building list, prop list, navmesh.
pub generated: bool,
}
/// Bevy resource for the chunk generation worker pool.
#[derive(Resource)]
pub struct ChunkGenWorker {
pub pool: BackgroundWorkerPool<ChunkGenRequest, ChunkGenResult>,
}
impl ChunkGenWorker {
pub fn new(thread_count: usize) -> Self {
Self {
pool: BackgroundWorkerPool::spawn(thread_count, |req: ChunkGenRequest| {
// Stub: real implementation generates terrain from seed + coordinates
ChunkGenResult {
chunk_x: req.chunk_x,
chunk_y: req.chunk_y,
chunk_z: req.chunk_z,
generated: true,
}
}),
}
}
}
// ---------------------------------------------------------------------------
// NpcPrep — pre-compute NPC state for areas about to become visible
// ---------------------------------------------------------------------------
/// Request to prepare NPCs for an area.
#[derive(Debug, Clone)]
pub struct NpcPrepRequest {
pub area_id: String,
pub world_seed: u64,
}
/// Prepared NPC state (placeholder).
#[derive(Debug)]
pub struct NpcPrepResult {
pub area_id: String,
pub npc_count: usize,
}
/// Bevy resource for the NPC preparation worker pool.
#[derive(Resource)]
pub struct NpcPrepWorker {
pub pool: BackgroundWorkerPool<NpcPrepRequest, NpcPrepResult>,
}
impl NpcPrepWorker {
pub fn new(thread_count: usize) -> Self {
Self {
pool: BackgroundWorkerPool::spawn(thread_count, |req: NpcPrepRequest| {
// Stub: real implementation pre-generates NPC appearance, inventory, mood
NpcPrepResult {
area_id: req.area_id,
npc_count: 0,
}
}),
}
}
}
// ---------------------------------------------------------------------------
// OffscreenTick — advance NPC state for entities outside the active tier
// ---------------------------------------------------------------------------
/// Request to advance off-screen NPCs by a specific number of ticks.
#[derive(Debug, Clone)]
pub struct OffscreenTickRequest {
pub area_id: String,
/// Exact number of simulation ticks to advance. Deterministic.
pub ticks_to_advance: u64,
pub world_seed: u64,
}
/// Updated NPC state after off-screen ticking (placeholder).
#[derive(Debug)]
pub struct OffscreenTickResult {
pub area_id: String,
pub ticks_advanced: u64,
}
/// Bevy resource for the off-screen tick worker pool.
#[derive(Resource)]
pub struct OffscreenTickWorker {
pub pool: BackgroundWorkerPool<OffscreenTickRequest, OffscreenTickResult>,
}
impl OffscreenTickWorker {
pub fn new(thread_count: usize) -> Self {
Self {
pool: BackgroundWorkerPool::spawn(thread_count, |req: OffscreenTickRequest| {
// Stub: real implementation snapshots NPC state, advances N ticks
OffscreenTickResult {
area_id: req.area_id,
ticks_advanced: req.ticks_to_advance,
}
}),
}
}
}