Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support glam and macaw types #85

Merged
merged 4 commits into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Unreleased

- Everything :scream:
- **added:** Add `Reflect` impls for [`glam`] types ([#85])
- **added:** Add `Reflect` impls for [`macaw`] types ([#85])

[#85]: https://github.com/EmbarkStudios/mirror-mirror/pull/85
[`glam`]: https://crates.io/crates/glam
[`macaw`]: https://crates.io/crates/macaw

# 0.1.0 (12. January, 2023)

- Initial release.
4 changes: 4 additions & 0 deletions crates/mirror-mirror/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ default = ["speedy", "serde", "std"]
std = ["dep:syn"]
speedy = ["std", "dep:speedy"]
serde = ["dep:serde"]
glam = ["dep:glam"]
macaw = ["dep:macaw"]

[dependencies]
ahash = { version = "0.8.2", default-features = false }
Expand All @@ -24,6 +26,8 @@ ordered-float = { version = "3.4.0", default-features = false }
serde = { version = "1.0", default-features = false, features = ["derive", "alloc"], optional = true }
speedy = { version = "0.8", optional = true }
syn = { version = "1.0.102", features = ["full", "parsing"], optional = true }
glam = { version = "0.22", optional = true }
macaw = { version = "0.18", optional = true }

[package.metadata.docs.rs]
all-features = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,52 @@ __private_derive_reflect_foreign! {
end: Idx,
}
}

#[cfg(feature = "glam")]
mod glam_impls {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to put this in an glam.rs file? It's a bit weird to have it in the mod.rs module here (I did look for it in another file when trying that PR locally.)

use glam::{Mat3, Vec2, Vec3};
use mirror_mirror_macros::__private_derive_reflect_foreign;

__private_derive_reflect_foreign! {
#[reflect(crate_name(crate))]
pub struct Vec2 {
pub x: f32,
pub y: f32,
}
}

__private_derive_reflect_foreign! {
#[reflect(crate_name(crate))]
pub struct Vec3 {
pub x: f32,
pub y: f32,
pub z: f32,
}
}

// `Vec4`, `Quat`, and `Mat2` are left out because glam uses bad hacks which changes the struct
// definitions for different architectures (simd vs no simd) and cargo features. So we'd have
// to use the same hacks in mirror-mirror which I'd like to avoid.

// `Mat4` is left out because it contains `Vec4` which we don't support.

__private_derive_reflect_foreign! {
#[reflect(crate_name(crate))]
pub struct Mat3 {
pub x_axis: Vec3,
pub y_axis: Vec3,
pub z_axis: Vec3,
}
}
}

#[cfg(feature = "macaw")]
mod macaw_impls {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto here; even if it makes for a tiny file, it's nice to have it separate from the rest of the core types imo

use macaw::ColorRgba8;
use mirror_mirror_macros::__private_derive_reflect_foreign;

__private_derive_reflect_foreign! {
#[reflect(crate_name(crate))]
pub struct ColorRgba8(pub [u8; 4]);
}
}
6 changes: 5 additions & 1 deletion crates/mirror-mirror/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,11 +205,15 @@
//! `std` | Enables using the standard library (`core` and `alloc` are always required) | Yes
//! `speedy` | Enables [`speedy`] support for most types | Yes
//! `serde` | Enables [`serde`] support for most types | Yes
//! `glam` | Enables impls for [`glam`] | No
//! `macaw` | Enables impls for [`macaw`] | No
//!
//! [`speedy`]: https://crates.io/crates/speedy
//! [`serde`]: https://crates.io/crates/serde
//! [`bevy_reflect`]: https://crates.io/crates/bevy_reflect
//! [`bevy`]: https://crates.io/crates/bevy
//! [`glam`]: https://crates.io/crates/glam
//! [`macaw`]: https://crates.io/crates/macaw

#![cfg_attr(not(feature = "std"), no_std)]
#![warn(
Expand Down Expand Up @@ -327,7 +331,7 @@ pub mod type_info;
/// Type erased value types.
pub mod value;

mod std_impls;
mod foreign_impls;

#[cfg(feature = "std")]
#[cfg(test)]
Expand Down