feo_oop_engine/scripting/
globals.rs

1//! Constructs that let you interface with the engine to safely create and use global variables.
2//! 
3//! TODO
4//! 
5use std::fmt::Debug;
6
7use vulkano::device::Queue;
8
9use crate::registration::id::IDSystem;
10
11use {
12    crate::{
13        scene::Scene,
14        event::UserEvent,
15    },
16    std::{
17        any::Any,
18        sync::{Arc, RwLock}
19    },
20    vulkano::swapchain::Surface,
21    winit::{
22        event_loop::EventLoopProxy,
23        window::Window
24    }
25};
26
27#[allow(clippy::type_complexity)]
28#[derive(Clone, Debug, Global)]
29pub struct EngineGlobals {
30    pub queue: Arc<Queue>,
31    pub surface: Arc<Surface<Window>>,
32    pub scene: Arc<RwLock<Scene>>,
33    pub event_loop_proxy: Arc<futures::lock::Mutex<EventLoopProxy<UserEvent<Arc<dyn Any + 'static + Send + Sync>>>>>,
34    pub id_system: IDSystem,
35}
36
37pub trait Global: GlobalClone + Debug + Any + Send + Sync + 'static {
38    fn as_any(&self) -> &dyn Any;
39}
40
41pub trait GlobalClone {
42    fn clone_global(&self) -> Box<dyn Global>;
43}
44
45impl<T> GlobalClone for T where T: 'static + Global + Clone {
46    fn clone_global(&self) -> Box<dyn Global> {
47        Box::new(self.clone())
48    }
49}
50
51impl Clone for Box<dyn Global> {
52    fn clone(&self) -> Self {
53        self.clone_global()
54    }
55}