Skip to main content

plasma_prp/core/
modifier.rs

1//! plModifier — base trait for scene object behaviors.
2//!
3//! Modifiers are attached to plSceneObjects and receive messages sent to
4//! their target objects. They provide per-frame evaluation and message handling.
5//!
6//! C++ ref: pnModifier/plModifier.h/.cpp, plMsgForwarder.h/.cpp
7
8use crate::core::uoid::Uoid;
9
10/// Trait for all modifiers — objects that attach to scene objects and
11/// respond to messages and per-frame updates.
12///
13/// Corresponds to plModifier in C++.
14pub trait Modifier: Send + Sync {
15    /// Get the class index of this modifier.
16    fn class_index(&self) -> u16;
17
18    /// Get the number of targets this modifier is attached to.
19    fn num_targets(&self) -> usize;
20
21    /// Add a target scene object.
22    fn add_target(&mut self, target: Uoid);
23
24    /// Remove a target scene object.
25    fn remove_target(&mut self, target: &Uoid);
26
27    /// Per-frame evaluation. Called each frame for active modifiers.
28    /// Returns true if the modifier's state changed.
29    fn eval(&mut self, secs: f64, del: f32, dirty: u32) -> bool;
30}
31
32/// Single-target modifier base — most modifiers only have one target.
33/// Corresponds to plSingleModifier in C++.
34#[derive(Debug, Clone, Default)]
35pub struct SingleModifierData {
36    pub target: Option<Uoid>,
37}
38
39impl SingleModifierData {
40    pub fn new() -> Self {
41        Self { target: None }
42    }
43
44    pub fn set_target(&mut self, target: Uoid) {
45        self.target = Some(target);
46    }
47
48    pub fn clear_target(&mut self) {
49        self.target = None;
50    }
51}
52
53/// plMsgForwarder — forwards messages from one key to multiple receivers.
54#[derive(Debug, Clone, Default)]
55pub struct MsgForwarderData {
56    pub forward_keys: Vec<Uoid>,
57}
58
59impl MsgForwarderData {
60    pub fn new() -> Self {
61        Self {
62            forward_keys: Vec::new(),
63        }
64    }
65
66    pub fn add_forward_key(&mut self, key: Uoid) {
67        self.forward_keys.push(key);
68    }
69}