summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2026-10-21 09:12:45 +0200
committerHampusM <hampus@hampusmat.com>2026-10-21 09:12:45 +0200
commite35751554ac82f5f0af02e9690458f0953e09380 (patch)
treeb0d7cdccdc89ee06d38410e5f651db21acba4c28
parent7c55cefc6b7b1da19b2bbe7f43daaba4f816f27d (diff)
refactor(engine): replace Asset::dependencies fn with visit_dependencies fnHEADmaster
-rw-r--r--engine/src/asset.rs18
-rw-r--r--engine/src/material.rs14
-rw-r--r--engine/src/mesh.rs6
-rw-r--r--engine/src/model.rs20
-rw-r--r--engine/src/rendering/shader.rs6
-rw-r--r--engine/src/texture.rs6
6 files changed, 46 insertions, 24 deletions
diff --git a/engine/src/asset.rs b/engine/src/asset.rs
index ea0037c..e1f699a 100644
--- a/engine/src/asset.rs
+++ b/engine/src/asset.rs
@@ -29,7 +29,7 @@ pub HANDLE_ASSETS_PHASE: (Phase, pair!(ChildOf, { *PRE_UPDATE_PHASE }));
pub trait Asset: Send + Sync + 'static
{
- fn dependencies(&self) -> impl Iterator<Item = Dependency<'_>>;
+ fn visit_dependencies<'this>(&'this self, func: &mut dyn FnMut(Dependency<'this>));
}
#[derive(Debug)]
@@ -61,6 +61,14 @@ pub struct Label<'a>
impl Label<'_>
{
+ pub fn borrow(&self) -> Label<'_>
+ {
+ Label {
+ path: (&*self.path).into(),
+ name: self.name.as_deref().map(Into::into),
+ }
+ }
+
#[must_use]
fn to_owned(&self) -> LabelOwned
{
@@ -373,7 +381,13 @@ impl Assets
let mut missing_dependencies = 0;
- for dependency in asset.dependencies() {
+ let mut dependencies = Vec::new();
+
+ asset.visit_dependencies(&mut |dependency| {
+ dependencies.push(dependency);
+ });
+
+ for dependency in dependencies {
match self.get_asset_by_label_mut(&dependency.label) {
Some((Some(StoredAsset { state: AssetState::Ready { .. }, .. }), _)) => {}
Some((
diff --git a/engine/src/material.rs b/engine/src/material.rs
index ae0751b..ded30a2 100644
--- a/engine/src/material.rs
+++ b/engine/src/material.rs
@@ -57,14 +57,14 @@ impl Default for Material
impl Asset for Material
{
- fn dependencies(&self) -> impl Iterator<Item = AssetDependency<'_>>
+ fn visit_dependencies<'this>(
+ &'this self,
+ func: &mut dyn FnMut(AssetDependency<'this>),
+ )
{
- self.loading_textures.iter().map(|(_, texture_label)| {
- AssetDependency::new::<Texture>(AssetLabel {
- path: (&*texture_label.path).into(),
- name: texture_label.name.as_deref().map(Into::into),
- })
- })
+ for (_, texture_label) in &self.loading_textures {
+ func(AssetDependency::new::<Texture>(texture_label.borrow()));
+ }
}
}
diff --git a/engine/src/mesh.rs b/engine/src/mesh.rs
index b52edb1..7d5e683 100644
--- a/engine/src/mesh.rs
+++ b/engine/src/mesh.rs
@@ -315,9 +315,11 @@ impl Mesh
impl Asset for Mesh
{
- fn dependencies(&self) -> impl Iterator<Item = crate::asset::Dependency<'_>>
+ fn visit_dependencies<'this>(
+ &'this self,
+ _func: &mut dyn FnMut(crate::asset::Dependency<'this>),
+ )
{
- [].into_iter()
}
}
diff --git a/engine/src/model.rs b/engine/src/model.rs
index c231a9f..62cfe21 100644
--- a/engine/src/model.rs
+++ b/engine/src/model.rs
@@ -20,9 +20,11 @@ pub struct Model {}
impl Asset for Model
{
- fn dependencies(&self) -> impl Iterator<Item = AssetDependency<'_>>
+ fn visit_dependencies<'this>(
+ &'this self,
+ _func: &mut dyn FnMut(crate::asset::Dependency<'this>),
+ )
{
- [].into_iter()
}
}
@@ -67,14 +69,14 @@ impl MaterialDescription
impl Asset for MaterialDescription
{
- fn dependencies(&self) -> impl Iterator<Item = AssetDependency<'_>>
+ fn visit_dependencies<'this>(
+ &'this self,
+ func: &mut dyn FnMut(AssetDependency<'this>),
+ )
{
- self.loading_material.iter().map(|material_label| {
- AssetDependency::new::<Material>(AssetLabel {
- path: (&*material_label.path).into(),
- name: material_label.name.as_deref().map(Into::into),
- })
- })
+ if let Some(material_label) = &self.loading_material {
+ func(AssetDependency::new::<Material>(material_label.borrow()));
+ }
}
}
diff --git a/engine/src/rendering/shader.rs b/engine/src/rendering/shader.rs
index f56a9ae..a4edbc0 100644
--- a/engine/src/rendering/shader.rs
+++ b/engine/src/rendering/shader.rs
@@ -57,9 +57,11 @@ pub struct ModuleSource
impl Asset for ModuleSource
{
- fn dependencies(&self) -> impl Iterator<Item = crate::asset::Dependency<'_>>
+ fn visit_dependencies<'this>(
+ &'this self,
+ _func: &mut dyn FnMut(crate::asset::Dependency<'this>),
+ )
{
- [].into_iter()
}
}
diff --git a/engine/src/texture.rs b/engine/src/texture.rs
index 2a20581..24fe009 100644
--- a/engine/src/texture.rs
+++ b/engine/src/texture.rs
@@ -14,9 +14,11 @@ pub enum Texture
impl Asset for Texture
{
- fn dependencies(&self) -> impl Iterator<Item = crate::asset::Dependency<'_>>
+ fn visit_dependencies<'this>(
+ &'this self,
+ _func: &mut dyn FnMut(crate::asset::Dependency<'this>),
+ )
{
- [].into_iter()
}
}