swarm / village/src/sim.rs

raw file 1074 bytes
//! Shared barrier-stepping resources: the world only advances after every
//! villager due this round has finished computing.

use bevy::prelude::*;

/// Simulated seconds. Advances only while `Phase::Stepping`.
#[derive(Resource)]
pub struct SimClock(pub f32);

#[derive(Resource, PartialEq, Clone, Copy, Debug)]
pub enum Phase {
    /// World animates, clock runs, movement/needs are live.
    Stepping,
    /// LLM calls in flight — scene frozen until every result lands.
    Computing,
}

#[derive(Resource)]
pub struct RoundState {
    /// Results still owed before the barrier lifts.
    pub pending: usize,
    /// Completed barriers (HUD stat).
    pub rounds: u64,
    /// Real-time when computing started (deadman timeout).
    pub computing_since: f32,
    /// Real-time before the next gather may fire (guarantees a visible step).
    pub step_until: f32,
}

impl Default for RoundState {
    fn default() -> Self {
        Self {
            pending: 0,
            rounds: 0,
            computing_since: 0.0,
            step_until: 0.5,
        }
    }
}