Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into bind_group_entries
Browse files Browse the repository at this point in the history
  • Loading branch information
robtfm committed Sep 13, 2023
2 parents 1176372 + 72b8f47 commit b563313
Show file tree
Hide file tree
Showing 218 changed files with 11,655 additions and 5,341 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,7 @@ dxil.dll

# Generated by "examples/scene/scene.rs"
assets/scenes/load_scene_example-new.scn.ron

assets/**/*.meta
crates/bevy_asset/imported_assets
imported_assets
51 changes: 40 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ default = [
"zstd",
"vorbis",
"x11",
"filesystem_watcher",
"bevy_gizmos",
"android_shared_stdcxx",
"tonemapping_luts",
Expand Down Expand Up @@ -194,9 +193,6 @@ symphonia-vorbis = ["bevy_internal/symphonia-vorbis"]
# WAV audio format support (through symphonia)
symphonia-wav = ["bevy_internal/symphonia-wav"]

# Enable watching file system for asset hot reload
filesystem_watcher = ["bevy_internal/filesystem_watcher"]

# Enable serialization support through serde
serialize = ["bevy_internal/serialize"]

Expand All @@ -215,9 +211,6 @@ subpixel_glyph_atlas = ["bevy_internal/subpixel_glyph_atlas"]
# Enable systems that allow for automated testing on CI
bevy_ci_testing = ["bevy_internal/bevy_ci_testing"]

# Enable the "debug asset server" for hot reloading internal assets
debug_asset_server = ["bevy_internal/debug_asset_server"]

# Enable animation support, and glTF animation loading
animation = ["bevy_internal/animation", "bevy_animation"]

Expand Down Expand Up @@ -248,6 +241,9 @@ shader_format_spirv = ["bevy_internal/shader_format_spirv"]
# Enable some limitations to be able to use WebGL2. If not enabled, it will default to WebGPU in Wasm
webgl2 = ["bevy_internal/webgl"]

# Enables watching the filesystem for Bevy Asset hot-reloading
filesystem_watcher = ["bevy_internal/filesystem_watcher"]

[dependencies]
bevy_dylib = { path = "crates/bevy_dylib", version = "0.12.0-dev", default-features = false, optional = true }
bevy_internal = { path = "crates/bevy_internal", version = "0.12.0-dev", default-features = false }
Expand Down Expand Up @@ -294,6 +290,16 @@ description = "Changes the transform of a sprite"
category = "2D Rendering"
wasm = true

[[example]]
name = "2d_viewport_to_world"
path = "examples/2d/2d_viewport_to_world.rs"

[package.metadata.example.2d_viewport_to_world]
name = "2D Viewport To World"
description = "Demonstrates how to use the `Camera::viewport_to_world_2d` method"
category = "2D Rendering"
wasm = true

[[example]]
name = "rotation"
path = "examples/2d/rotation.rs"
Expand Down Expand Up @@ -471,6 +477,17 @@ description = "A scene showcasing the built-in 3D shapes"
category = "3D Rendering"
wasm = true

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

[package.metadata.example.3d_viewport_to_world]
name = "3D Viewport To World"
description = "Demonstrates how to use the `Camera::viewport_to_world` method"
category = "3D Rendering"
wasm = true

[[example]]
name = "generate_custom_mesh"
path = "examples/3d/generate_custom_mesh.rs"
Expand Down Expand Up @@ -1022,13 +1039,13 @@ category = "Assets"
wasm = true

[[example]]
name = "custom_asset_io"
path = "examples/asset/custom_asset_io.rs"
name = "custom_asset_reader"
path = "examples/asset/custom_asset_reader.rs"
doc-scrape-examples = true

[package.metadata.example.custom_asset_io]
[package.metadata.example.custom_asset_reader]
name = "Custom Asset IO"
description = "Implements a custom asset io loader"
description = "Implements a custom AssetReader"
category = "Assets"
wasm = true

Expand All @@ -1043,6 +1060,18 @@ description = "Demonstrates automatic reloading of assets when modified on disk"
category = "Assets"
wasm = true

[[example]]
name = "asset_processing"
path = "examples/asset/processing/processing.rs"
doc-scrape-examples = true
required-features = ["filesystem_watcher"]

[package.metadata.example.asset_processing]
name = "Asset Processing"
description = "Demonstrates how to process and load custom assets"
category = "Assets"
wasm = false

# Async Tasks
[[example]]
name = "async_compute"
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/change_detection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn deterministic_rand() -> ChaCha8Rng {

fn setup<T: Component + Default>(entity_count: u32) -> World {
let mut world = World::default();
world.spawn_batch((0..entity_count).map(|_| (T::default(),)));
world.spawn_batch((0..entity_count).map(|_| T::default()));
black_box(world)
}

Expand Down
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use criterion::*;
mod iter;
mod send;

criterion_group!(event_benches, send, iter,);
criterion_group!(event_benches, send, iter);

fn send(c: &mut Criterion) {
let mut group = c.benchmark_group("events_send");
Expand Down
2 changes: 1 addition & 1 deletion benches/benches/bevy_ecs/world/world_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ pub fn query_get(criterion: &mut Criterion) {
group.bench_function(format!("{}_entities_sparse", entity_count), |bencher| {
let mut world = World::default();
let mut entities: Vec<_> = world
.spawn_batch((0..entity_count).map(|_| (Sparse::default(),)))
.spawn_batch((0..entity_count).map(|_| Sparse::default()))
.collect();
entities.shuffle(&mut deterministic_rand());
let mut query = SystemState::<Query<&Sparse>>::new(&mut world);
Expand Down
9 changes: 4 additions & 5 deletions crates/bevy_animation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ use std::ops::Deref;
use std::time::Duration;

use bevy_app::{App, Plugin, PostUpdate};
use bevy_asset::{AddAsset, Assets, Handle};
use bevy_asset::{Asset, AssetApp, Assets, Handle};
use bevy_core::Name;
use bevy_ecs::prelude::*;
use bevy_hierarchy::{Children, Parent};
use bevy_math::{Quat, Vec3};
use bevy_reflect::{Reflect, TypeUuid};
use bevy_reflect::Reflect;
use bevy_render::mesh::morph::MorphWeights;
use bevy_time::Time;
use bevy_transform::{prelude::Transform, TransformSystem};
Expand Down Expand Up @@ -65,8 +65,7 @@ pub struct EntityPath {
}

/// A list of [`VariableCurve`], and the [`EntityPath`] to which they apply.
#[derive(Reflect, Clone, TypeUuid, Debug, Default)]
#[uuid = "d81b7179-0448-4eb0-89fe-c067222725bf"]
#[derive(Asset, Reflect, Clone, Debug, Default)]
pub struct AnimationClip {
curves: Vec<Vec<VariableCurve>>,
paths: HashMap<EntityPath, usize>,
Expand Down Expand Up @@ -734,7 +733,7 @@ pub struct AnimationPlugin;

impl Plugin for AnimationPlugin {
fn build(&self, app: &mut App) {
app.add_asset::<AnimationClip>()
app.init_asset::<AnimationClip>()
.register_asset_reflect::<AnimationClip>()
.register_type::<AnimationPlayer>()
.add_systems(
Expand Down
13 changes: 3 additions & 10 deletions crates/bevy_app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -393,21 +393,14 @@ impl App {
}

/// Configures a system set in the default schedule, adding the set if it does not exist.
#[deprecated(since = "0.12.0", note = "Please use `configure_sets` instead.")]
#[track_caller]
pub fn configure_set(
&mut self,
schedule: impl ScheduleLabel,
set: impl IntoSystemSetConfig,
set: impl IntoSystemSetConfigs,
) -> &mut Self {
let mut schedules = self.world.resource_mut::<Schedules>();
if let Some(schedule) = schedules.get_mut(&schedule) {
schedule.configure_set(set);
} else {
let mut new_schedule = Schedule::new(schedule);
new_schedule.configure_set(set);
schedules.insert(new_schedule);
}
self
self.configure_sets(schedule, set)
}

/// Configures a collection of system sets in the default schedule, adding any sets that do not exist.
Expand Down
36 changes: 19 additions & 17 deletions crates/bevy_asset/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,35 @@ repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
keywords = ["bevy"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[features]
default = []
filesystem_watcher = ["notify"]
debug_asset_server = ["filesystem_watcher"]
filesystem_watcher = ["notify-debouncer-full"]
multi-threaded = ["bevy_tasks/multi-threaded"]

[dependencies]
# bevy
bevy_app = { path = "../bevy_app", version = "0.12.0-dev" }
bevy_diagnostic = { path = "../bevy_diagnostic", version = "0.12.0-dev" }
bevy_asset_macros = { path = "macros", version = "0.12.0-dev" }
bevy_ecs = { path = "../bevy_ecs", version = "0.12.0-dev" }
bevy_log = { path = "../bevy_log", version = "0.12.0-dev" }
bevy_reflect = { path = "../bevy_reflect", version = "0.12.0-dev", features = ["bevy"] }
bevy_reflect = { path = "../bevy_reflect", version = "0.12.0-dev" }
bevy_tasks = { path = "../bevy_tasks", version = "0.12.0-dev" }
bevy_utils = { path = "../bevy_utils", version = "0.12.0-dev" }

# other
anyhow = "1.0"
async-broadcast = "0.5"
async-fs = "1.5"
async-lock = "2.8"
crossbeam-channel = "0.5"
downcast-rs = "1.2"
futures-io = "0.3"
futures-lite = "1.12"
md5 = "0.7"
parking_lot = { version = "0.12", features = ["arc_lock", "send_guard"] }
ron = "0.8"
serde = { version = "1", features = ["derive"] }
crossbeam-channel = "0.5.0"
anyhow = "1.0.4"
thiserror = "1.0"
downcast-rs = "1.2.0"
fastrand = "1.7.0"
notify = { version = "6.0.0", optional = true }
parking_lot = "0.12.1"
async-channel = "1.4.2"
notify-debouncer-full = { version = "0.2.0", optional = true }

[target.'cfg(target_os = "android")'.dependencies]
bevy_winit = { path = "../bevy_winit", version = "0.12.0-dev" }
Expand All @@ -44,6 +48,4 @@ wasm-bindgen-futures = "0.4"
js-sys = "0.3"

[dev-dependencies]
futures-lite = "1.4.0"
tempfile = "3.2.0"
bevy_core = { path = "../bevy_core", version = "0.12.0-dev" }
bevy_core = { path = "../bevy_core", version = "0.12.0-dev" }
19 changes: 19 additions & 0 deletions crates/bevy_asset/macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "bevy_asset_macros"
version = "0.12.0-dev"
edition = "2021"
description = "Derive implementations for bevy_asset"
homepage = "https://bevyengine.org"
repository = "https://github.com/bevyengine/bevy"
license = "MIT OR Apache-2.0"
keywords = ["bevy"]

[lib]
proc-macro = true

[dependencies]
bevy_macro_utils = { path = "../../bevy_macro_utils", version = "0.12.0-dev" }

syn = "2.0"
proc-macro2 = "1.0"
quote = "1.0"
76 changes: 76 additions & 0 deletions crates/bevy_asset/macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
use bevy_macro_utils::BevyManifest;
use proc_macro::{Span, TokenStream};
use quote::quote;
use syn::{parse_macro_input, Data, DeriveInput, Path};

pub(crate) fn bevy_asset_path() -> syn::Path {
BevyManifest::default().get_path("bevy_asset")
}

const DEPENDENCY_ATTRIBUTE: &str = "dependency";

#[proc_macro_derive(Asset, attributes(dependency))]
pub fn derive_asset(input: TokenStream) -> TokenStream {
let ast = parse_macro_input!(input as DeriveInput);
let bevy_asset_path: Path = bevy_asset_path();

let struct_name = &ast.ident;
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();
let dependency_visitor = match derive_dependency_visitor_internal(&ast, &bevy_asset_path) {
Ok(dependency_visitor) => dependency_visitor,
Err(err) => return err.into_compile_error().into(),
};

TokenStream::from(quote! {
impl #impl_generics #bevy_asset_path::Asset for #struct_name #type_generics #where_clause { }
#dependency_visitor
})
}

#[proc_macro_derive(VisitAssetDependencies, attributes(dependency))]
pub fn derive_asset_dependency_visitor(input: TokenStream) -> TokenStream {
let ast = parse_macro_input!(input as DeriveInput);
let bevy_asset_path: Path = bevy_asset_path();
match derive_dependency_visitor_internal(&ast, &bevy_asset_path) {
Ok(dependency_visitor) => TokenStream::from(dependency_visitor),
Err(err) => err.into_compile_error().into(),
}
}

fn derive_dependency_visitor_internal(
ast: &DeriveInput,
bevy_asset_path: &Path,
) -> Result<proc_macro2::TokenStream, syn::Error> {
let mut field_visitors = Vec::new();
if let Data::Struct(data_struct) = &ast.data {
for field in data_struct.fields.iter() {
if field
.attrs
.iter()
.any(|a| a.path().is_ident(DEPENDENCY_ATTRIBUTE))
{
if let Some(field_ident) = &field.ident {
field_visitors.push(quote! {
#bevy_asset_path::VisitAssetDependencies::visit_dependencies(&self.#field_ident, visit);
});
}
}
}
} else {
return Err(syn::Error::new(
Span::call_site().into(),
"Asset derive currently only works on structs",
));
}

let struct_name = &ast.ident;
let (impl_generics, type_generics, where_clause) = &ast.generics.split_for_impl();

Ok(quote! {
impl #impl_generics #bevy_asset_path::VisitAssetDependencies for #struct_name #type_generics #where_clause {
fn visit_dependencies(&self, visit: &mut impl FnMut(#bevy_asset_path::UntypedAssetId)) {
#(#field_visitors)*
}
}
})
}
Loading

0 comments on commit b563313

Please sign in to comment.