Skip to content

Commit

Permalink
Merge branch 'main' into ColorOpsOnColor
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile committed May 13, 2024
2 parents 1bc07bf + 62bb83c commit 2d73b3c
Show file tree
Hide file tree
Showing 126 changed files with 5,398 additions and 2,380 deletions.
5 changes: 5 additions & 0 deletions .cargo/config_fast_builds.toml
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,8 @@ rustflags = [
# In most cases the gains are negligible, but if you are on macos and have slow compile times you should see significant gains.
# [profile.dev]
# debug = 1

# This is enables you to run the CI tool using `cargo ci`.
# This is not enabled by default, you need to copy this file to `config.toml`.
[alias]
ci = "run --package ci --"
1 change: 0 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,3 @@ jobs:
title: "Preparing Next Release"
body: |
Preparing next release. This PR has been auto-generated.
UI tests have not been automatically bumped to the latest version, please fix them manually.
27 changes: 21 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ workspace = true
default = [
"animation",
"bevy_asset",
"bevy_state",
"bevy_audio",
"bevy_color",
"bevy_gilrs",
Expand Down Expand Up @@ -334,6 +335,9 @@ meshlet_processor = ["bevy_internal/meshlet_processor"]
# Enable support for the ios_simulator by downgrading some rendering capabilities
ios_simulator = ["bevy_internal/ios_simulator"]

# Enable built in global state machines
bevy_state = ["bevy_internal/bevy_state"]

[dependencies]
bevy_internal = { path = "crates/bevy_internal", version = "0.14.0-dev", default-features = false }

Expand Down Expand Up @@ -1729,35 +1733,35 @@ wasm = false

[[example]]
name = "state"
path = "examples/ecs/state.rs"
path = "examples/state/state.rs"
doc-scrape-examples = true

[package.metadata.example.state]
name = "State"
description = "Illustrates how to use States to control transitioning from a Menu state to an InGame state"
category = "ECS (Entity Component System)"
category = "State"
wasm = false

[[example]]
name = "sub_states"
path = "examples/ecs/sub_states.rs"
path = "examples/state/sub_states.rs"
doc-scrape-examples = true

[package.metadata.example.sub_states]
name = "Sub States"
description = "Using Sub States for hierarchical state handling."
category = "ECS (Entity Component System)"
category = "State"
wasm = false

[[example]]
name = "computed_states"
path = "examples/ecs/computed_states.rs"
path = "examples/state/computed_states.rs"
doc-scrape-examples = true

[package.metadata.example.computed_states]
name = "Computed States"
description = "Advanced state patterns using Computed States"
category = "ECS (Entity Component System)"
category = "State"
wasm = false

[[example]]
Expand Down Expand Up @@ -3022,6 +3026,17 @@ description = "Demonstrates the clearcoat PBR feature"
category = "3D Rendering"
wasm = false

[[example]]
name = "depth_of_field"
path = "examples/3d/depth_of_field.rs"
doc-scrape-examples = true

[package.metadata.example.depth_of_field]
name = "Depth of field"
description = "Demonstrates depth of field"
category = "3D Rendering"
wasm = false

[profile.wasm-release]
inherits = "release"
opt-level = "z"
Expand Down
Binary file not shown.
Binary file not shown.
6 changes: 3 additions & 3 deletions crates/bevy_animation/src/animatable.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::util;
use bevy_color::{ClampColor, Laba, LinearRgba, Oklaba, Srgba, Xyza};
use bevy_color::{Laba, LinearRgba, Oklaba, Srgba, Xyza};
use bevy_ecs::world::World;
use bevy_math::*;
use bevy_reflect::Reflect;
Expand Down Expand Up @@ -63,7 +63,7 @@ macro_rules! impl_color_animatable {
#[inline]
fn interpolate(a: &Self, b: &Self, t: f32) -> Self {
let value = *a * (1. - t) + *b * t;
value.clamped()
value
}

#[inline]
Expand All @@ -76,7 +76,7 @@ macro_rules! impl_color_animatable {
value = Self::interpolate(&value, &input.value, input.weight);
}
}
value.clamped()
value
}
}
};
Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ keywords = ["bevy"]
[features]
trace = []
bevy_debug_stepping = []
default = ["bevy_reflect"]
default = ["bevy_reflect", "bevy_state"]
bevy_reflect = ["dep:bevy_reflect", "bevy_ecs/bevy_reflect"]
serialize = ["bevy_ecs/serde"]
bevy_state = ["dep:bevy_state"]

