Skip to main content

dreamwell_engine/physics/
render_policy.rs

1use super::render_mode::RenderMode;
2use serde::{Deserialize, Serialize};
3
4/// Curve types for over-life property animation.
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct Curve1 {
7    pub points: Vec<(f32, f32)>,
8}
9
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Curve2 {
12    pub points: Vec<(f32, [f32; 2])>,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct Curve4 {
17    pub points: Vec<(f32, [f32; 4])>,
18}
19
20/// Render policy — visual presentation parameters.
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct RenderPolicy {
23    pub mode: RenderMode,
24    pub material: String,
25    pub lit: bool,
26    pub cast_shadows: bool,
27    pub receive_shadows: bool,
28    pub soft_depth_fade: bool,
29    pub velocity_alignment: bool,
30    pub color_over_life: Option<Curve4>,
31    pub size_over_life: Option<Curve2>,
32    pub alpha_over_life: Option<Curve1>,
33}
34
35impl Default for RenderPolicy {
36    fn default() -> Self {
37        Self {
38            mode: RenderMode::Billboard,
39            material: String::new(),
40            lit: false,
41            cast_shadows: false,
42            receive_shadows: false,
43            soft_depth_fade: true,
44            velocity_alignment: false,
45            color_over_life: None,
46            size_over_life: None,
47            alpha_over_life: None,
48        }
49    }
50}
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn render_policy_default() {
58        let r = RenderPolicy::default();
59        assert_eq!(r.mode, RenderMode::Billboard);
60        assert!(!r.lit);
61    }
62
63    #[test]
64    fn render_policy_serde() {
65        let r = RenderPolicy {
66            mode: RenderMode::ShardInstance,
67            material: "mat/stone_shard".into(),
68            lit: true,
69            cast_shadows: false,
70            receive_shadows: true,
71            soft_depth_fade: true,
72            velocity_alignment: true,
73            color_over_life: Some(Curve4 {
74                points: vec![(0.0, [1.0, 1.0, 1.0, 1.0]), (1.0, [0.5, 0.5, 0.5, 0.0])],
75            }),
76            size_over_life: None,
77            alpha_over_life: None,
78        };
79        let json = serde_json::to_string(&r).unwrap();
80        let restored: RenderPolicy = serde_json::from_str(&json).unwrap();
81        assert_eq!(restored.mode, RenderMode::ShardInstance);
82    }
83}