mirror of
https://github.com/bevyengine/bevy
synced 2024-11-23 13:13:49 +00:00
Remove the meta
field from LoadedAsset
and ErasedLoadedAsset
.
This commit is contained in:
parent
9b4d2de215
commit
08f45b98dd
5 changed files with 26 additions and 40 deletions
|
@ -50,7 +50,7 @@ pub trait ErasedAssetLoader: Send + Sync + 'static {
|
|||
fn load<'a>(
|
||||
&'a self,
|
||||
reader: &'a mut dyn Reader,
|
||||
meta: Box<dyn AssetMetaDyn>,
|
||||
meta: &'a dyn AssetMetaDyn,
|
||||
load_context: LoadContext<'a>,
|
||||
) -> BoxedFuture<
|
||||
'a,
|
||||
|
@ -81,7 +81,7 @@ where
|
|||
fn load<'a>(
|
||||
&'a self,
|
||||
reader: &'a mut dyn Reader,
|
||||
meta: Box<dyn AssetMetaDyn>,
|
||||
meta: &'a dyn AssetMetaDyn,
|
||||
mut load_context: LoadContext<'a>,
|
||||
) -> BoxedFuture<
|
||||
'a,
|
||||
|
@ -96,7 +96,7 @@ where
|
|||
let asset = <L as AssetLoader>::load(self, reader, settings, &mut load_context)
|
||||
.await
|
||||
.map_err(Into::into)?;
|
||||
Ok(load_context.finish(asset, Some(meta)).into())
|
||||
Ok(load_context.finish(asset).into())
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -147,12 +147,11 @@ pub struct LoadedAsset<A: Asset> {
|
|||
pub(crate) dependencies: HashSet<UntypedAssetId>,
|
||||
pub(crate) loader_dependencies: HashMap<AssetPath<'static>, AssetHash>,
|
||||
pub(crate) labeled_assets: HashMap<CowArc<'static, str>, LabeledAsset>,
|
||||
pub(crate) meta: Option<Box<dyn AssetMetaDyn>>,
|
||||
}
|
||||
|
||||
impl<A: Asset> LoadedAsset<A> {
|
||||
/// Create a new loaded asset. This will use [`VisitAssetDependencies`](crate::VisitAssetDependencies) to populate `dependencies`.
|
||||
pub fn new_with_dependencies(value: A, meta: Option<Box<dyn AssetMetaDyn>>) -> Self {
|
||||
pub fn new_with_dependencies(value: A) -> Self {
|
||||
let mut dependencies = HashSet::new();
|
||||
value.visit_dependencies(&mut |id| {
|
||||
dependencies.insert(id);
|
||||
|
@ -162,7 +161,6 @@ impl<A: Asset> LoadedAsset<A> {
|
|||
dependencies,
|
||||
loader_dependencies: HashMap::default(),
|
||||
labeled_assets: HashMap::default(),
|
||||
meta,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -192,7 +190,7 @@ impl<A: Asset> LoadedAsset<A> {
|
|||
|
||||
impl<A: Asset> From<A> for LoadedAsset<A> {
|
||||
fn from(asset: A) -> Self {
|
||||
LoadedAsset::new_with_dependencies(asset, None)
|
||||
LoadedAsset::new_with_dependencies(asset)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -202,7 +200,6 @@ pub struct ErasedLoadedAsset {
|
|||
pub(crate) dependencies: HashSet<UntypedAssetId>,
|
||||
pub(crate) loader_dependencies: HashMap<AssetPath<'static>, AssetHash>,
|
||||
pub(crate) labeled_assets: HashMap<CowArc<'static, str>, LabeledAsset>,
|
||||
pub(crate) meta: Option<Box<dyn AssetMetaDyn>>,
|
||||
}
|
||||
|
||||
impl<A: Asset> From<LoadedAsset<A>> for ErasedLoadedAsset {
|
||||
|
@ -212,7 +209,6 @@ impl<A: Asset> From<LoadedAsset<A>> for ErasedLoadedAsset {
|
|||
dependencies: asset.dependencies,
|
||||
loader_dependencies: asset.loader_dependencies,
|
||||
labeled_assets: asset.labeled_assets,
|
||||
meta: asset.meta,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -254,7 +250,6 @@ impl ErasedLoadedAsset {
|
|||
|
||||
/// Cast this loaded asset as the given type. If the type does not match,
|
||||
/// the original type-erased asset is returned.
|
||||
#[expect(clippy::result_large_err, reason = "Function returns `Self` on error.")]
|
||||
pub fn downcast<A: Asset>(mut self) -> Result<LoadedAsset<A>, ErasedLoadedAsset> {
|
||||
match self.value.downcast::<A>() {
|
||||
Ok(value) => Ok(LoadedAsset {
|
||||
|
@ -262,7 +257,6 @@ impl ErasedLoadedAsset {
|
|||
dependencies: self.dependencies,
|
||||
loader_dependencies: self.loader_dependencies,
|
||||
labeled_assets: self.labeled_assets,
|
||||
meta: self.meta,
|
||||
}),
|
||||
Err(value) => {
|
||||
self.value = value;
|
||||
|
@ -360,7 +354,7 @@ impl<'a> LoadContext<'a> {
|
|||
/// for i in 0..2 {
|
||||
/// let mut labeled = load_context.begin_labeled_asset();
|
||||
/// handles.push(std::thread::spawn(move || {
|
||||
/// (i.to_string(), labeled.finish(Image::default(), None))
|
||||
/// (i.to_string(), labeled.finish(Image::default()))
|
||||
/// }));
|
||||
/// }
|
||||
|
||||
|
@ -393,7 +387,7 @@ impl<'a> LoadContext<'a> {
|
|||
) -> Handle<A> {
|
||||
let mut context = self.begin_labeled_asset();
|
||||
let asset = load(&mut context);
|
||||
let loaded_asset = context.finish(asset, None);
|
||||
let loaded_asset = context.finish(asset);
|
||||
self.add_loaded_labeled_asset(label, loaded_asset)
|
||||
}
|
||||
|
||||
|
@ -447,13 +441,12 @@ impl<'a> LoadContext<'a> {
|
|||
|
||||
/// "Finishes" this context by populating the final [`Asset`] value (and the erased [`AssetMeta`] value, if it exists).
|
||||
/// The relevant asset metadata collected in this context will be stored in the returned [`LoadedAsset`].
|
||||
pub fn finish<A: Asset>(self, value: A, meta: Option<Box<dyn AssetMetaDyn>>) -> LoadedAsset<A> {
|
||||
pub fn finish<A: Asset>(self, value: A) -> LoadedAsset<A> {
|
||||
LoadedAsset {
|
||||
value,
|
||||
dependencies: self.dependencies,
|
||||
loader_dependencies: self.loader_dependencies,
|
||||
labeled_assets: self.labeled_assets,
|
||||
meta,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -520,7 +513,7 @@ impl<'a> LoadContext<'a> {
|
|||
pub(crate) async fn load_direct_internal(
|
||||
&mut self,
|
||||
path: AssetPath<'static>,
|
||||
meta: Box<dyn AssetMetaDyn>,
|
||||
meta: &dyn AssetMetaDyn,
|
||||
loader: &dyn ErasedAssetLoader,
|
||||
reader: &mut dyn Reader,
|
||||
) -> Result<ErasedLoadedAsset, LoadDirectError> {
|
||||
|
@ -539,10 +532,7 @@ impl<'a> LoadContext<'a> {
|
|||
dependency: path.clone(),
|
||||
error,
|
||||
})?;
|
||||
let info = loaded_asset
|
||||
.meta
|
||||
.as_ref()
|
||||
.and_then(|m| m.processed_info().as_ref());
|
||||
let info = meta.processed_info().as_ref();
|
||||
let hash = info.map(|i| i.full_hash).unwrap_or_default();
|
||||
self.loader_dependencies.insert(path, hash);
|
||||
Ok(loaded_asset)
|
||||
|
|
|
@ -240,7 +240,7 @@ impl<'ctx: 'reader, 'builder, 'reader> DirectNestedLoader<'ctx, 'builder, 'reade
|
|||
let asset = self
|
||||
.base
|
||||
.load_context
|
||||
.load_direct_internal(path.clone(), meta, &*loader, reader.as_mut())
|
||||
.load_direct_internal(path.clone(), meta.as_ref(), &*loader, reader.as_mut())
|
||||
.await?;
|
||||
Ok((loader, asset))
|
||||
}
|
||||
|
|
|
@ -320,14 +320,7 @@ impl<'a> ProcessContext<'a> {
|
|||
let loader = server.get_asset_loader_with_type_name(loader_name).await?;
|
||||
let mut reader = SliceReader::new(self.asset_bytes);
|
||||
let loaded_asset = server
|
||||
.load_with_meta_loader_and_reader(
|
||||
self.path,
|
||||
Box::new(meta),
|
||||
&*loader,
|
||||
&mut reader,
|
||||
false,
|
||||
true,
|
||||
)
|
||||
.load_with_meta_loader_and_reader(self.path, &meta, &*loader, &mut reader, false, true)
|
||||
.await?;
|
||||
for (path, full_hash) in &loaded_asset.loader_dependencies {
|
||||
self.new_processed_info
|
||||
|
|
|
@ -442,11 +442,8 @@ impl AssetServer {
|
|||
match server.load_untyped_async(path).await {
|
||||
Ok(handle) => server.send_asset_event(InternalAssetEvent::Loaded {
|
||||
id,
|
||||
loaded_asset: LoadedAsset::new_with_dependencies(
|
||||
LoadedUntypedAsset { handle },
|
||||
None,
|
||||
)
|
||||
.into(),
|
||||
loaded_asset: LoadedAsset::new_with_dependencies(LoadedUntypedAsset { handle })
|
||||
.into(),
|
||||
}),
|
||||
Err(err) => {
|
||||
error!("{err}");
|
||||
|
@ -601,7 +598,14 @@ impl AssetServer {
|
|||
};
|
||||
|
||||
match self
|
||||
.load_with_meta_loader_and_reader(&base_path, meta, &*loader, &mut *reader, true, false)
|
||||
.load_with_meta_loader_and_reader(
|
||||
&base_path,
|
||||
meta.as_ref(),
|
||||
&*loader,
|
||||
&mut *reader,
|
||||
true,
|
||||
false,
|
||||
)
|
||||
.await
|
||||
{
|
||||
Ok(loaded_asset) => {
|
||||
|
@ -689,7 +693,7 @@ impl AssetServer {
|
|||
/// After the asset has been fully loaded by the [`AssetServer`], it will show up in the relevant [`Assets`] storage.
|
||||
#[must_use = "not using the returned strong handle may result in the unexpected release of the asset"]
|
||||
pub fn add<A: Asset>(&self, asset: A) -> Handle<A> {
|
||||
self.load_asset(LoadedAsset::new_with_dependencies(asset, None))
|
||||
self.load_asset(LoadedAsset::new_with_dependencies(asset))
|
||||
}
|
||||
|
||||
pub(crate) fn load_asset<A: Asset>(&self, asset: impl Into<LoadedAsset<A>>) -> Handle<A> {
|
||||
|
@ -747,7 +751,7 @@ impl AssetServer {
|
|||
let task = IoTaskPool::get().spawn(async move {
|
||||
match future.await {
|
||||
Ok(asset) => {
|
||||
let loaded_asset = LoadedAsset::new_with_dependencies(asset, None).into();
|
||||
let loaded_asset = LoadedAsset::new_with_dependencies(asset).into();
|
||||
event_sender
|
||||
.send(InternalAssetEvent::Loaded { id, loaded_asset })
|
||||
.unwrap();
|
||||
|
@ -877,7 +881,6 @@ impl AssetServer {
|
|||
id,
|
||||
loaded_asset: LoadedAsset::new_with_dependencies(
|
||||
LoadedFolder { handles },
|
||||
None,
|
||||
)
|
||||
.into(),
|
||||
}),
|
||||
|
@ -1241,7 +1244,7 @@ impl AssetServer {
|
|||
pub(crate) async fn load_with_meta_loader_and_reader(
|
||||
&self,
|
||||
asset_path: &AssetPath<'_>,
|
||||
meta: Box<dyn AssetMetaDyn>,
|
||||
meta: &dyn AssetMetaDyn,
|
||||
loader: &dyn ErasedAssetLoader,
|
||||
reader: &mut dyn Reader,
|
||||
load_dependencies: bool,
|
||||
|
|
|
@ -756,7 +756,7 @@ async fn load_gltf<'a, 'b, 'c>(
|
|||
joints: joint_entities,
|
||||
});
|
||||
}
|
||||
let loaded_scene = scene_load_context.finish(Scene::new(world), None);
|
||||
let loaded_scene = scene_load_context.finish(Scene::new(world));
|
||||
let scene_handle = load_context.add_loaded_labeled_asset(scene_label(&scene), loaded_scene);
|
||||
|
||||
if let Some(name) = scene.name() {
|
||||
|
|
Loading…
Reference in a new issue