diff --git a/examples/2d.rs b/examples/2d.rs index 0768c6679..5530edcfc 100644 --- a/examples/2d.rs +++ b/examples/2d.rs @@ -58,7 +58,7 @@ impl SceneLoader { }, ) .unwrap(); - let material = MaterialResource::new_ok(Default::default(), material, true); + let material = MaterialResource::new_ok(Default::default(), material); // Add some sprites. for y in 0..10 { diff --git a/examples/navmesh.rs b/examples/navmesh.rs index 53d30f7df..fc731d2b7 100644 --- a/examples/navmesh.rs +++ b/examples/navmesh.rs @@ -80,7 +80,6 @@ async fn create_scene(resource_manager: ResourceManager) -> GameScene { .with_material(MaterialResource::new_ok( Default::default(), cursor_material, - true, )) .build()]) .build(&mut scene.graph); @@ -103,11 +102,7 @@ async fn create_scene(resource_manager: ResourceManager) -> GameScene { .with_surfaces(vec![SurfaceBuilder::new(SurfaceSharedData::new( SurfaceData::make_sphere(10, 10, 0.2, &Matrix4::identity()), )) - .with_material(MaterialResource::new_ok( - Default::default(), - agent_material, - true, - )) + .with_material(MaterialResource::new_ok(Default::default(), agent_material)) .build()]) .build(&mut scene.graph); diff --git a/fyrox-resource/src/graph.rs b/fyrox-resource/src/graph.rs index 1647b3b72..5cd110f2b 100644 --- a/fyrox-resource/src/graph.rs +++ b/fyrox-resource/src/graph.rs @@ -114,19 +114,17 @@ mod test { fn resource_graph_node_pretty_print() { let mut s = String::new(); let mut node = ResourceGraphNode::new(&UntypedResource::new_pending( - PathBuf::from("/foo"), + PathBuf::from("/foo").into(), Uuid::default(), - true, )); let node2 = ResourceGraphNode::new(&UntypedResource::new_pending( - PathBuf::from("/bar"), + PathBuf::from("/bar").into(), Uuid::default(), - true, )); node.children.push(node2); node.pretty_print(1, &mut s); - assert_eq!(s, "\t/foo\n\t\t/bar\n".to_string()); + assert_eq!(s, "\tExternal (/foo)\n\t\tExternal (/bar)\n".to_string()); } #[test] @@ -152,37 +150,33 @@ mod test { #[test] fn resource_dependency_pretty_print() { let mut graph = ResourceDependencyGraph::new(&UntypedResource::new_pending( - PathBuf::from("/foo"), + PathBuf::from("/foo").into(), Uuid::default(), - true, )); graph .root .children .push(ResourceGraphNode::new(&UntypedResource::new_pending( - PathBuf::from("/bar"), + PathBuf::from("/bar").into(), Uuid::default(), - true, ))); let s = graph.pretty_print(); - assert_eq!(s, "/foo\n\t/bar\n".to_string()); + assert_eq!(s, "External (/foo)\n\tExternal (/bar)\n".to_string()); } #[test] fn resource_dependency_for_each() { let mut graph = ResourceDependencyGraph::new(&UntypedResource::new_pending( - PathBuf::from("/foo"), + PathBuf::from("/foo").into(), Uuid::default(), - true, )); graph .root .children .push(ResourceGraphNode::new(&UntypedResource::new_pending( - PathBuf::from("/bar"), + PathBuf::from("/bar").into(), Uuid::default(), - true, ))); let mut uuids = Vec::new(); diff --git a/fyrox-resource/src/loader.rs b/fyrox-resource/src/loader.rs index 7a2ee8a85..ccb2d88e4 100644 --- a/fyrox-resource/src/loader.rs +++ b/fyrox-resource/src/loader.rs @@ -209,13 +209,7 @@ mod test { Default::default() } - fn load( - &self, - _resource: UntypedResource, - _event_broadcaster: ResourceEventBroadcaster, - _reload: bool, - _io: Arc, - ) -> BoxedLoaderFuture { + fn load(&self, _path: PathBuf, _io: Arc) -> BoxedLoaderFuture { todo!() } } diff --git a/fyrox-resource/src/manager.rs b/fyrox-resource/src/manager.rs index c4346b40b..f904284ec 100644 --- a/fyrox-resource/src/manager.rs +++ b/fyrox-resource/src/manager.rs @@ -687,7 +687,7 @@ impl ResourceManagerState { mod test { use std::{fs::File, time::Duration}; - use crate::loader::{BoxedLoaderFuture, ResourceLoader}; + use crate::loader::{BoxedLoaderFuture, LoaderPayload, ResourceLoader}; use super::*; @@ -730,17 +730,8 @@ mod test { ::type_uuid() } - fn load( - &self, - resource: UntypedResource, - event_broadcaster: ResourceEventBroadcaster, - reload: bool, - _io: Arc, - ) -> BoxedLoaderFuture { - Box::pin(async move { - resource.commit_ok(Stub::default()); - event_broadcaster.broadcast_loaded_or_reloaded(resource, reload); - }) + fn load(&self, _path: PathBuf, _io: Arc) -> BoxedLoaderFuture { + Box::pin(async move { Ok(LoaderPayload::new(Stub::default())) }) } } @@ -753,8 +744,8 @@ mod test { let cx = ResourceWaitContext { resources: vec![ - UntypedResource::new_pending(path.clone(), type_uuid, true), - UntypedResource::new_load_error(path.clone(), Default::default(), type_uuid, true), + UntypedResource::new_pending(path.clone().into(), type_uuid), + UntypedResource::new_load_error(path.clone().into(), Default::default(), type_uuid), ], }; assert!(!cx.is_all_loaded()); @@ -796,14 +787,13 @@ mod test { let path = PathBuf::from("test.txt"); let type_uuid = Uuid::default(); - state.push(UntypedResource::new_pending(path.clone(), type_uuid, true)); + state.push(UntypedResource::new_pending(path.clone().into(), type_uuid)); state.push(UntypedResource::new_load_error( - path.clone(), + path.clone().into(), Default::default(), type_uuid, - true, )); - state.push(UntypedResource::new_ok(Default::default(), true, Stub {})); + state.push(UntypedResource::new_ok(Default::default(), Stub {})); assert_eq!(state.count_loaded_resources(), 1); assert_eq!(state.count_pending_resources(), 1); @@ -819,14 +809,13 @@ mod test { let path = PathBuf::from("test.txt"); let type_uuid = Uuid::default(); - state.push(UntypedResource::new_pending(path.clone(), type_uuid, true)); + state.push(UntypedResource::new_pending(path.clone().into(), type_uuid)); state.push(UntypedResource::new_load_error( - path.clone(), + path.clone().into(), Default::default(), type_uuid, - true, )); - state.push(UntypedResource::new_ok(Default::default(), true, Stub {})); + state.push(UntypedResource::new_ok(Default::default(), Stub {})); assert_eq!(state.loading_progress(), 33); } @@ -839,7 +828,7 @@ mod test { let path = PathBuf::from("test.txt"); let type_uuid = Uuid::default(); - let resource = UntypedResource::new_pending(path.clone(), type_uuid, true); + let resource = UntypedResource::new_pending(path.clone().into(), type_uuid); state.push(resource.clone()); assert_eq!(state.find(path), Some(&resource)); @@ -853,9 +842,10 @@ mod test { let path = PathBuf::from("test.txt"); let type_uuid = Uuid::default(); - let r1 = UntypedResource::new_pending(path.clone(), type_uuid, true); - let r2 = UntypedResource::new_load_error(path.clone(), Default::default(), type_uuid, true); - let r3 = UntypedResource::new_ok(Default::default(), true, Stub {}); + let r1 = UntypedResource::new_pending(path.clone().into(), type_uuid); + let r2 = + UntypedResource::new_load_error(path.clone().into(), Default::default(), type_uuid); + let r3 = UntypedResource::new_ok(Default::default(), Stub {}); state.push(r1.clone()); state.push(r2.clone()); state.push(r3.clone()); @@ -869,9 +859,8 @@ mod test { let mut state = ResourceManagerState::new(); state.push(UntypedResource::new_pending( - PathBuf::from("test.txt"), + PathBuf::from("test.txt").into(), Uuid::default(), - true, )); assert_eq!(state.len(), 1); @@ -886,7 +875,7 @@ mod test { let type_uuid = Uuid::default(); let resource = - UntypedResource::new_load_error(path.clone(), Default::default(), type_uuid, true); + UntypedResource::new_load_error(path.clone().into(), Default::default(), type_uuid); state.push(resource.clone()); let res = state.request(path); @@ -895,7 +884,7 @@ mod test { let path = PathBuf::from("foo.txt"); let res = state.request(path.clone()); - assert_eq!(res.path(), path.clone()); + assert_eq!(res.kind(), ResourceKind::External(path.clone())); assert_eq!(res.type_uuid(), type_uuid); assert!(!res.is_loading()); } @@ -906,10 +895,9 @@ mod test { state.loaders.set(Stub {}); let resource = UntypedResource::new_load_error( - PathBuf::from("test.txt"), + PathBuf::from("test.txt").into(), Default::default(), Uuid::default(), - true, ); state.push(resource.clone()); @@ -923,7 +911,7 @@ mod test { fn resource_manager_state_get_wait_context() { let mut state = ResourceManagerState::new(); - let resource = UntypedResource::new_ok(Default::default(), true, Stub {}); + let resource = UntypedResource::new_ok(Default::default(), Stub {}); state.push(resource.clone()); let cx = state.get_wait_context(); @@ -944,11 +932,11 @@ mod test { let path = PathBuf::from("test.txt"); let type_uuid = Uuid::default(); - let resource = UntypedResource::new_pending(path.clone(), type_uuid, true); + let resource = UntypedResource::new_pending(path.clone().into(), type_uuid); let res = manager.register(resource.clone(), path.clone(), |_, __| true); assert!(res.is_err()); - let resource = UntypedResource::new_ok(Default::default(), true, Stub {}); + let resource = UntypedResource::new_ok(Default::default(), Stub {}); let res = manager.register(resource.clone(), path.clone(), |_, __| true); assert!(res.is_ok()); } @@ -956,7 +944,7 @@ mod test { #[test] fn resource_manager_request() { let manager = ResourceManager::new(); - let untyped = UntypedResource::new_ok(Default::default(), true, Stub {}); + let untyped = UntypedResource::new_ok(Default::default(), Stub {}); let res = manager.register(untyped.clone(), PathBuf::from("foo.txt"), |_, __| true); assert!(res.is_ok()); @@ -973,7 +961,7 @@ mod test { #[test] fn resource_manager_request_untyped() { let manager = ResourceManager::new(); - let resource = UntypedResource::new_ok(Default::default(), true, Stub {}); + let resource = UntypedResource::new_ok(Default::default(), Stub {}); let res = manager.register(resource.clone(), PathBuf::from("foo.txt"), |_, __| true); assert!(res.is_ok()); diff --git a/fyrox-resource/src/untyped.rs b/fyrox-resource/src/untyped.rs index 9a2502e9c..6c518c50d 100644 --- a/fyrox-resource/src/untyped.rs +++ b/fyrox-resource/src/untyped.rs @@ -81,6 +81,12 @@ impl From> for ResourceKind { } } +impl From for ResourceKind { + fn from(value: PathBuf) -> Self { + Self::External(value) + } +} + impl<'a> From<&'a str> for ResourceKind { fn from(value: &'a str) -> Self { Self::External(value.into()) @@ -468,23 +474,28 @@ mod test { #[test] fn untyped_resource_new_pending() { - let r = UntypedResource::new_pending(PathBuf::from("/foo"), Uuid::default(), true); + let r = UntypedResource::new_pending(PathBuf::from("/foo").into(), Uuid::default()); assert_eq!(r.0.lock().type_uuid, Uuid::default()); - assert_eq!(r.0.lock().path, PathBuf::from("/foo")); + assert_eq!( + r.0.lock().kind, + ResourceKind::External(PathBuf::from("/foo")) + ); } #[test] fn untyped_resource_new_load_error() { let r = UntypedResource::new_load_error( - PathBuf::from("/foo"), + PathBuf::from("/foo").into(), Default::default(), Uuid::default(), - true, ); assert_eq!(r.0.lock().type_uuid, Uuid::default()); - assert_eq!(r.0.lock().path, PathBuf::from("/foo")); + assert_eq!( + r.0.lock().kind, + ResourceKind::External(PathBuf::from("/foo")) + ); } #[test] @@ -498,9 +509,8 @@ mod test { fn untyped_resource_try_cast() { let r = UntypedResource::default(); let r2 = UntypedResource::new_pending( - PathBuf::from("/foo"), + PathBuf::from("/foo").into(), Uuid::from_u128(0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128), - true, ); assert!(r.try_cast::().is_some()); @@ -512,11 +522,11 @@ mod test { let path = PathBuf::from("/foo"); let stub = Stub {}; - let r = UntypedResource::new_pending(path.clone(), Default::default(), true); - assert_eq!(r.0.lock().path, path); + let r = UntypedResource::new_pending(path.clone().into(), Default::default()); + assert_eq!(r.0.lock().kind, ResourceKind::External(path.clone())); r.commit(ResourceState::Ok(Box::new(stub))); - assert_eq!(r.0.lock().path, path); + assert_eq!(r.0.lock().kind, ResourceKind::External(path)); } #[test] @@ -524,11 +534,11 @@ mod test { let path = PathBuf::from("/foo"); let stub = Stub {}; - let r = UntypedResource::new_pending(path.clone(), Default::default(), true); - assert_eq!(r.0.lock().path, path); + let r = UntypedResource::new_pending(path.clone().into(), Default::default()); + assert_eq!(r.0.lock().kind, ResourceKind::External(path.clone())); r.commit_ok(stub); - assert_eq!(r.0.lock().path, path); + assert_eq!(r.0.lock().kind, ResourceKind::External(path)); } #[test] @@ -536,9 +546,9 @@ mod test { let path = PathBuf::from("/foo"); let path2 = PathBuf::from("/bar"); - let r = UntypedResource::new_pending(path.clone(), Default::default(), true); - assert_eq!(r.0.lock().path, path); - assert_ne!(r.0.lock().path, path2); + let r = UntypedResource::new_pending(path.clone().into(), Default::default()); + assert_eq!(r.0.lock().kind, ResourceKind::External(path)); + assert_ne!(r.0.lock().kind, ResourceKind::External(path2)); } #[test] @@ -550,17 +560,15 @@ mod test { let mut cx = task::Context::from_waker(&waker); let mut r = UntypedResource(Arc::new(Mutex::new(ResourceHeader { - path: path.clone(), + kind: path.clone().into(), type_uuid: Uuid::default(), - is_embedded: true, state: ResourceState::Ok(Box::new(stub)), }))); assert!(Pin::new(&mut r).poll(&mut cx).is_ready()); let mut r = UntypedResource(Arc::new(Mutex::new(ResourceHeader { - path: path.clone(), + kind: path.clone().into(), type_uuid: Uuid::default(), - is_embedded: true, state: ResourceState::LoadError { error: Default::default(), }, diff --git a/fyrox-sound/examples/hrtf.rs b/fyrox-sound/examples/hrtf.rs index fb991af7b..c6d27c961 100644 --- a/fyrox-sound/examples/hrtf.rs +++ b/fyrox-sound/examples/hrtf.rs @@ -34,7 +34,7 @@ fn main() { context .state() .set_renderer(Renderer::HrtfRenderer(HrtfRenderer::new( - HrirSphereResource::from_hrir_sphere(hrir_sphere, hrir_path, true), + HrirSphereResource::from_hrir_sphere(hrir_sphere, hrir_path.into()), ))); // Create some sounds. diff --git a/fyrox-sound/examples/reverb.rs b/fyrox-sound/examples/reverb.rs index f9463492a..90f29e3ab 100644 --- a/fyrox-sound/examples/reverb.rs +++ b/fyrox-sound/examples/reverb.rs @@ -34,7 +34,7 @@ fn main() { context .state() .set_renderer(Renderer::HrtfRenderer(HrtfRenderer::new( - HrirSphereResource::from_hrir_sphere(hrir_sphere, hrir_path, true), + HrirSphereResource::from_hrir_sphere(hrir_sphere, hrir_path.into()), ))); { diff --git a/fyrox-sound/src/buffer/loader.rs b/fyrox-sound/src/buffer/loader.rs index 676a1d30b..9e30d333c 100644 --- a/fyrox-sound/src/buffer/loader.rs +++ b/fyrox-sound/src/buffer/loader.rs @@ -49,7 +49,7 @@ impl ResourceLoader for SoundBufferLoader { let source = DataSource::from_file(&path, io) .await - .map_err(|e| LoadError::new(e))?; + .map_err(LoadError::new)?; let result = if import_options.stream { SoundBuffer::raw_streaming(source) diff --git a/fyrox-sound/src/renderer/hrtf.rs b/fyrox-sound/src/renderer/hrtf.rs index 818c693d2..3dfe5c77b 100644 --- a/fyrox-sound/src/renderer/hrtf.rs +++ b/fyrox-sound/src/renderer/hrtf.rs @@ -31,7 +31,7 @@ //! let hrir_path = PathBuf::from("examples/data/IRC_1002_C.bin"); //! let hrir_sphere = HrirSphere::from_file(&hrir_path, context::SAMPLE_RATE).unwrap(); //! -//! context.state().set_renderer(Renderer::HrtfRenderer(HrtfRenderer::new(HrirSphereResource::from_hrir_sphere(hrir_sphere, hrir_path, true)))); +//! context.state().set_renderer(Renderer::HrtfRenderer(HrtfRenderer::new(HrirSphereResource::from_hrir_sphere(hrir_sphere, hrir_path.into())))); //! } //! ``` //! @@ -227,9 +227,9 @@ impl ResourceLoader for HrirSphereLoader { fn load(&self, path: PathBuf, io: Arc) -> BoxedLoaderFuture { Box::pin(async move { - let reader = io.file_reader(&path).await.map_err(|e| LoadError::new(e))?; + let reader = io.file_reader(&path).await.map_err(LoadError::new)?; let hrir_sphere = - HrirSphere::new(reader, context::SAMPLE_RATE).map_err(|e| LoadError::new(e))?; + HrirSphere::new(reader, context::SAMPLE_RATE).map_err(LoadError::new)?; Ok(LoaderPayload::new(HrirSphereResourceData { hrir_sphere: Some(hrir_sphere), })) diff --git a/src/material/loader.rs b/src/material/loader.rs index a2ef873e5..2102e033b 100644 --- a/src/material/loader.rs +++ b/src/material/loader.rs @@ -32,7 +32,7 @@ impl ResourceLoader for MaterialLoader { Box::pin(async move { let material = Material::from_file(&path, io.as_ref(), resource_manager) .await - .map_err(|e| LoadError::new(e))?; + .map_err(LoadError::new)?; Ok(LoaderPayload::new(material)) }) } diff --git a/src/material/shader/loader.rs b/src/material/shader/loader.rs index 721c5107c..9c1cfd3bc 100644 --- a/src/material/shader/loader.rs +++ b/src/material/shader/loader.rs @@ -27,7 +27,7 @@ impl ResourceLoader for ShaderLoader { Box::pin(async move { let shader_state = Shader::from_file(&path, io.as_ref()) .await - .map_err(|e| LoadError::new(e))?; + .map_err(LoadError::new)?; Ok(LoaderPayload::new(shader_state)) }) } diff --git a/src/material/shader/mod.rs b/src/material/shader/mod.rs index 4cebfcc1d..431258e49 100644 --- a/src/material/shader/mod.rs +++ b/src/material/shader/mod.rs @@ -737,7 +737,7 @@ mod test { ) "#; - let shader = ShaderResource::from_str(code, "test", true).unwrap(); + let shader = ShaderResource::from_str(code, "test".into()).unwrap(); let data = shader.data_ref(); let reference_definition = ShaderDefinition { diff --git a/src/resource/curve/loader.rs b/src/resource/curve/loader.rs index 9c599d24c..2acf0c881 100644 --- a/src/resource/curve/loader.rs +++ b/src/resource/curve/loader.rs @@ -27,7 +27,7 @@ impl ResourceLoader for CurveLoader { Box::pin(async move { let curve_state = CurveResourceState::from_file(&path, io.as_ref()) .await - .map_err(|e| LoadError::new(e))?; + .map_err(LoadError::new)?; Ok(LoaderPayload::new(curve_state)) }) } diff --git a/src/resource/model/loader.rs b/src/resource/model/loader.rs index 85465b37e..57b4d5db6 100644 --- a/src/resource/model/loader.rs +++ b/src/resource/model/loader.rs @@ -56,7 +56,7 @@ impl ResourceLoader for ModelLoader { import_options, ) .await - .map_err(|e| LoadError::new(e))?; + .map_err(LoadError::new)?; Ok(LoaderPayload::new(model)) }) diff --git a/src/resource/texture/loader.rs b/src/resource/texture/loader.rs index ceb8c97bb..9f88ed1f9 100644 --- a/src/resource/texture/loader.rs +++ b/src/resource/texture/loader.rs @@ -42,7 +42,7 @@ impl ResourceLoader for TextureLoader { let raw_texture = Texture::load_from_file(&path, io, import_options) .await - .map_err(|e| LoadError::new(e))?; + .map_err(LoadError::new)?; Ok(LoaderPayload::new(raw_texture)) }) diff --git a/src/resource/texture/mod.rs b/src/resource/texture/mod.rs index 875b1f73b..655a54aa6 100644 --- a/src/resource/texture/mod.rs +++ b/src/resource/texture/mod.rs @@ -1735,7 +1735,7 @@ pub mod test { }, TexturePixelKind::RGBA8, vec![1, 1, 1, 1], - false, + Default::default(), ) .unwrap() } diff --git a/src/scene/particle_system/mod.rs b/src/scene/particle_system/mod.rs index 1338d9ce7..f60035abf 100644 --- a/src/scene/particle_system/mod.rs +++ b/src/scene/particle_system/mod.rs @@ -201,7 +201,7 @@ impl Visit for ParticleSystemRng { /// ) /// .with_radius(0.01) /// .build()]) -/// .with_material(MaterialResource::new_ok(Default::default(), material, true)) +/// .with_material(MaterialResource::new_ok(Default::default(), material)) /// .build(graph); /// } /// ``` diff --git a/src/scene/sprite.rs b/src/scene/sprite.rs index dc556d595..dc9885e79 100644 --- a/src/scene/sprite.rs +++ b/src/scene/sprite.rs @@ -125,7 +125,7 @@ impl VertexTrait for SpriteVertex { /// .unwrap(); /// /// SpriteBuilder::new(BaseBuilder::new()) -/// .with_material(MaterialResource::new_ok(Default::default(), material, true)) +/// .with_material(MaterialResource::new_ok(Default::default(), material)) /// .build(graph) /// } /// ```