blue_engine_core/prelude/
mod.rs1use downcast::{Any, downcast};
2pub mod imports;
4pub use imports::*;
5pub mod primitive_shapes;
8pub use crate::camera::{Camera, CameraContainer, Projection};
9pub use crate::definition::{
10    Pipeline, PipelineData, ShaderSettings, TextureData, TextureMode, VertexBuffers,
11    pixel_to_cartesian,
12};
13pub use crate::engine::{Engine, EngineSettings};
14pub use crate::objects::{
15    Instance, InstanceRaw, Object, ObjectSettings, ObjectStorage, RotateAmount, RotateAxis,
16};
17pub use crate::render::Renderer;
18#[cfg(all(feature = "window", not(feature = "headless")))]
19pub use crate::window::Window;
20
21#[cfg(not(feature = "u32"))]
23pub type UnsignedIntType = u16;
24#[cfg(feature = "u32")]
25pub type UnsignedIntType = u32;
26
27pub mod macros {
29    macro_rules! impl_deref {
30        ($struct:ty,$type:ty) => {
31            impl std::ops::Deref for $struct {
32                type Target = $type;
33
34                fn deref(&self) -> &Self::Target {
35                    &self.0
36                }
37            }
38            impl std::ops::DerefMut for $struct {
39                fn deref_mut(&mut self) -> &mut Self::Target {
40                    &mut self.0
41                }
42            }
43        };
44    }
45
46    macro_rules! impl_deref_field {
47        ($struct:ty,$type:ty,$field:ident) => {
48            impl std::ops::Deref for $struct {
49                type Target = $type;
50
51                fn deref(&self) -> &Self::Target {
52                    &self.$field
53                }
54            }
55            impl std::ops::DerefMut for $struct {
56                fn deref_mut(&mut self) -> &mut Self::Target {
57                    &mut self.$field
58                }
59            }
60        };
61    }
62
63    pub(crate) use impl_deref;
64    pub(crate) use impl_deref_field;
65}
66
67#[repr(C)]
70#[derive(Copy, Clone, Debug, bytemuck::Pod, bytemuck::Zeroable)]
71pub struct Vertex {
72    pub position: [f32; 3],
74    pub uv: [f32; 2],
76    pub normal: [f32; 3],
78}
79impl Vertex {
80    pub(crate) fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
81        wgpu::VertexBufferLayout {
82            array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
83            step_mode: wgpu::VertexStepMode::Vertex,
84            attributes: &[
85                wgpu::VertexAttribute {
86                    offset: 0,
87                    shader_location: 0,
88                    format: wgpu::VertexFormat::Float32x3,
89                },
90                wgpu::VertexAttribute {
91                    offset: std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
93                    shader_location: 1,
94                    format: wgpu::VertexFormat::Float32x2,
95                },
96                wgpu::VertexAttribute {
97                    offset: std::mem::size_of::<[f32; 5]>() as wgpu::BufferAddress,
98                    shader_location: 2,
99                    format: wgpu::VertexFormat::Float32x3,
100                },
101            ],
102        }
103    }
104}
105unsafe impl Send for Vertex {}
106unsafe impl Sync for Vertex {}
107
108pub trait Signal: Any {
110    #[allow(clippy::too_many_arguments)]
112    fn init(&mut self, _engine: &mut crate::Engine) {}
113
114    #[allow(clippy::too_many_arguments)]
116    #[cfg(all(feature = "window", not(feature = "headless")))]
117    fn device_events(&mut self, _engine: &mut crate::Engine, _events: &crate::DeviceEvent) {}
118
119    #[allow(clippy::too_many_arguments)]
121    #[cfg(all(feature = "window", not(feature = "headless")))]
122    fn window_events(&mut self, _engine: &mut crate::Engine, _events: &crate::WindowEvent) {}
123
124    #[allow(clippy::too_many_arguments)]
126    fn frame(
127        &mut self,
128        _engine: &mut crate::Engine,
129        _encoder: &mut crate::CommandEncoder,
130        _view: &crate::TextureView,
131    ) {
132    }
133}
134downcast!(dyn Signal);
137
138pub struct SignalStorage {
140    pub events: Vec<(String, Box<dyn Signal>)>,
142}
143
144pub type WindowSize = (u32, u32);