summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engine/src/camera.rs7
-rw-r--r--engine/src/camera/fly.rs3
-rw-r--r--engine/src/collision.rs5
-rw-r--r--engine/src/data_types/dimens.rs8
-rw-r--r--engine/src/data_types/vector.rs16
-rw-r--r--engine/src/draw_flags.rs15
-rw-r--r--engine/src/lighting.rs7
-rw-r--r--engine/src/material.rs3
-rw-r--r--engine/src/projection.rs11
-rw-r--r--engine/src/transform.rs5
-rw-r--r--engine/src/ui/dear_imgui.rs3
-rw-r--r--engine/src/windowing/dpi.rs87
-rw-r--r--engine/src/windowing/mouse.rs5
-rw-r--r--engine/src/windowing/window.rs10
14 files changed, 113 insertions, 72 deletions
diff --git a/engine/src/camera.rs b/engine/src/camera.rs
index 1eb1246..b697ee3 100644
--- a/engine/src/camera.rs
+++ b/engine/src/camera.rs
@@ -1,10 +1,11 @@
use crate::ecs::Component;
use crate::projection::{Perspective, Projection};
+use crate::reflection::Reflection;
use crate::vector::Vec3;
pub mod fly;
-#[derive(Debug, Clone, Component)]
+#[derive(Debug, Clone, Component, Reflection)]
pub struct Camera
{
pub target: Vec3<f32>,
@@ -25,11 +26,11 @@ impl Default for Camera
}
/// Marker component for cameras that are active.
-#[derive(Debug, Default, Clone, Copy, Component)]
+#[derive(Debug, Default, Clone, Copy, Component, Reflection)]
pub struct Active;
/// Cameras that can be controlled have this component.
-#[derive(Debug, Clone, Copy, Component)]
+#[derive(Debug, Clone, Copy, Component, Reflection)]
pub struct Controllable
{
pub control_enabled: bool,
diff --git a/engine/src/camera/fly.rs b/engine/src/camera/fly.rs
index 9d5658b..18afcb8 100644
--- a/engine/src/camera/fly.rs
+++ b/engine/src/camera/fly.rs
@@ -11,13 +11,14 @@ use crate::ecs::system::Into;
use crate::ecs::{Component, Query};
use crate::input::keyboard::{Key, Keyboard};
use crate::input::mouse::Mouse;
+use crate::reflection::Reflection;
use crate::transform::WorldPosition;
use crate::vector::{Vec2, Vec3};
builder! {
/// A fly camera.
#[builder(name = Builder, derives = (Debug))]
-#[derive(Debug, Component)]
+#[derive(Debug, Component, Reflection)]
#[non_exhaustive]
pub struct Fly {
pub current_pitch: f64,
diff --git a/engine/src/collision.rs b/engine/src/collision.rs
index c053a7f..015ab58 100644
--- a/engine/src/collision.rs
+++ b/engine/src/collision.rs
@@ -1,5 +1,6 @@
use crate::ecs::Component;
use crate::mesh::Mesh;
+use crate::reflection::Reflection;
use crate::vector::Vec3;
pub trait Collider<Other>
@@ -7,7 +8,7 @@ pub trait Collider<Other>
fn intersects(&self, other: &Other) -> bool;
}
-#[derive(Debug, Default, Clone, Component)]
+#[derive(Debug, Default, Clone, Component, Reflection)]
#[non_exhaustive]
pub struct BoxCollider
{
@@ -78,7 +79,7 @@ impl Collider<Vec3<f32>> for BoxCollider
}
}
-#[derive(Debug, Default, Clone, Component)]
+#[derive(Debug, Default, Clone, Component, Reflection)]
pub struct SphereCollider
{
pub center: Vec3<f32>,
diff --git a/engine/src/data_types/dimens.rs b/engine/src/data_types/dimens.rs
index a197560..64a30d3 100644
--- a/engine/src/data_types/dimens.rs
+++ b/engine/src/data_types/dimens.rs
@@ -1,8 +1,11 @@
use std::num::NonZeroU32;
use std::ops::Div;
+use crate::reflection::Reflection;
+
/// 2D dimensions.
-#[derive(Debug, Clone, Copy, PartialEq, Eq)]
+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Reflection)]
+#[reflection(impl_with_generics(<f32>, <f64>, <u32>, <u16>))]
pub struct Dimens<Value>
{
pub width: Value,
@@ -51,7 +54,8 @@ impl Dimens<u32>
}
/// 3D dimensions.
-#[derive(Debug, Clone, Copy, PartialEq, PartialOrd)]
+#[derive(Debug, Clone, Copy, PartialEq, PartialOrd, Reflection)]
+#[reflection(impl_with_generics(<f32>, <f64>, <u32>, <u16>))]
pub struct Dimens3<Value>
{
pub width: Value,
diff --git a/engine/src/data_types/vector.rs b/engine/src/data_types/vector.rs
index 980ca59..dd9e386 100644
--- a/engine/src/data_types/vector.rs
+++ b/engine/src/data_types/vector.rs
@@ -1,6 +1,7 @@
use std::ops::{Add, AddAssign, Div, DivAssign, Mul, MulAssign, Neg, Sub, SubAssign};
use crate::color::Color;
+use crate::reflection::Reflection;
macro_rules! impl_math_op_traits {
(impl $op_trait: ident for $vector: ident, ($($vec_field: ident),+)) => {
@@ -64,8 +65,9 @@ macro_rules! impl_math_op_traits {
};
}
-#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
-pub struct Vec2<Value>
+#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Reflection)]
+#[reflection(impl_with_generics(<f32>, <f64>, <u32>, <u16>))]
+pub struct Vec2<Value: 'static>
{
pub x: Value,
pub y: Value,
@@ -116,8 +118,9 @@ impl<Value> From<Vec2<Value>> for [Value; 2]
}
}
-#[derive(Debug, Default, Clone, Copy, PartialEq)]
-pub struct Vec3<Value>
+#[derive(Debug, Default, Clone, Copy, PartialEq, Reflection)]
+#[reflection(impl_with_generics(<f32>, <f64>, <u32>, <u16>))]
+pub struct Vec3<Value: 'static>
{
pub x: Value,
pub y: Value,
@@ -251,8 +254,9 @@ impl<Value> From<Vec3<Value>> for [Value; 3]
}
}
-#[derive(Debug, Default, Clone, Copy, PartialEq)]
-pub struct Vec4<Value>
+#[derive(Debug, Default, Clone, Copy, PartialEq, Reflection)]
+#[reflection(impl_with_generics(<f32>, <f64>, <u32>, <u16>))]
+pub struct Vec4<Value: 'static>
{
pub x: Value,
pub y: Value,
diff --git a/engine/src/draw_flags.rs b/engine/src/draw_flags.rs
index ecc94a8..e58eea0 100644
--- a/engine/src/draw_flags.rs
+++ b/engine/src/draw_flags.rs
@@ -1,10 +1,11 @@
use crate::builder;
use crate::ecs::Component;
+use crate::reflection::Reflection;
builder! {
/// Flags for how a object should be drawn.
#[builder(name = Builder, derives = (Debug, Default, Clone))]
-#[derive(Debug, Default, Clone, Component)]
+#[derive(Debug, Default, Clone, Component, Reflection)]
#[non_exhaustive]
pub struct DrawFlags
{
@@ -21,14 +22,16 @@ impl DrawFlags
}
}
-#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(Debug, Default, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Reflection)]
pub struct PolygonModeConfig
{
pub face: PolygonModeFace,
pub mode: PolygonMode,
}
-#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(
+ Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Reflection,
+)]
pub enum PolygonMode
{
Point,
@@ -38,7 +41,9 @@ pub enum PolygonMode
Fill,
}
-#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
+#[derive(
+ Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Reflection,
+)]
pub enum PolygonModeFace
{
Front,
@@ -49,5 +54,5 @@ pub enum PolygonModeFace
}
/// Component that makes a object not be drawn.
-#[derive(Debug, Clone, Copy, Component)]
+#[derive(Debug, Clone, Copy, Component, Reflection)]
pub struct NoDraw;
diff --git a/engine/src/lighting.rs b/engine/src/lighting.rs
index 2a07541..f085b17 100644
--- a/engine/src/lighting.rs
+++ b/engine/src/lighting.rs
@@ -2,10 +2,11 @@ use crate::builder;
use crate::color::Color;
use crate::data_types::vector::Vec3;
use crate::ecs::{Component, Sole};
+use crate::reflection::Reflection;
builder! {
#[builder(name = PointLightBuilder, derives = (Debug, Clone))]
-#[derive(Debug, Clone, Component)]
+#[derive(Debug, Clone, Component, Reflection)]
#[non_exhaustive]
pub struct PointLight
{
@@ -48,7 +49,7 @@ impl Default for PointLightBuilder
}
/// Parameters for light [attenuation](https://en.wikipedia.org/wiki/Attenuation).
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Reflection)]
pub struct AttenuationParams
{
pub constant: f32,
@@ -70,7 +71,7 @@ impl Default for AttenuationParams
builder! {
#[builder(name = DirectionalLightBuilder, derives = (Debug, Default, Clone))]
-#[derive(Debug, Default, Clone, Component)]
+#[derive(Debug, Default, Clone, Component, Reflection)]
#[non_exhaustive]
pub struct DirectionalLight
{
diff --git a/engine/src/material.rs b/engine/src/material.rs
index 59f0a6a..42a9884 100644
--- a/engine/src/material.rs
+++ b/engine/src/material.rs
@@ -2,6 +2,7 @@ use crate::asset::Handle as AssetHandle;
use crate::builder;
use crate::color::Color;
use crate::ecs::Component;
+use crate::reflection::Reflection;
use crate::texture::Texture;
pub mod asset;
@@ -150,7 +151,7 @@ impl Default for Builder
builder! {
/// Material flags.
#[builder(name = FlagsBuilder, derives = (Debug, Clone))]
-#[derive(Debug, Clone, Component)]
+#[derive(Debug, Clone, Component, Reflection)]
#[non_exhaustive]
pub struct Flags
{
diff --git a/engine/src/projection.rs b/engine/src/projection.rs
index e4f5898..ea3d7ed 100644
--- a/engine/src/projection.rs
+++ b/engine/src/projection.rs
@@ -1,9 +1,10 @@
use crate::builder;
use crate::data_types::dimens::Dimens;
use crate::matrix::Matrix;
+use crate::reflection::Reflection;
use crate::vector::Vec2;
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Reflection)]
#[non_exhaustive]
pub enum Projection
{
@@ -12,7 +13,7 @@ pub enum Projection
}
/// Perspective projection parameters.
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Reflection)]
pub struct Perspective
{
pub fov_radians: f32,
@@ -55,16 +56,18 @@ impl Default for Perspective
}
}
-#[derive(Debug, Clone)]
+#[derive(Debug, Default, Clone, Reflection)]
pub enum OrthographicSize
{
FixedSize(Dimens<f32>),
+
+ #[default]
WindowSize,
}
builder! {
#[builder(name = OrthographicBuilder, derives=(Debug, Clone))]
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Reflection)]
#[non_exhaustive]
pub struct Orthographic
{
diff --git a/engine/src/transform.rs b/engine/src/transform.rs
index 642fb72..7f89807 100644
--- a/engine/src/transform.rs
+++ b/engine/src/transform.rs
@@ -1,5 +1,6 @@
use crate::builder;
use crate::ecs::Component;
+use crate::reflection::Reflection;
use crate::vector::Vec3;
builder!(
@@ -41,7 +42,7 @@ impl Default for Builder
}
/// A position in world space.
-#[derive(Debug, Default, Clone, Copy, Component)]
+#[derive(Debug, Default, Clone, Copy, Component, Reflection)]
pub struct WorldPosition
{
pub position: Vec3<f32>,
@@ -56,7 +57,7 @@ impl From<Vec3<f32>> for WorldPosition
}
/// Scaling of a 3D object.
-#[derive(Debug, Clone, Copy, Component)]
+#[derive(Debug, Clone, Copy, Component, Reflection)]
pub struct Scale
{
pub scale: Vec3<f32>,
diff --git a/engine/src/ui/dear_imgui.rs b/engine/src/ui/dear_imgui.rs
index 666fcc7..1e2a3fd 100644
--- a/engine/src/ui/dear_imgui.rs
+++ b/engine/src/ui/dear_imgui.rs
@@ -43,6 +43,7 @@ use crate::projection::{
ClipVolume as ProjectionClipVolume,
Orthographic as OrthographicProjection,
};
+use crate::reflection::Reflection;
use crate::rendering::blending::{
Config as RenderingBlendingConfiguration,
Equation as RenderingBlendingEquation,
@@ -290,7 +291,7 @@ fn update(
Ok(())
}
-#[derive(Debug, Component)]
+#[derive(Debug, Component, Reflection)]
pub struct TargetWindow;
#[derive(Debug, Default, Component)]
diff --git a/engine/src/windowing/dpi.rs b/engine/src/windowing/dpi.rs
index e11fa25..d628709 100644
--- a/engine/src/windowing/dpi.rs
+++ b/engine/src/windowing/dpi.rs
@@ -1,3 +1,5 @@
+use crate::reflection::Reflection;
+
macro_rules! gen_struct_from_to_impls {
($struct: ident, fields=($($field: ident),*)) => {
impl<Pixel> From<winit::dpi::$struct<Pixel>> for $struct<Pixel>
@@ -46,78 +48,88 @@ macro_rules! gen_enum_from_to_impls {
};
}
-#[derive(Debug, Default, Clone, PartialEq)]
+#[derive(Debug, Default, Clone, PartialEq, Reflection)]
+#[reflection(impl_with_generics(<u32>, <i32>, <f32>, <f64>))]
pub struct PhysicalPosition<Pixel>
{
pub x: Pixel,
- pub y: Pixel
+ pub y: Pixel,
}
impl<Pixel> PhysicalPosition<Pixel>
{
- pub fn to_logical<LogicalPixel>(&self, scale_factor: f64) -> LogicalPosition<LogicalPixel>
+ pub fn to_logical<LogicalPixel>(
+ &self,
+ scale_factor: f64,
+ ) -> LogicalPosition<LogicalPixel>
where
Pixel: Into<f64> + Clone,
- LogicalPixel: From<f64>
+ LogicalPixel: From<f64>,
{
let x = self.x.clone().into();
let y = self.y.clone().into();
LogicalPosition {
x: (x / scale_factor).into(),
- y: (y / scale_factor).into()
+ y: (y / scale_factor).into(),
}
}
- pub fn try_convert_from<SourcePixel>(source: PhysicalPosition<SourcePixel>) -> Result<Self, Pixel::Error>
+ pub fn try_convert_from<SourcePixel>(
+ source: PhysicalPosition<SourcePixel>,
+ ) -> Result<Self, Pixel::Error>
where
- Pixel: TryFrom<SourcePixel>
+ Pixel: TryFrom<SourcePixel>,
{
Ok(Self {
x: source.x.try_into()?,
- y: source.y.try_into()?
+ y: source.y.try_into()?,
})
}
}
-gen_struct_from_to_impls!(PhysicalPosition, fields=(x, y));
+gen_struct_from_to_impls!(PhysicalPosition, fields = (x, y));
-#[derive(Debug, Default, Clone, PartialEq)]
+#[derive(Debug, Default, Clone, PartialEq, Reflection)]
+#[reflection(impl_with_generics(<f64>))]
pub struct LogicalPosition<Pixel>
{
pub x: Pixel,
- pub y: Pixel
+ pub y: Pixel,
}
impl<Pixel> LogicalPosition<Pixel>
{
- pub fn try_convert_from<SourcePixel>(source: LogicalPosition<SourcePixel>) -> Result<Self, Pixel::Error>
+ pub fn try_convert_from<SourcePixel>(
+ source: LogicalPosition<SourcePixel>,
+ ) -> Result<Self, Pixel::Error>
where
- Pixel: TryFrom<SourcePixel>
+ Pixel: TryFrom<SourcePixel>,
{
Ok(Self {
x: source.x.try_into()?,
- y: source.y.try_into()?
+ y: source.y.try_into()?,
})
}
}
-gen_struct_from_to_impls!(LogicalPosition, fields=(x, y));
+gen_struct_from_to_impls!(LogicalPosition, fields = (x, y));
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, PartialEq, Reflection)]
pub enum Position
{
Physical(PhysicalPosition<i32>),
- Logical(LogicalPosition<f64>)
+ Logical(LogicalPosition<f64>),
}
-gen_enum_from_to_impls!(Position, variants=(Physical, Logical));
+gen_enum_from_to_impls!(Position, variants = (Physical, Logical));
-#[derive(Debug, Default, Clone, PartialEq)]
+#[derive(Debug, Default, Clone, PartialEq, Reflection)]
+#[reflection(impl_with_generics(<u32>))]
pub struct PhysicalSize<Pixel>
{
pub width: Pixel,
- pub height: Pixel
+ pub height: Pixel,
}
impl<Pixel> PhysicalSize<Pixel>
@@ -125,60 +137,65 @@ impl<Pixel> PhysicalSize<Pixel>
pub fn to_logical<LogicalPixel>(&self, scale_factor: f64) -> LogicalSize<LogicalPixel>
where
Pixel: Into<f64> + Clone,
- LogicalPixel: From<f64>
+ LogicalPixel: From<f64>,
{
let width = self.width.clone().into();
let height = self.height.clone().into();
LogicalSize {
width: (width / scale_factor).into(),
- height: (height / scale_factor).into()
+ height: (height / scale_factor).into(),
}
}
}
impl<Pixel> PhysicalSize<Pixel>
{
- pub fn try_convert_from<SourcePixel>(source: PhysicalSize<SourcePixel>) -> Result<Self, Pixel::Error>
+ pub fn try_convert_from<SourcePixel>(
+ source: PhysicalSize<SourcePixel>,
+ ) -> Result<Self, Pixel::Error>
where
- Pixel: TryFrom<SourcePixel>
+ Pixel: TryFrom<SourcePixel>,
{
Ok(Self {
width: source.width.try_into()?,
- height: source.height.try_into()?
+ height: source.height.try_into()?,
})
}
}
-gen_struct_from_to_impls!(PhysicalSize, fields=(width, height));
+gen_struct_from_to_impls!(PhysicalSize, fields = (width, height));
-#[derive(Debug, Default, Clone, PartialEq)]
+#[derive(Debug, Default, Clone, PartialEq, Reflection)]
+#[reflection(impl_with_generics(<f64>))]
pub struct LogicalSize<Pixel>
{
pub width: Pixel,
- pub height: Pixel
+ pub height: Pixel,
}
impl<Pixel> LogicalSize<Pixel>
{
- pub fn try_convert_from<SourcePixel>(source: LogicalSize<SourcePixel>) -> Result<Self, Pixel::Error>
+ pub fn try_convert_from<SourcePixel>(
+ source: LogicalSize<SourcePixel>,
+ ) -> Result<Self, Pixel::Error>
where
- Pixel: TryFrom<SourcePixel>
+ Pixel: TryFrom<SourcePixel>,
{
Ok(Self {
width: source.width.try_into()?,
- height: source.height.try_into()?
+ height: source.height.try_into()?,
})
}
}
-gen_struct_from_to_impls!(LogicalSize, fields=(width, height));
+gen_struct_from_to_impls!(LogicalSize, fields = (width, height));
-#[derive(Debug, Clone, PartialEq)]
+#[derive(Debug, Clone, PartialEq, Reflection)]
pub enum Size
{
Physical(PhysicalSize<u32>),
- Logical(LogicalSize<f64>)
+ Logical(LogicalSize<f64>),
}
-gen_enum_from_to_impls!(Size, variants=(Physical, Logical));
+gen_enum_from_to_impls!(Size, variants = (Physical, Logical));
diff --git a/engine/src/windowing/mouse.rs b/engine/src/windowing/mouse.rs
index 3145a17..93a0d93 100644
--- a/engine/src/windowing/mouse.rs
+++ b/engine/src/windowing/mouse.rs
@@ -1,10 +1,11 @@
use std::collections::HashMap;
use crate::ecs::Sole;
+use crate::reflection::Reflection;
use crate::vector::Vec2;
use crate::windowing::dpi::PhysicalPosition;
-#[derive(Debug, Default, Clone, Sole)]
+#[derive(Debug, Default, Clone, Sole, Reflection)]
#[non_exhaustive]
pub struct Mouse
{
@@ -21,7 +22,7 @@ pub struct Mouse
pub curr_tick_scroll_delta: ScrollDelta,
}
-#[derive(Debug, Clone, Default)]
+#[derive(Debug, Clone, Default, Reflection)]
pub struct ScrollDelta
{
pub vert_lines: f32,
diff --git a/engine/src/windowing/window.rs b/engine/src/windowing/window.rs
index 8f95dc8..54c24ac 100644
--- a/engine/src/windowing/window.rs
+++ b/engine/src/windowing/window.rs
@@ -21,7 +21,7 @@ impl Id
}
}
-#[derive(Debug, Component, Clone)]
+#[derive(Debug, Component, Clone, Reflection)]
#[non_exhaustive]
pub struct CreationAttributes
{
@@ -165,7 +165,7 @@ impl Default for CreationAttributes
}
}
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Reflection)]
#[non_exhaustive]
pub enum Fullscreen
{
@@ -173,7 +173,7 @@ pub enum Fullscreen
}
/// Window icon
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Reflection)]
#[non_exhaustive]
pub enum Icon
{
@@ -183,7 +183,7 @@ pub enum Icon
WindowsResource(Cow<'static, str>),
}
-#[derive(Debug, Component, Clone, Copy)]
+#[derive(Debug, Default, Component, Clone, Copy, Reflection)]
pub struct CreationReady;
#[derive(Debug, Component, Reflection)]
@@ -254,7 +254,7 @@ impl Window
}
}
-#[derive(Debug, Component)]
+#[derive(Debug, Component, Reflection)]
pub struct Closed;
#[derive(