Skip to content

Commit

Permalink
Merge branch 'bevyengine:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
BeastLe9enD authored Aug 31, 2024
2 parents dd5cc5c + ffe0f7f commit 92b0a9a
Show file tree
Hide file tree
Showing 189 changed files with 7,714 additions and 4,143 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Check for typos
uses: crate-ci/typos@v1.23.6
uses: crate-ci/typos@v1.24.1
- name: Typos info
if: failure()
run: |
Expand Down
20 changes: 15 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,6 @@ trace_tracy_memory = [
# Tracing support
trace = ["bevy_internal/trace"]

# Save a trace of all wgpu calls
wgpu_trace = ["bevy_internal/wgpu_trace"]

# EXR image format support
exr = ["bevy_internal/exr"]

Expand Down Expand Up @@ -1410,7 +1407,8 @@ doc-scrape-examples = true
name = "Custom Asset IO"
description = "Implements a custom AssetReader"
category = "Assets"
wasm = true
# Incompatible with the asset path patching of the example-showcase tool
wasm = false

[[example]]
name = "embedded_asset"
Expand All @@ -1432,7 +1430,8 @@ doc-scrape-examples = true
name = "Extra asset source"
description = "Load an asset from a non-standard asset source"
category = "Assets"
wasm = true
# Uses non-standard asset path
wasm = false

[[example]]
name = "hot_asset_reloading"
Expand Down Expand Up @@ -3387,6 +3386,17 @@ description = "Demonstrates how to use picking events to spawn simple objects"
category = "Picking"
wasm = true

[[example]]
name = "sprite_picking"
path = "examples/picking/sprite_picking.rs"
doc-scrape-examples = true

[package.metadata.example.sprite_picking]
name = "Sprite Picking"
description = "Demonstrates picking sprites and sprite atlases"
category = "Picking"
wasm = true

[profile.wasm-release]
inherits = "release"
opt-level = "z"
Expand Down
19 changes: 6 additions & 13 deletions benches/benches/bevy_ecs/world/commands.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::mem::size_of;

use bevy_ecs::{
component::Component,
entity::Entity,
Expand Down Expand Up @@ -44,19 +45,11 @@ pub fn spawn_commands(criterion: &mut Criterion) {
bencher.iter(|| {
let mut commands = Commands::new(&mut command_queue, &world);
for i in 0..entity_count {
let mut entity = commands.spawn_empty();

if black_box(i % 2 == 0) {
entity.insert(A);
}

if black_box(i % 3 == 0) {
entity.insert(B);
}

if black_box(i % 4 == 0) {
entity.insert(C);
}
let mut entity = commands
.spawn_empty()
.insert_if(A, || black_box(i % 2 == 0))
.insert_if(B, || black_box(i % 3 == 0))
.insert_if(C, || black_box(i % 4 == 0));

if black_box(i % 5 == 0) {
entity.despawn();
Expand Down
20 changes: 18 additions & 2 deletions crates/bevy_animation/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@
use std::io::{self, Write};
use std::ops::{Index, IndexMut};

use bevy_asset::io::Reader;
use bevy_asset::{Asset, AssetId, AssetLoader, AssetPath, Handle, LoadContext};
use bevy_asset::{io::Reader, Asset, AssetId, AssetLoader, AssetPath, Handle, LoadContext};
use bevy_reflect::{Reflect, ReflectSerialize};
use petgraph::graph::{DiGraph, NodeIndex};
use ron::de::SpannedError;
Expand Down Expand Up @@ -192,6 +191,23 @@ impl AnimationGraph {
(graph, node_index)
}

/// A convenience method to create an [`AnimationGraph`]s with an iterator
/// of clips.
///
/// All of the animation clips will be direct children of the root with
/// weight 1.0.
///
/// Returns the the graph and indices of the new nodes.
pub fn from_clips<'a, I>(clips: I) -> (Self, Vec<AnimationNodeIndex>)
where
I: IntoIterator<Item = Handle<AnimationClip>>,
<I as IntoIterator>::IntoIter: 'a,
{
let mut graph = Self::new();
let indices = graph.add_clips(clips, 1.0, graph.root).collect();
(graph, indices)
}

/// Adds an [`AnimationClip`] to the animation graph with the given weight
/// and returns its index.
///
Expand Down
24 changes: 13 additions & 11 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,19 @@ use std::ops::{Add, Mul};
use bevy_app::{App, Plugin, PostUpdate};
use bevy_asset::{Asset, AssetApp, Assets, Handle};
use bevy_core::Name;
use bevy_ecs::entity::MapEntities;
use bevy_ecs::prelude::*;
use bevy_ecs::reflect::ReflectMapEntities;
use bevy_ecs::{entity::MapEntities, prelude::*, reflect::ReflectMapEntities};
use bevy_math::{FloatExt, Quat, Vec3};
use bevy_reflect::Reflect;
use bevy_render::mesh::morph::MorphWeights;
use bevy_time::Time;
use bevy_transform::{prelude::Transform, TransformSystem};
use bevy_utils::hashbrown::HashMap;
use bevy_utils::{
hashbrown::HashMap,
tracing::{error, trace},
NoOpHash,
};
use fixedbitset::FixedBitSet;
use graph::{AnimationGraph, AnimationNodeIndex};
use petgraph::graph::NodeIndex;
use petgraph::Direction;
use prelude::{AnimationGraphAssetLoader, AnimationTransitions};
use petgraph::{graph::NodeIndex, Direction};
use thread_local::ThreadLocal;
use uuid::Uuid;

Expand All @@ -51,7 +46,10 @@ pub mod prelude {
};
}

use crate::transition::{advance_transitions, expire_completed_transitions};
use crate::{
graph::{AnimationGraph, AnimationGraphAssetLoader, AnimationNodeIndex},
transition::{advance_transitions, expire_completed_transitions, AnimationTransitions},
};

/// The [UUID namespace] of animation targets (e.g. bones).
///
Expand Down Expand Up @@ -442,8 +440,9 @@ impl ActiveAnimation {
}

/// Sets the weight of this animation.
pub fn set_weight(&mut self, weight: f32) {
pub fn set_weight(&mut self, weight: f32) -> &mut Self {
self.weight = weight;
self
}

/// Pause the animation.
Expand Down Expand Up @@ -528,7 +527,10 @@ impl ActiveAnimation {
}
}

/// Animation controls
/// Animation controls.
///
/// Automatically added to any root animations of a `SceneBundle` when it is
/// spawned.
#[derive(Component, Default, Reflect)]
#[reflect(Component)]
pub struct AnimationPlayer {
Expand Down
38 changes: 34 additions & 4 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use std::{
process::{ExitCode, Termination},
};
use std::{
num::NonZeroU8,
num::NonZero,
panic::{catch_unwind, resume_unwind, AssertUnwindSafe},
};
use thiserror::Error;
Expand Down Expand Up @@ -990,6 +990,36 @@ impl App {
}

/// Spawns an [`Observer`] entity, which will watch for and respond to the given event.
///
/// # Examples
///
/// ```rust
/// # use bevy_app::prelude::*;
/// # use bevy_ecs::prelude::*;
/// # use bevy_utils::default;
/// #
/// # let mut app = App::new();
/// #
/// # #[derive(Event)]
/// # struct Party {
/// # friends_allowed: bool,
/// # };
/// #
/// # #[derive(Event)]
/// # struct Invite;
/// #
/// # #[derive(Component)]
/// # struct Friend;
/// #
/// // An observer system can be any system where the first parameter is a trigger
/// app.observe(|trigger: Trigger<Party>, friends: Query<Entity, With<Friend>>, mut commands: Commands| {
/// if trigger.event().friends_allowed {
/// for friend in friends.iter() {
/// commands.trigger_targets(Invite, friend);
/// }
/// }
/// });
/// ```
pub fn observe<E: Event, B: Bundle, M>(
&mut self,
observer: impl IntoObserverSystem<E, B, M>,
Expand Down Expand Up @@ -1031,14 +1061,14 @@ pub enum AppExit {
Success,
/// The [`App`] experienced an unhandleable error.
/// Holds the exit code we expect our app to return.
Error(NonZeroU8),
Error(NonZero<u8>),
}

impl AppExit {
/// Creates a [`AppExit::Error`] with a error code of 1.
#[must_use]
pub const fn error() -> Self {
Self::Error(NonZeroU8::MIN)
Self::Error(NonZero::<u8>::MIN)
}

/// Returns `true` if `self` is a [`AppExit::Success`].
Expand All @@ -1059,7 +1089,7 @@ impl AppExit {
/// [`AppExit::Error`] is constructed.
#[must_use]
pub const fn from_code(code: u8) -> Self {
match NonZeroU8::new(code) {
match NonZero::<u8>::new(code) {
Some(code) => Self::Error(code),
None => Self::Success,
}
Expand Down
1 change: 1 addition & 0 deletions crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ bevy_tasks = { path = "../bevy_tasks", version = "0.15.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.15.0-dev" }

stackfuture = "0.3"
atomicow = "1.0"
async-broadcast = "0.5"
async-fs = "2.0"
async-lock = "3.0"
Expand Down
20 changes: 19 additions & 1 deletion crates/bevy_asset/src/io/embedded/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ impl EmbeddedAssetRegistry {
self.dir.insert_meta(asset_path, value);
}

/// Removes an asset stored using `full_path` (the full path as [`file`] would return for that file, if it was capable of
/// running in a non-rust file). If no asset is stored with at `full_path` its a no-op.
/// It returning `Option` contains the originally stored `Data` or `None`.
pub fn remove_asset(&self, full_path: &Path) -> Option<super::memory::Data> {
self.dir.remove_asset(full_path)
}

/// Registers a `embedded` [`AssetSource`] that uses this [`EmbeddedAssetRegistry`].
// NOTE: unused_mut because embedded_watcher feature is the only mutable consumer of `let mut source`
#[allow(unused_mut)]
Expand Down Expand Up @@ -300,7 +307,7 @@ macro_rules! load_internal_binary_asset {

#[cfg(test)]
mod tests {
use super::_embedded_asset_path;
use super::{EmbeddedAssetRegistry, _embedded_asset_path};
use std::path::Path;

// Relative paths show up if this macro is being invoked by a local crate.
Expand Down Expand Up @@ -404,4 +411,15 @@ mod tests {
// Really, should be "my_crate/src/the/asset.png"
assert_eq!(asset_path, Path::new("my_crate/the/asset.png"));
}

#[test]
fn remove_embedded_asset() {
let reg = EmbeddedAssetRegistry::default();
let path = std::path::PathBuf::from("a/b/asset.png");
reg.insert_asset(path.clone(), &path, &[]);
assert!(reg.dir.get_asset(&path).is_some());
assert!(reg.remove_asset(&path).is_some());
assert!(reg.dir.get_asset(&path).is_none());
assert!(reg.remove_asset(&path).is_none());
}
}
11 changes: 11 additions & 0 deletions crates/bevy_asset/src/io/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ impl Dir {
);
}

/// Removes the stored asset at `path` and returns the `Data` stored if found and otherwise `None`.
pub fn remove_asset(&self, path: &Path) -> Option<Data> {
let mut dir = self.clone();
if let Some(parent) = path.parent() {
dir = self.get_or_insert_dir(parent);
}
let key: Box<str> = path.file_name().unwrap().to_string_lossy().into();
let data = dir.0.write().assets.remove(&key);
data
}

pub fn insert_meta(&self, path: &Path, value: impl Into<Value>) {
let mut dir = self.clone();
if let Some(parent) = path.parent() {
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_asset/src/io/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use crate::{
io::{processor_gated::ProcessorGatedReader, AssetSourceEvent, AssetWatcher},
processor::AssetProcessorData,
};
use atomicow::CowArc;
use bevy_ecs::system::Resource;
use bevy_utils::tracing::{error, warn};
use bevy_utils::{CowArc, Duration, HashMap};
use bevy_utils::{Duration, HashMap};
use std::{fmt::Display, hash::Hash, sync::Arc};
use thiserror::Error;

Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_asset/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ use crate::{
Asset, AssetLoadError, AssetServer, AssetServerMode, Assets, Handle, UntypedAssetId,
UntypedHandle,
};
use atomicow::CowArc;
use bevy_ecs::world::World;
use bevy_utils::{BoxedFuture, ConditionalSendFuture, CowArc, HashMap, HashSet};
use bevy_utils::{BoxedFuture, ConditionalSendFuture, HashMap, HashSet};
use downcast_rs::{impl_downcast, Downcast};
use ron::error::SpannedError;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion crates/bevy_asset/src/path.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::io::AssetSourceId;
use atomicow::CowArc;
use bevy_reflect::{Reflect, ReflectDeserialize, ReflectSerialize};
use bevy_utils::CowArc;
use serde::{de::Visitor, Deserialize, Serialize};
use std::{
fmt::{Debug, Display},
Expand Down
3 changes: 2 additions & 1 deletion crates/bevy_asset/src/saver.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::transformer::TransformedAsset;
use crate::{io::Writer, meta::Settings, Asset, ErasedLoadedAsset};
use crate::{AssetLoader, Handle, LabeledAsset, UntypedHandle};
use bevy_utils::{BoxedFuture, ConditionalSendFuture, CowArc, HashMap};
use atomicow::CowArc;
use bevy_utils::{BoxedFuture, ConditionalSendFuture, HashMap};
use serde::{Deserialize, Serialize};
use std::{borrow::Borrow, hash::Hash, ops::Deref};

Expand Down
Loading

0 comments on commit 92b0a9a

Please sign in to comment.