dreamwell-engine 1.0.0

Dreamwell pure-logic engine library — transforms, hierarchy, canon pipeline, spatial math, hashing, tile rules, validation, waymark schema, material/lighting descriptors. No SpacetimeDB dependency.
Documentation
use super::render_mode::RenderMode;
use serde::{Deserialize, Serialize};

/// Curve types for over-life property animation.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Curve1 {
    pub points: Vec<(f32, f32)>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Curve2 {
    pub points: Vec<(f32, [f32; 2])>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Curve4 {
    pub points: Vec<(f32, [f32; 4])>,
}

/// Render policy — visual presentation parameters.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RenderPolicy {
    pub mode: RenderMode,
    pub material: String,
    pub lit: bool,
    pub cast_shadows: bool,
    pub receive_shadows: bool,
    pub soft_depth_fade: bool,
    pub velocity_alignment: bool,
    pub color_over_life: Option<Curve4>,
    pub size_over_life: Option<Curve2>,
    pub alpha_over_life: Option<Curve1>,
}

impl Default for RenderPolicy {
    fn default() -> Self {
        Self {
            mode: RenderMode::Billboard,
            material: String::new(),
            lit: false,
            cast_shadows: false,
            receive_shadows: false,
            soft_depth_fade: true,
            velocity_alignment: false,
            color_over_life: None,
            size_over_life: None,
            alpha_over_life: None,
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn render_policy_default() {
        let r = RenderPolicy::default();
        assert_eq!(r.mode, RenderMode::Billboard);
        assert!(!r.lit);
    }

    #[test]
    fn render_policy_serde() {
        let r = RenderPolicy {
            mode: RenderMode::ShardInstance,
            material: "mat/stone_shard".into(),
            lit: true,
            cast_shadows: false,
            receive_shadows: true,
            soft_depth_fade: true,
            velocity_alignment: true,
            color_over_life: Some(Curve4 {
                points: vec![(0.0, [1.0, 1.0, 1.0, 1.0]), (1.0, [0.5, 0.5, 0.5, 0.0])],
            }),
            size_over_life: None,
            alpha_over_life: None,
        };
        let json = serde_json::to_string(&r).unwrap();
        let restored: RenderPolicy = serde_json::from_str(&json).unwrap();
        assert_eq!(restored.mode, RenderMode::ShardInstance);
    }
}