Skip to content

Commit 17464a7

Browse files
committed
Merge branch 'main' into wireframe-material-no-color
2 parents bd19b54 + dd46fd3 commit 17464a7

File tree

74 files changed

+376
-264
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+376
-264
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,6 @@ bevy_dylib = { path = "crates/bevy_dylib", version = "0.12.0-dev", default-featu
252252
bevy_internal = { path = "crates/bevy_internal", version = "0.12.0-dev", default-features = false }
253253

254254
[dev-dependencies]
255-
anyhow = "1.0.4"
256255
rand = "0.8.0"
257256
ron = "0.8.0"
258257
serde = { version = "1", features = ["derive"] }

assets/shaders/custom_material.wgsl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#import bevy_pbr::mesh_vertex_output MeshVertexOutput
2+
// we can import items from shader modules in the assets folder with a quoted path
3+
#import "shaders/custom_material_import.wgsl" COLOR_MULTIPLIER
24

35
struct CustomMaterial {
46
color: vec4<f32>,
@@ -12,5 +14,5 @@ struct CustomMaterial {
1214
fn fragment(
1315
mesh: MeshVertexOutput,
1416
) -> @location(0) vec4<f32> {
15-
return material.color * textureSample(base_color_texture, base_color_sampler, mesh.uv);
17+
return material.color * textureSample(base_color_texture, base_color_sampler, mesh.uv) * COLOR_MULTIPLIER;
1618
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// this is made available to the importing module
2+
const COLOR_MULTIPLIER: vec4<f32> = vec4<f32>(1.0, 1.0, 1.0, 0.5);

crates/bevy_app/src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ impl App {
334334
/// initial state.
335335
///
336336
/// If you would like to control how other systems run based on the current state,
337-
/// you can emulate this behavior using the [`in_state`] [`Condition`](bevy_ecs::schedule::Condition).
337+
/// you can emulate this behavior using the [`in_state`] [`Condition`].
338338
///
339339
/// Note that you can also apply state transitions at other points in the schedule
340340
/// by adding the [`apply_state_transition`] system manually.

crates/bevy_app/src/plugin.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ pub trait Plugin: Downcast + Any + Send + Sync {
5151
std::any::type_name::<Self>()
5252
}
5353

54-
/// If the plugin can be meaningfully instantiated several times in an [`App`](crate::App),
54+
/// If the plugin can be meaningfully instantiated several times in an [`App`],
5555
/// override this method to return `false`.
5656
fn is_unique(&self) -> bool {
5757
true

crates/bevy_asset/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.12.0-dev" }
2323
bevy_tasks = { path = "../bevy_tasks", version = "0.12.0-dev" }
2424
bevy_utils = { path = "../bevy_utils", version = "0.12.0-dev" }
2525

26-
anyhow = "1.0"
2726
async-broadcast = "0.5"
2827
async-fs = "1.5"
2928
async-lock = "2.8"

crates/bevy_asset/src/io/android.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::io::{
22
get_meta_path, AssetReader, AssetReaderError, AssetWatcher, EmptyPathStream, PathStream,
33
Reader, VecReader,
44
};
5-
use anyhow::Result;
65
use bevy_log::error;
76
use bevy_utils::BoxedFuture;
87
use std::{ffi::CString, path::Path};

crates/bevy_asset/src/io/file/file_watcher.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::io::{AssetSourceEvent, AssetWatcher};
2-
use anyhow::Result;
32
use bevy_log::error;
43
use bevy_utils::Duration;
54
use crossbeam_channel::Sender;

crates/bevy_asset/src/io/file/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::io::{
55
get_meta_path, AssetReader, AssetReaderError, AssetWatcher, AssetWriter, AssetWriterError,
66
PathStream, Reader, Writer,
77
};
8-
use anyhow::Result;
98
use async_fs::{read_dir, File};
109
use bevy_utils::BoxedFuture;
1110
use futures_lite::StreamExt;

crates/bevy_asset/src/io/gated.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::io::{AssetReader, AssetReaderError, PathStream, Reader};
2-
use anyhow::Result;
32
use bevy_utils::{BoxedFuture, HashMap};
43
use crossbeam_channel::{Receiver, Sender};
54
use parking_lot::RwLock;

crates/bevy_asset/src/io/memory.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use crate::io::{AssetReader, AssetReaderError, PathStream, Reader};
2-
use anyhow::Result;
32
use bevy_utils::{BoxedFuture, HashMap};
43
use futures_io::AsyncRead;
54
use futures_lite::{ready, Stream};

crates/bevy_asset/src/io/processor_gated.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ use crate::{
33
processor::{AssetProcessorData, ProcessStatus},
44
AssetPath,
55
};
6-
use anyhow::Result;
76
use async_lock::RwLockReadGuardArc;
87
use bevy_log::trace;
98
use bevy_utils::BoxedFuture;

crates/bevy_asset/src/io/wasm.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::io::{
22
get_meta_path, AssetReader, AssetReaderError, AssetWatcher, EmptyPathStream, PathStream,
33
Reader, VecReader,
44
};
5-
use anyhow::Result;
65
use bevy_log::error;
76
use bevy_utils::BoxedFuture;
87
use js_sys::{Uint8Array, JSON};

crates/bevy_asset/src/lib.rs

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub use path::*;
3535
pub use reflect::*;
3636
pub use server::*;
3737

38-
pub use anyhow;
3938
pub use bevy_utils::BoxedFuture;
4039

4140
use crate::{
@@ -428,8 +427,9 @@ mod tests {
428427
Reader,
429428
},
430429
loader::{AssetLoader, LoadContext},
431-
Asset, AssetApp, AssetEvent, AssetId, AssetPlugin, AssetProvider, AssetProviders,
432-
AssetServer, Assets, DependencyLoadState, LoadState, RecursiveDependencyLoadState,
430+
Asset, AssetApp, AssetEvent, AssetId, AssetPath, AssetPlugin, AssetProvider,
431+
AssetProviders, AssetServer, Assets, DependencyLoadState, LoadState,
432+
RecursiveDependencyLoadState,
433433
};
434434
use bevy_app::{App, Update};
435435
use bevy_core::TaskPoolPlugin;
@@ -444,6 +444,7 @@ mod tests {
444444
use futures_lite::AsyncReadExt;
445445
use serde::{Deserialize, Serialize};
446446
use std::path::Path;
447+
use thiserror::Error;
447448

448449
#[derive(Asset, TypePath, Debug)]
449450
pub struct CoolText {
@@ -471,24 +472,40 @@ mod tests {
471472
#[derive(Default)]
472473
struct CoolTextLoader;
473474

475+
#[derive(Error, Debug)]
476+
enum CoolTextLoaderError {
477+
#[error("Could not load dependency: {dependency}")]
478+
CannotLoadDependency { dependency: AssetPath<'static> },
479+
#[error("A RON error occurred during loading")]
480+
RonSpannedError(#[from] ron::error::SpannedError),
481+
#[error("An IO error occurred during loading")]
482+
Io(#[from] std::io::Error),
483+
}
484+
474485
impl AssetLoader for CoolTextLoader {
475486
type Asset = CoolText;
476487

477488
type Settings = ();
478489

490+
type Error = CoolTextLoaderError;
491+
479492
fn load<'a>(
480493
&'a self,
481494
reader: &'a mut Reader,
482495
_settings: &'a Self::Settings,
483496
load_context: &'a mut LoadContext,
484-
) -> BoxedFuture<'a, Result<Self::Asset, anyhow::Error>> {
497+
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
485498
Box::pin(async move {
486499
let mut bytes = Vec::new();
487500
reader.read_to_end(&mut bytes).await?;
488501
let mut ron: CoolTextRon = ron::de::from_bytes(&bytes)?;
489502
let mut embedded = String::new();
490503
for dep in ron.embedded_dependencies {
491-
let loaded = load_context.load_direct(&dep).await?;
504+
let loaded = load_context.load_direct(&dep).await.map_err(|_| {
505+
Self::Error::CannotLoadDependency {
506+
dependency: dep.into(),
507+
}
508+
})?;
492509
let cool = loaded.get::<CoolText>().unwrap();
493510
embedded.push_str(&cool.text);
494511
}

crates/bevy_asset/src/loader.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,15 @@ pub trait AssetLoader: Send + Sync + 'static {
2626
type Asset: crate::Asset;
2727
/// The settings type used by this [`AssetLoader`].
2828
type Settings: Settings + Default + Serialize + for<'a> Deserialize<'a>;
29+
/// The type of [error](`std::error::Error`) which could be encountered by this loader.
30+
type Error: std::error::Error + Send + Sync + 'static;
2931
/// Asynchronously loads [`AssetLoader::Asset`] (and any other labeled assets) from the bytes provided by [`Reader`].
3032
fn load<'a>(
3133
&'a self,
3234
reader: &'a mut Reader,
3335
settings: &'a Self::Settings,
3436
load_context: &'a mut LoadContext,
35-
) -> BoxedFuture<'a, Result<Self::Asset, anyhow::Error>>;
37+
) -> BoxedFuture<'a, Result<Self::Asset, Self::Error>>;
3638

3739
/// Returns a list of extensions supported by this asset loader, without the preceding dot.
3840
fn extensions(&self) -> &[&str];
@@ -46,7 +48,10 @@ pub trait ErasedAssetLoader: Send + Sync + 'static {
4648
reader: &'a mut Reader,
4749
meta: Box<dyn AssetMetaDyn>,
4850
load_context: LoadContext<'a>,
49-
) -> BoxedFuture<'a, Result<ErasedLoadedAsset, AssetLoaderError>>;
51+
) -> BoxedFuture<
52+
'a,
53+
Result<ErasedLoadedAsset, Box<dyn std::error::Error + Send + Sync + 'static>>,
54+
>;
5055

5156
/// Returns a list of extensions supported by this asset loader, without the preceding dot.
5257
fn extensions(&self) -> &[&str];
@@ -64,17 +69,6 @@ pub trait ErasedAssetLoader: Send + Sync + 'static {
6469
fn asset_type_id(&self) -> TypeId;
6570
}
6671

67-
/// An error encountered during [`AssetLoader::load`].
68-
#[derive(Error, Debug)]
69-
pub enum AssetLoaderError {
70-
/// Any error that occurs during load.
71-
#[error(transparent)]
72-
Load(#[from] anyhow::Error),
73-
/// A failure to deserialize metadata during load.
74-
#[error(transparent)]
75-
DeserializeMeta(#[from] DeserializeMetaError),
76-
}
77-
7872
impl<L> ErasedAssetLoader for L
7973
where
8074
L: AssetLoader + Send + Sync,
@@ -85,7 +79,10 @@ where
8579
reader: &'a mut Reader,
8680
meta: Box<dyn AssetMetaDyn>,
8781
mut load_context: LoadContext<'a>,
88-
) -> BoxedFuture<'a, Result<ErasedLoadedAsset, AssetLoaderError>> {
82+
) -> BoxedFuture<
83+
'a,
84+
Result<ErasedLoadedAsset, Box<dyn std::error::Error + Send + Sync + 'static>>,
85+
> {
8986
Box::pin(async move {
9087
let settings = meta
9188
.loader_settings()

crates/bevy_asset/src/meta.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,13 @@ impl VisitAssetDependencies for () {
193193
impl AssetLoader for () {
194194
type Asset = ();
195195
type Settings = ();
196+
type Error = std::io::Error;
196197
fn load<'a>(
197198
&'a self,
198199
_reader: &'a mut crate::io::Reader,
199200
_settings: &'a Self::Settings,
200201
_load_context: &'a mut crate::LoadContext,
201-
) -> bevy_utils::BoxedFuture<'a, Result<Self::Asset, anyhow::Error>> {
202+
) -> bevy_utils::BoxedFuture<'a, Result<Self::Asset, Self::Error>> {
202203
unreachable!();
203204
}
204205

crates/bevy_asset/src/processor/mod.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::{
1313
get_asset_hash, get_full_asset_hash, AssetAction, AssetActionMinimal, AssetHash, AssetMeta,
1414
AssetMetaDyn, AssetMetaMinimal, ProcessedInfo, ProcessedInfoMinimal,
1515
},
16-
AssetLoadError, AssetLoaderError, AssetPath, AssetServer, DeserializeMetaError,
17-
LoadDirectError, MissingAssetLoaderForExtensionError, CANNOT_WATCH_ERROR_MESSAGE,
16+
AssetLoadError, AssetPath, AssetServer, DeserializeMetaError,
17+
MissingAssetLoaderForExtensionError, CANNOT_WATCH_ERROR_MESSAGE,
1818
};
1919
use bevy_ecs::prelude::*;
2020
use bevy_log::{debug, error, trace, warn};
@@ -1130,20 +1130,17 @@ impl ProcessorAssetInfos {
11301130
Err(err) => {
11311131
error!("Failed to process asset {:?}: {:?}", asset_path, err);
11321132
// if this failed because a dependency could not be loaded, make sure it is reprocessed if that dependency is reprocessed
1133-
if let ProcessError::AssetLoadError(AssetLoadError::AssetLoaderError {
1134-
error: AssetLoaderError::Load(loader_error),
1135-
..
1133+
if let ProcessError::AssetLoadError(AssetLoadError::CannotLoadDependency {
1134+
path: dependency,
11361135
}) = err
11371136
{
1138-
if let Some(error) = loader_error.downcast_ref::<LoadDirectError>() {
1139-
let info = self.get_mut(&asset_path).expect("info should exist");
1140-
info.processed_info = Some(ProcessedInfo {
1141-
hash: AssetHash::default(),
1142-
full_hash: AssetHash::default(),
1143-
process_dependencies: vec![],
1144-
});
1145-
self.add_dependant(&error.dependency, asset_path.to_owned());
1146-
}
1137+
let info = self.get_mut(&asset_path).expect("info should exist");
1138+
info.processed_info = Some(ProcessedInfo {
1139+
hash: AssetHash::default(),
1140+
full_hash: AssetHash::default(),
1141+
process_dependencies: vec![],
1142+
});
1143+
self.add_dependant(&dependency, asset_path.to_owned());
11471144
}
11481145

11491146
let info = self.get_mut(&asset_path).expect("info should exist");

crates/bevy_asset/src/processor/process.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub enum ProcessError {
9191
#[error("The wrong meta type was passed into a processor. This is probably an internal implementation error.")]
9292
WrongMetaType,
9393
#[error("Encountered an error while saving the asset: {0}")]
94-
AssetSaveError(anyhow::Error),
94+
AssetSaveError(#[from] Box<dyn std::error::Error + Send + Sync + 'static>),
9595
#[error("Assets without extensions are not supported.")]
9696
ExtensionRequired,
9797
}
@@ -122,7 +122,7 @@ impl<Loader: AssetLoader, Saver: AssetSaver<Asset = Loader::Asset>> Process
122122
.saver
123123
.save(writer, saved_asset, &settings.saver_settings)
124124
.await
125-
.map_err(ProcessError::AssetSaveError)?;
125+
.map_err(|error| ProcessError::AssetSaveError(Box::new(error)))?;
126126
Ok(output_settings)
127127
})
128128
}

crates/bevy_asset/src/saver.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,14 @@ use std::ops::Deref;
77
/// Saves an [`Asset`] of a given [`AssetSaver::Asset`] type. [`AssetSaver::OutputLoader`] will then be used to load the saved asset
88
/// in the final deployed application. The saver should produce asset bytes in a format that [`AssetSaver::OutputLoader`] can read.
99
pub trait AssetSaver: Send + Sync + 'static {
10+
/// The top level [`Asset`] saved by this [`AssetSaver`].
1011
type Asset: Asset;
12+
/// The settings type used by this [`AssetSaver`].
1113
type Settings: Settings + Default + Serialize + for<'a> Deserialize<'a>;
14+
/// The type of [`AssetLoader`] used to load this [`Asset`]
1215
type OutputLoader: AssetLoader;
16+
/// The type of [error](`std::error::Error`) which could be encountered by this saver.
17+
type Error: std::error::Error + Send + Sync + 'static;
1318

1419
/// Saves the given runtime [`Asset`] by writing it to a byte format using `writer`. The passed in `settings` can influence how the
1520
/// `asset` is saved.
@@ -18,7 +23,7 @@ pub trait AssetSaver: Send + Sync + 'static {
1823
writer: &'a mut Writer,
1924
asset: SavedAsset<'a, Self::Asset>,
2025
settings: &'a Self::Settings,
21-
) -> BoxedFuture<'a, Result<<Self::OutputLoader as AssetLoader>::Settings, anyhow::Error>>;
26+
) -> BoxedFuture<'a, Result<<Self::OutputLoader as AssetLoader>::Settings, Self::Error>>;
2227
}
2328

2429
/// A type-erased dynamic variant of [`AssetSaver`] that allows callers to save assets without knowing the actual type of the [`AssetSaver`].
@@ -30,7 +35,7 @@ pub trait ErasedAssetSaver: Send + Sync + 'static {
3035
writer: &'a mut Writer,
3136
asset: &'a ErasedLoadedAsset,
3237
settings: &'a dyn Settings,
33-
) -> BoxedFuture<'a, Result<(), anyhow::Error>>;
38+
) -> BoxedFuture<'a, Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>>;
3439

3540
/// The type name of the [`AssetSaver`].
3641
fn type_name(&self) -> &'static str;
@@ -42,7 +47,7 @@ impl<S: AssetSaver> ErasedAssetSaver for S {
4247
writer: &'a mut Writer,
4348
asset: &'a ErasedLoadedAsset,
4449
settings: &'a dyn Settings,
45-
) -> BoxedFuture<'a, Result<(), anyhow::Error>> {
50+
) -> BoxedFuture<'a, Result<(), Box<dyn std::error::Error + Send + Sync + 'static>>> {
4651
Box::pin(async move {
4752
let settings = settings
4853
.downcast_ref::<S::Settings>()

0 commit comments

Comments
 (0)