gloss_renderer/plugin_manager/
systems.rs

1use crate::{scene::Scene, viewer::GpuResources};
2
3use gloss_hecs::Entity;
4use gloss_utils::abi_stable_aliases::std_types::{RDuration, RNone, ROption, ROption::RSome, RString};
5#[cfg(not(target_arch = "wasm32"))]
6use gloss_utils::abi_stable_aliases::StableAbi;
7
8use super::{gui::window::GuiWindow, plugins::Event, runner::RunnerState};
9
10#[repr(C)]
11#[derive(Clone)]
12#[cfg_attr(not(target_arch = "wasm32"), derive(StableAbi))]
13pub struct GuiSystem {
14    pub f: extern "C" fn(selected_entity: &ROption<Entity>, scene: &mut Scene) -> GuiWindow,
15}
16impl GuiSystem {
17    pub fn new(f: extern "C" fn(selected_entity: &ROption<Entity>, scene: &mut Scene) -> GuiWindow) -> Self {
18        Self { f }
19    }
20}
21
22#[repr(C)]
23#[derive(Clone)]
24#[cfg_attr(not(target_arch = "wasm32"), derive(StableAbi))]
25pub struct SystemMetadata {
26    pub autorun: bool,
27    pub execution_time: RDuration,
28}
29impl Default for SystemMetadata {
30    fn default() -> Self {
31        Self {
32            autorun: true,
33            execution_time: RDuration::from_secs(0),
34        }
35    }
36}
37
38#[repr(C)]
39#[derive(Clone)]
40#[cfg_attr(not(target_arch = "wasm32"), derive(StableAbi))]
41pub struct LogicSystem {
42    pub f: extern "C" fn(scene: &mut Scene, runner: &mut RunnerState),
43    pub name: ROption<RString>,
44}
45
46impl LogicSystem {
47    pub fn new(f: extern "C" fn(scene: &mut Scene, runner: &mut RunnerState)) -> Self {
48        Self { f, name: RNone }
49    }
50    #[must_use]
51    pub fn with_name(self, name: &str) -> Self {
52        Self {
53            f: self.f,
54            name: RSome(name.to_string().into()),
55        }
56    }
57}
58
59#[repr(C)]
60#[derive(Clone)]
61#[cfg_attr(not(target_arch = "wasm32"), derive(StableAbi))]
62pub struct EventSystem {
63    pub f: extern "C" fn(scene: &mut Scene, runner: &mut RunnerState, event: &Event) -> bool,
64    pub name: ROption<RString>,
65}
66impl EventSystem {
67    pub fn new(f: extern "C" fn(scene: &mut Scene, runner: &mut RunnerState, event: &Event) -> bool) -> Self {
68        Self { f, name: RNone }
69    }
70    #[must_use]
71    pub fn with_name(self, name: &str) -> Self {
72        Self {
73            f: self.f,
74            name: RSome(name.to_string().into()),
75        }
76    }
77}
78
79// We do not need to derive StableAbi and do #[repr(C)] because we do not need this to be FFI safe
80// These systems can only be added from within gloss
81#[derive(Clone)]
82pub struct GpuSystem {
83    pub f: fn(scene: &mut Scene, runner: &mut RunnerState, gpu_res: &GpuResources),
84    pub name: ROption<RString>,
85}
86
87impl GpuSystem {
88    pub fn new(f: fn(scene: &mut Scene, runner: &mut RunnerState, gpu_res: &GpuResources)) -> Self {
89        Self { f, name: RNone }
90    }
91    #[must_use]
92    pub fn with_name(self, name: &str) -> Self {
93        Self {
94            f: self.f,
95            name: RSome(name.to_string().into()),
96        }
97    }
98}