euv-core 0.56.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Execution status returned by every `BehaviorTree` node on tick.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub enum BtStatus {
    /// Node is still executing and will resume on the next tick.
    Running,
    /// Node completed its task successfully.
    #[default]
    Success,
    /// Node failed its condition or action.
    Failure,
}

/// Typed value stored inside a `BehaviorTree` `Blackboard`.
#[derive(Clone, Debug, PartialEq)]
pub enum BtValue {
    /// Boolean flag value.
    Bool(bool),
    /// Signed 64-bit integer value.
    Int(i64),
    /// 32-bit floating-point scalar value.
    Float(f32),
    /// 2D spatial vector value.
    Vec2(Vec2),
    /// 3D spatial vector value.
    Vec3(Vec3),
    /// Owned UTF-8 text value.
    Text(String),
}

/// Completion policy for `BehaviorTree` parallel composite nodes.
#[derive(Clone, Copy, Debug, Default, Eq, Hash, PartialEq)]
pub enum BtParallelPolicy {
    /// Succeeds when all children succeed; fails as soon as any child fails.
    #[default]
    RequireAll,
    /// Succeeds as soon as any child succeeds; fails only when all children fail.
    RequireOne,
    /// Succeeds once at least `usize` children succeed; fails if remaining cannot reach threshold.
    Threshold(usize),
}

/// Decorator operation wrapping a single child node in a `BehaviorTree`.
#[derive(Clone, Debug, PartialEq)]
pub enum BtDecoratorKind {
    /// Flips `Success <-> Failure` while preserving `Running`.
    Inverter,
    /// Repeats child up to `usize` times (`0` repeats indefinitely until failure).
    Repeater(usize),
    /// Enforces a cooldown duration in seconds before allowing child re-entry after completion.
    Cooldown(f32),
    /// Requires blackboard boolean `key == expected` before ticking child, returning `Failure` otherwise.
    Guard {
        /// Blackboard key name checked before executing child.
        key: String,
        /// Required boolean value for the guard to pass.
        expected: bool,
    },
}

/// Structural node variant inside an arena-indexed `BehaviorTree`.
#[derive(Clone, Debug, PartialEq)]
pub enum BtNodeKind {
    /// Executes children in order until one fails or runs.
    Sequence(Vec<usize>),
    /// Executes children in order until one succeeds or runs.
    Selector(Vec<usize>),
    /// Executes all children concurrently under `policy`.
    Parallel {
        /// Child node indices ticked together.
        children: Vec<usize>,
        /// Success/failure aggregation policy.
        policy: BtParallelPolicy,
    },
    /// Wraps a single child node with `kind`.
    Decorator {
        /// Decorator behavior specification.
        kind: BtDecoratorKind,
        /// Child node index.
        child: usize,
    },
    /// Evaluates user condition callback `condition_id` returning `Success` or `Failure`.
    Condition(u32),
    /// Executes user action callback `action_id` returning `BtStatus`.
    Action(u32),
}

/// Lifecycle notification emitted by `HierarchicalFsm` during transitions and updates.
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub enum HfsmLifecycleEvent {
    /// State `u32` was entered top-down.
    Enter(u32),
    /// State `u32` was ticked during `update`.
    Update(u32),
    /// State `u32` was exited bottom-up.
    Exit(u32),
}

/// Mathematical response curve shaping normalized `[0.0, 1.0]` consideration inputs in `UtilityAiBrain`.
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum UtilityCurveKind {
    /// Clamped affine ramp `(slope * x + intercept).clamp(0, 1)`.
    Linear {
        /// Ramp slope.
        slope: f32,
        /// Vertical intercept.
        intercept: f32,
    },
    /// Power curve `x^exponent` (or `1 - x^exponent` when `invert` is true).
    Quadratic {
        /// Positive polynomial exponent.
        exponent: f32,
        /// Whether to invert output as `1.0 - x^exponent`.
        invert: bool,
    },
    /// S-shaped logistic sigmoid `1 / (1 + exp(-steepness * (x - midpoint)))`.
    Logistic {
        /// Transition slope around `midpoint`.
        steepness: f32,
        /// Inflection midpoint in `[0.0, 1.0]`.
        midpoint: f32,
    },
    /// Normalized exponential growth `(exp(base_power * x) - 1) / (exp(base_power) - 1)`.
    Exponential {
        /// Curvature rate (positive = convex rise, negative = concave rise).
        base_power: f32,
    },
}