gloss_renderer/plugin_manager/
systems.rs1use crate::scene::Scene;
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)]
13#[cfg_attr(not(target_arch = "wasm32"), derive(StableAbi))]
14pub struct GuiSystem {
15 pub f: extern "C" fn(selected_entity: ROption<Entity>, scene: &mut Scene) -> GuiWindow,
16}
17impl GuiSystem {
18 pub fn new(f: extern "C" fn(selected_entity: ROption<Entity>, scene: &mut Scene) -> GuiWindow) -> Self {
19 Self { f }
20 }
21}
22
23#[repr(C)]
24#[derive(Clone)]
26#[cfg_attr(not(target_arch = "wasm32"), derive(StableAbi))]
27pub struct SystemMetadata {
28 pub autorun: bool,
29 pub execution_time: RDuration,
31}
32impl Default for SystemMetadata {
33 fn default() -> Self {
34 Self {
35 autorun: true,
36 execution_time: RDuration::from_secs(0),
38 }
39 }
40}
41
42#[repr(C)]
43#[derive(Clone)]
45#[cfg_attr(not(target_arch = "wasm32"), derive(StableAbi))]
46pub struct LogicSystem {
47 pub f: extern "C" fn(scene: &mut Scene, runner: &mut RunnerState),
49 pub name: ROption<RString>,
51}
52impl LogicSystem {
53 pub fn new(f: extern "C" fn(scene: &mut Scene, runner: &mut RunnerState)) -> Self {
54 Self { f, name: RNone }
55 }
56 #[must_use]
57 pub fn with_name(self, name: &str) -> Self {
58 Self {
59 f: self.f,
60 name: RSome(name.to_string().into()),
61 }
62 }
63}
64
65#[repr(C)]
66#[derive(Clone)]
68#[cfg_attr(not(target_arch = "wasm32"), derive(StableAbi))]
69pub struct EventSystem {
70 pub f: extern "C" fn(scene: &mut Scene, runner: &mut RunnerState, event: &Event) -> bool,
71 pub name: ROption<RString>,
72}
73impl EventSystem {
74 pub fn new(f: extern "C" fn(scene: &mut Scene, runner: &mut RunnerState, event: &Event) -> bool) -> Self {
75 Self { f, name: RNone }
76 }
77 #[must_use]
78 pub fn with_name(self, name: &str) -> Self {
79 Self {
80 f: self.f,
81 name: RSome(name.to_string().into()),
82 }
83 }
84}