diff --git a/lyra-ecs/Cargo.toml b/lyra-ecs/Cargo.toml index 5c9afd2..8249429 100644 --- a/lyra-ecs/Cargo.toml +++ b/lyra-ecs/Cargo.toml @@ -5,10 +5,14 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html +[features] +math = ["dep:glam"] + [dependencies] lyra-ecs-derive = { path = "./lyra-ecs-derive" } anyhow = "1.0.75" thiserror = "1.0.50" +glam = { version = "0.24.0", optional = true } [dev-dependencies] rand = "0.8.5" # used for tests diff --git a/lyra-ecs/src/lib.rs b/lyra-ecs/src/lib.rs index f42b377..e22f7f8 100644 --- a/lyra-ecs/src/lib.rs +++ b/lyra-ecs/src/lib.rs @@ -34,6 +34,10 @@ pub mod system; pub mod tick; pub use tick::*; +/// Implements Component for glam math types +#[cfg(feature = "math")] +pub mod math; + pub use lyra_ecs_derive::*; #[cfg(test)] diff --git a/lyra-ecs/src/math.rs b/lyra-ecs/src/math.rs new file mode 100644 index 0000000..045b70f --- /dev/null +++ b/lyra-ecs/src/math.rs @@ -0,0 +1,19 @@ +use crate::Component; + +use glam::{Vec3, Quat, Vec2, Vec4, Mat4}; + +macro_rules! impl_component_math { + ($type: ident) => { + impl Component for $type { + fn name() -> &'static str { + stringify!($type) + } + } + }; +} + +impl_component_math!(Vec2); +impl_component_math!(Vec3); +impl_component_math!(Vec4); +impl_component_math!(Mat4); +impl_component_math!(Quat); \ No newline at end of file