Skip to content

Commit

Permalink
Update to bevy 0.14 (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbrea-c authored Jul 7, 2024
1 parent 9e2cde1 commit 6176df2
Show file tree
Hide file tree
Showing 10 changed files with 599 additions and 560 deletions.
947 changes: 565 additions & 382 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bevy_utilitarian"
version = "0.4.0"
version = "0.5.0"
edition = "2021"
readme = "README.md"
license = "MIT OR Apache-2.0"
Expand All @@ -11,8 +11,8 @@ keywords = ["bevy", "gamedev", "utility", "interpolation", "math"]
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
serde = { version = "1.0.197", features = ["derive"] }
bevy = { version = "0.13", default-features = false, features = [
serde = { version = "1.0", features = ["derive"] }
bevy = { version = "0.14", default-features = false, features = [
"bevy_render",
] }
rand = "0.8.5"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,4 @@ Currently, this library offers:
| 0.2 | 0.12 |
| 0.3 | 0.12 |
| 0.4 | 0.13 |
| 0.5 | 0.14 |
114 changes: 0 additions & 114 deletions src/curves/color_point.rs

This file was deleted.

10 changes: 5 additions & 5 deletions src/curves/constant.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use super::{curve::AsParamCurve, point::Point};
use bevy::reflect::Reflect;
use super::curve::AsParamCurve;
use bevy::{math::VectorSpace, reflect::Reflect};
use serde::{Deserialize, Serialize};

#[derive(Reflect, Serialize, Deserialize, Clone, Debug)]
pub struct ConstantParamCurve<P: Point> {
pub struct ConstantParamCurve<P: VectorSpace> {
val: P,
}

impl<P: Point> ConstantParamCurve<P> {
impl<P: VectorSpace> ConstantParamCurve<P> {
pub fn new(val: P) -> Self {
Self { val }
}
}

impl<P: Point> AsParamCurve<P> for ConstantParamCurve<P> {
impl<P: VectorSpace> AsParamCurve<P> for ConstantParamCurve<P> {
fn get(&self, _: f32) -> P {
self.val
}
Expand Down
38 changes: 18 additions & 20 deletions src/curves/curve.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
use super::{
color_point::ColorPoint, constant::ConstantParamCurve, linear::LinearParamCurve, point::Point,
};
use bevy::reflect::Reflect;
use super::{constant::ConstantParamCurve, linear::LinearParamCurve};
use bevy::{color::LinearRgba, math::VectorSpace, reflect::Reflect};
use serde::{Deserialize, Serialize};

pub trait AsParamCurve<P: Point> {
pub trait AsParamCurve<P: VectorSpace> {
/// Get a point on the curve at the given `t` parameter value
///
/// `t` is a value between 0.0 and 1.0.
fn get(&self, t: f32) -> P;
}

#[derive(Reflect, Clone, Serialize, Deserialize, Debug)]
pub enum ParamCurve<P: Point> {
pub enum ParamCurve<P: VectorSpace> {
Linear(LinearParamCurve<P>),
Constant(ConstantParamCurve<P>),
}

impl<P: Point> ParamCurve<P> {
impl<P: VectorSpace> ParamCurve<P> {
pub fn linear_uniform(points: Vec<P>) -> Self {
Self::Linear(LinearParamCurve::continuous_uniform(points))
}
Expand All @@ -31,7 +29,7 @@ impl<P: Point> ParamCurve<P> {
}
}

impl<P: Point> AsParamCurve<P> for ParamCurve<P> {
impl<P: VectorSpace> AsParamCurve<P> for ParamCurve<P> {
fn get(&self, t: f32) -> P {
match self {
ParamCurve::Linear(c) => c.get(t),
Expand All @@ -40,36 +38,36 @@ impl<P: Point> AsParamCurve<P> for ParamCurve<P> {
}
}

pub type Gradient = ParamCurve<ColorPoint>;
pub type Gradient = ParamCurve<LinearRgba>;

#[cfg(test)]
mod tests {
use super::*;
use bevy::render::color::Color;
use bevy::color::LinearRgba;

#[test]
fn gradient_alpha_blending_works() {
let grad = Gradient::linear_uniform(vec![
ColorPoint::rgba(1., 1., 1., 1.),
ColorPoint::rgba(1., 1., 1., 0.),
LinearRgba::new(1., 1., 1., 1.),
LinearRgba::new(1., 1., 1., 0.),
]);

let mid = grad.get(0.5);

assert!(mid.a() - 0.5 < 0.000001);
assert!(mid.alpha - 0.5 < 0.000001);
}

#[test]
fn gradient_alpha_blending_works_large() {
let grad = Gradient::linear(vec![
(0., Color::rgba(300., 100., 1., 1.).into()),
(0.7, Color::rgba(3., 1., 1., 1.).into()),
(0.8, Color::rgba(1., 0.3, 0.3, 1.).into()),
(0.9, Color::rgba(0.3, 0.3, 0.3, 1.).into()),
(1., Color::rgba(0.1, 0.1, 0.1, 0.).into()),
(0., LinearRgba::new(300., 100., 1., 1.).into()),
(0.7, LinearRgba::new(3., 1., 1., 1.).into()),
(0.8, LinearRgba::new(1., 0.3, 0.3, 1.).into()),
(0.9, LinearRgba::new(0.3, 0.3, 0.3, 1.).into()),
(1., LinearRgba::new(0.1, 0.1, 0.1, 0.).into()),
]);

let col = *grad.get(0.9343);
assert!(col.a() - (1. - 0.343) < 0.000001);
let col = grad.get(0.9343);
assert!(col.alpha - (1. - 0.343) < 0.000001);
}
}
14 changes: 7 additions & 7 deletions src/curves/linear.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
use std::f32::consts::PI;

use super::{curve::AsParamCurve, point::Point};
use bevy::prelude::*;
use super::curve::AsParamCurve;
use bevy::{math::VectorSpace, prelude::*};
use serde::{Deserialize, Serialize};

#[derive(Reflect, Clone, Serialize, Deserialize, Debug)]
struct LinearSegment<P: Point> {
struct LinearSegment<P: VectorSpace> {
pub start: P,
pub end: P,
}

impl<P: Point> LinearSegment<P> {
impl<P: VectorSpace> LinearSegment<P> {
pub fn new(start: P, end: P) -> Self {
Self { start, end }
}
Expand All @@ -21,12 +21,12 @@ impl<P: Point> LinearSegment<P> {
}

#[derive(Reflect, Clone, Serialize, Deserialize, Debug)]
pub struct LinearParamCurve<P: Point> {
pub struct LinearParamCurve<P: VectorSpace> {
/// List of the `t` value at the start of the segment, followed by line segment
segments: Vec<(f32, LinearSegment<P>)>,
}

impl<P: Point> LinearParamCurve<P> {
impl<P: VectorSpace> LinearParamCurve<P> {
pub fn new(segments: impl IntoIterator<Item = (f32, P, P)>) -> Self {
let segments: Vec<(f32, LinearSegment<P>)> = segments
.into_iter()
Expand Down Expand Up @@ -88,7 +88,7 @@ impl<P: Point> LinearParamCurve<P> {
}
}

impl<P: Point> AsParamCurve<P> for LinearParamCurve<P> {
impl<P: VectorSpace> AsParamCurve<P> for LinearParamCurve<P> {
fn get(&self, t: f32) -> P {
let t = t.clamp(0., 1.);

Expand Down
2 changes: 0 additions & 2 deletions src/curves/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
pub mod color_point;
pub mod constant;
pub mod curve;
pub mod linear;
pub mod point;
25 changes: 0 additions & 25 deletions src/curves/point.rs

This file was deleted.

2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@ pub mod steppers;
pub mod prelude {
use super::*;
pub use curves::{
color_point::ColorPoint,
constant::ConstantParamCurve,
curve::{AsParamCurve, Gradient, ParamCurve},
linear::LinearParamCurve,
point::Point,
};
pub use geometric::{pitchyaw::PitchYaw, pitchyawclamped::PitchYawClamped};
pub use randomized_values::{RandF32, RandValue, RandVec3};
Expand Down

0 comments on commit 6176df2

Please sign in to comment.