[dependencies]
# bevy
Expand All @@ -22,6 +23,7 @@ bevy_ecs = { path = "../bevy_ecs", version = "0.14.0-dev", default-features = fa
bevy_reflect = { path = "../bevy_reflect", version = "0.14.0-dev", optional = true }
bevy_utils = { path = "../bevy_utils", version = "0.14.0-dev" }
bevy_tasks = { path = "../bevy_tasks", version = "0.14.0-dev" }
bevy_state = { path = "../bevy_state", optional = true, version = "0.14.0-dev" }

# other
serde = { version = "1.0", features = ["derive"], optional = true }
Expand Down
42 changes: 13 additions & 29 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use bevy_ecs::{
event::{event_update_system, ManualEventReader},
intern::Interned,
prelude::*,
schedule::{FreelyMutableState, ScheduleBuildSettings, ScheduleLabel},
schedule::{ScheduleBuildSettings, ScheduleLabel},
system::SystemId,
};
#[cfg(feature = "bevy_state")]
use bevy_state::{prelude::*, state::FreelyMutableState};
#[cfg(feature = "trace")]
use bevy_utils::tracing::info_span;
use bevy_utils::{tracing::debug, HashMap};
Expand Down Expand Up @@ -264,6 +266,7 @@ impl App {
self.sub_apps.iter().any(|s| s.is_building_plugins())
}

#[cfg(feature = "bevy_state")]
/// Initializes a [`State`] with standard starting values.
///
/// This method is idempotent: it has no effect when called again using the same generic type.
Expand All @@ -281,6 +284,7 @@ impl App {
self
}

#[cfg(feature = "bevy_state")]
/// Inserts a specific [`State`] to the current [`App`] and overrides any [`State`] previously
/// added of the same type.
///
Expand All @@ -297,23 +301,19 @@ impl App {
self
}

#[cfg(feature = "bevy_state")]
/// Sets up a type implementing [`ComputedStates`].
///
/// This method is idempotent: it has no effect when called again using the same generic type.
///
/// For each source state the derived state depends on, it adds this state's derivation
/// to it's [`ComputeDependantStates<Source>`](bevy_ecs::schedule::ComputeDependantStates<S>) schedule.
pub fn add_computed_state<S: ComputedStates>(&mut self) -> &mut Self {
self.main_mut().add_computed_state::<S>();
self
}

#[cfg(feature = "bevy_state")]
/// Sets up a type implementing [`SubStates`].
///
/// This method is idempotent: it has no effect when called again using the same generic type.
///
/// For each source state the derived state depends on, it adds this state's existence check
/// to it's [`ComputeDependantStates<Source>`](bevy_ecs::schedule::ComputeDependantStates<S>) schedule.
pub fn add_sub_state<S: SubStates>(&mut self) -> &mut Self {
self.main_mut().add_sub_state::<S>();
self
Expand Down Expand Up @@ -983,10 +983,7 @@ impl Termination for AppExit {
mod tests {
use std::{marker::PhantomData, mem};

use bevy_ecs::{
schedule::{OnEnter, States},
system::Commands,
};
use bevy_ecs::{schedule::ScheduleLabel, system::Commands};

use crate::{App, AppExit, Plugin};

Expand Down Expand Up @@ -1059,11 +1056,9 @@ mod tests {
App::new().add_plugins(PluginRun);
}

#[derive(States, PartialEq, Eq, Debug, Default, Hash, Clone)]
enum AppState {
#[default]
MainMenu,
}
#[derive(ScheduleLabel, Hash, Clone, PartialEq, Eq, Debug)]
struct EnterMainMenu;

fn bar(mut commands: Commands) {
commands.spawn_empty();
}
Expand All @@ -1075,20 +1070,9 @@ mod tests {
#[test]
fn add_systems_should_create_schedule_if_it_does_not_exist() {
let mut app = App::new();
app.init_state::<AppState>()
.add_systems(OnEnter(AppState::MainMenu), (foo, bar));

app.world_mut().run_schedule(OnEnter(AppState::MainMenu));
assert_eq!(app.world().entities().len(), 2);
}

#[test]
fn add_systems_should_create_schedule_if_it_does_not_exist2() {
let mut app = App::new();
app.add_systems(OnEnter(AppState::MainMenu), (foo, bar))
.init_state::<AppState>();
app.add_systems(EnterMainMenu, (foo, bar));

app.world_mut().run_schedule(OnEnter(AppState::MainMenu));
app.world_mut().run_schedule(EnterMainMenu);
assert_eq!(app.world().entities().len(), 2);
}

Expand Down
4 changes: 3 additions & 1 deletion crates/bevy_app/src/main_schedule.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use crate::{App, Plugin};
use bevy_ecs::{
schedule::{ExecutorKind, InternedScheduleLabel, Schedule, ScheduleLabel, StateTransition},
schedule::{ExecutorKind, InternedScheduleLabel, Schedule, ScheduleLabel},
system::{Local, Resource},
world::{Mut, World},
};
#[cfg(feature = "bevy_state")]
use bevy_state::state::StateTransition;

/// The schedule that contains the app logic that is evaluated each tick of [`App::update()`].
///
Expand Down
15 changes: 11 additions & 4 deletions crates/bevy_app/src/sub_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ use crate::{App, InternedAppLabel, Plugin, Plugins, PluginsState, Startup};
use bevy_ecs::{
event::EventRegistry,
prelude::*,
schedule::{
setup_state_transitions_in_world, FreelyMutableState, InternedScheduleLabel,
ScheduleBuildSettings, ScheduleLabel,
},
schedule::{InternedScheduleLabel, ScheduleBuildSettings, ScheduleLabel},
system::SystemId,
};
#[cfg(feature = "bevy_state")]
use bevy_state::{
prelude::*,
state::{setup_state_transitions_in_world, FreelyMutableState},
};

#[cfg(feature = "trace")]
use bevy_utils::tracing::info_span;
use bevy_utils::{HashMap, HashSet};
Expand Down Expand Up @@ -295,6 +298,7 @@ impl SubApp {
self
}

#[cfg(feature = "bevy_state")]
/// See [`App::init_state`].
pub fn init_state<S: FreelyMutableState + FromWorld>(&mut self) -> &mut Self {
if !self.world.contains_resource::<State<S>>() {
Expand All @@ -309,6 +313,7 @@ impl SubApp {
self
}

#[cfg(feature = "bevy_state")]
/// See [`App::insert_state`].
pub fn insert_state<S: FreelyMutableState>(&mut self, state: S) -> &mut Self {
if !self.world.contains_resource::<State<S>>() {
Expand All @@ -324,6 +329,7 @@ impl SubApp {
self
}

#[cfg(feature = "bevy_state")]
/// See [`App::add_computed_state`].
pub fn add_computed_state<S: ComputedStates>(&mut self) -> &mut Self {
if !self
Expand All @@ -339,6 +345,7 @@ impl SubApp {
self
}

#[cfg(feature = "bevy_state")]
/// See [`App::add_sub_state`].
pub fn add_sub_state<S: SubStates>(&mut self) -> &mut Self {
if !self
Expand Down
6 changes: 5 additions & 1 deletion crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ bevy_winit = { path = "../bevy_winit", version = "0.14.0-dev" }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { version = "0.2" }
web-sys = { version = "0.3", features = ["Request", "Window", "Response"] }
web-sys = { version = "0.3", features = [
"Window",
"Response",
"WorkerGlobalScope",
] }
wasm-bindgen-futures = "0.4"
js-sys = "0.3"

Expand Down
1 change: 1 addition & 0 deletions crates/bevy_color/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ homepage = "https://bevyengine.org"
repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
keywords = ["bevy", "color"]
rust-version = "1.76.0"

[dependencies]
bevy_math = { path = "../bevy_math", version = "0.14.0-dev" }
Expand Down
35 changes: 20 additions & 15 deletions crates/bevy_color/src/color_ops.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use bevy_math::{Vec3, Vec4};

/// Methods for changing the luminance of a color. Note that these methods are not
/// guaranteed to produce consistent results across color spaces,
/// but will be within a given space.
Expand Down Expand Up @@ -80,21 +82,24 @@ pub trait Hue: Sized {
}
}

/// Trait with methods for asserting a colorspace is within bounds.
///
/// During ordinary usage (e.g. reading images from disk, rendering images, picking colors for UI), colors should always be within their ordinary bounds (such as 0 to 1 for RGB colors).
/// However, some applications, such as high dynamic range rendering or bloom rely on unbounded colors to naturally represent a wider array of choices.
pub trait ClampColor: Sized {
/// Return a new version of this color clamped, with all fields in bounds.
fn clamped(&self) -> Self;

/// Changes all the fields of this color to ensure they are within bounds.
fn clamp(&mut self) {
*self = self.clamped();
}

/// Are all the fields of this color in bounds?
fn is_within_bounds(&self) -> bool;
/// Trait with methods for converting colors to non-color types
pub trait ColorToComponents {
/// Convert to an f32 array
fn to_f32_array(self) -> [f32; 4];
/// Convert to an f32 array without the alpha value
fn to_f32_array_no_alpha(self) -> [f32; 3];
/// Convert to a Vec4
fn to_vec4(self) -> Vec4;
/// Convert to a Vec3
fn to_vec3(self) -> Vec3;
/// Convert from an f32 array
fn from_f32_array(color: [f32; 4]) -> Self;
/// Convert from an f32 array without the alpha value
fn from_f32_array_no_alpha(color: [f32; 3]) -> Self;
/// Convert from a Vec4
fn from_vec4(color: Vec4) -> Self;
/// Convert from a Vec3
fn from_vec3(color: Vec3) -> Self;
}

/// Utility function for interpolating hue values. This ensures that the interpolation
Expand Down

0 comments on commit 2d73b3c

Please sign in to comment.