Skip to main content

atomr_view_core/
actors.rs

1use crate::bridge::{BackendCommand, BackendEvent, UiBridgeMessage};
2use crate::scene::{SceneDescription, ScenePatch};
3use atomr_core::prelude::*;
4
5pub struct WindowActor {
6    pub id: String,
7    pub bridge: ActorRef<UiBridgeMessage>, // UiBridgeActor Ref
8    pub scene: SceneDescription,
9}
10
11#[async_trait]
12impl Actor for WindowActor {
13    type Msg = WindowMessage;
14
15    async fn handle(&mut self, ctx: &mut Context<Self>, msg: WindowMessage) {
16        match msg {
17            WindowMessage::UpdateScene(scene) => {
18                self.scene = scene.clone();
19                self.bridge.tell(UiBridgeMessage::Command(BackendCommand::SetScene {
20                    window_id: self.id.clone(),
21                    scene,
22                }));
23            }
24            WindowMessage::PatchScene(patches) => {
25                // In a real impl, we'd apply patches to `self.scene` here
26                self.bridge.tell(UiBridgeMessage::Command(BackendCommand::ApplyPatches {
27                    window_id: self.id.clone(),
28                    patches,
29                }));
30            }
31            WindowMessage::BackendEvent(evt) => {
32                match evt {
33                    BackendEvent::WindowClosed { .. } => {
34                        ctx.stop_self();
35                    }
36                    BackendEvent::Input { event: _, .. } => {
37                        // Handle input, maybe forward to regions
38                    }
39                    _ => {}
40                }
41            }
42        }
43    }
44}
45
46pub enum WindowMessage {
47    UpdateScene(SceneDescription),
48    PatchScene(Vec<ScenePatch>),
49    BackendEvent(BackendEvent),
50}
51
52pub struct RegionActor {
53    pub id: String,
54    pub parent_window: ActorRef<WindowMessage>, // WindowActor Ref
55}
56
57#[async_trait]
58impl Actor for RegionActor {
59    type Msg = RegionMessage;
60
61    async fn handle(&mut self, _ctx: &mut Context<Self>, msg: RegionMessage) {
62        match msg {
63            RegionMessage::StateUpdate => {
64                // Compute new scene fragment and send to parent_window
65            }
66        }
67    }
68}
69
70pub enum RegionMessage {
71    StateUpdate,
72}
73
74pub struct PersistenceActor;
75
76#[async_trait]
77impl Actor for PersistenceActor {
78    type Msg = PersistenceMessage;
79
80    async fn handle(&mut self, _ctx: &mut Context<Self>, _msg: PersistenceMessage) {
81        // Integrate with atomr-persistence
82    }
83}
84
85pub enum PersistenceMessage {
86    Save(String, String),
87    Load(String),
88}
89
90pub struct InferenceActor;
91
92#[async_trait]
93impl Actor for InferenceActor {
94    type Msg = InferenceMessage;
95
96    async fn handle(&mut self, _ctx: &mut Context<Self>, _msg: InferenceMessage) {
97        // Integrate with atomr-infer
98    }
99}
100
101pub enum InferenceMessage {
102    Predict(String),
103}