Skip to main content

mittens_engine/engine/ecs/system/
pipeline_system.rs

1use crate::engine::ecs::RxWorld;
2use crate::engine::ecs::component::SignalRouteUpwardComponent;
3use crate::engine::ecs::rx::signal_pipeline::{
4    SignalPipeline, SignalPipelineOp, SignalRouteUpward,
5};
6use crate::engine::ecs::{ComponentId, World};
7
8/// Maintains RxWorld-owned intent routing pipelines based on operator components.
9#[derive(Debug, Default)]
10pub struct PipelineSystem;
11
12impl PipelineSystem {
13    pub fn register_signal_route_upward(
14        &mut self,
15        world: &World,
16        rx: &mut RxWorld,
17        operator_component: ComponentId,
18    ) {
19        let Some(cfg) =
20            world.get_component_by_id_as::<SignalRouteUpwardComponent>(operator_component)
21        else {
22            return;
23        };
24
25        let Some(owner) = world.parent_of(operator_component) else {
26            return;
27        };
28
29        let pipeline = SignalPipeline {
30            source_operator: operator_component,
31            ops: vec![SignalPipelineOp::RouteUpward(SignalRouteUpward {
32                intent_kind: cfg.intent_kind.clone(),
33                parent_type: cfg.parent_type.clone(),
34            })],
35        };
36
37        rx.register_pipeline(owner, pipeline);
38    }
39
40    pub fn remove_signal_route_upward(
41        &mut self,
42        rx: &mut RxWorld,
43        operator_component: ComponentId,
44    ) {
45        rx.remove_pipelines_from_operator(operator_component);
46    }
47}