mirror of
https://github.com/FyroxEngine/Fyrox.git
synced 2026-10-12 02:02:20 +00:00
resource api improvements + fixed tests
This commit is contained in:
+1
-1
@@ -58,7 +58,7 @@ impl SceneLoader {
|
||||
},
|
||||
)
|
||||
.unwrap();
|
||||
let material = MaterialResource::new_ok(material);
|
||||
let material = MaterialResource::new_ok(Default::default(), material, true);
|
||||
|
||||
// Add some sprites.
|
||||
for y in 0..10 {
|
||||
|
||||
+10
-2
@@ -77,7 +77,11 @@ async fn create_scene(resource_manager: ResourceManager) -> GameScene {
|
||||
.with_surfaces(vec![SurfaceBuilder::new(SurfaceSharedData::new(
|
||||
SurfaceData::make_sphere(10, 10, 0.1, &Matrix4::identity()),
|
||||
))
|
||||
.with_material(MaterialResource::new_ok(cursor_material))
|
||||
.with_material(MaterialResource::new_ok(
|
||||
Default::default(),
|
||||
cursor_material,
|
||||
true,
|
||||
))
|
||||
.build()])
|
||||
.build(&mut scene.graph);
|
||||
|
||||
@@ -99,7 +103,11 @@ 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(agent_material))
|
||||
.with_material(MaterialResource::new_ok(
|
||||
Default::default(),
|
||||
agent_material,
|
||||
true,
|
||||
))
|
||||
.build()])
|
||||
.build(&mut scene.graph);
|
||||
|
||||
|
||||
@@ -85,8 +85,6 @@ impl ResourceConstructorContainer {
|
||||
|
||||
#[cfg(test)]
|
||||
mod test {
|
||||
use std::path::PathBuf;
|
||||
|
||||
use fyrox_core::reflect::prelude::*;
|
||||
use fyrox_core::visitor::{Visit, VisitResult, Visitor};
|
||||
|
||||
@@ -96,28 +94,16 @@ mod test {
|
||||
struct Stub {}
|
||||
|
||||
impl ResourceData for Stub {
|
||||
fn path(&self) -> &std::path::Path {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn set_path(&mut self, _path: std::path::PathBuf) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
unimplemented!()
|
||||
self
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||
unimplemented!()
|
||||
self
|
||||
}
|
||||
|
||||
fn type_uuid(&self) -> Uuid {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn is_embedded(&self) -> bool {
|
||||
unimplemented!()
|
||||
Uuid::default()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -164,40 +150,4 @@ mod test {
|
||||
let res = c.try_create(&Uuid::default());
|
||||
assert!(res.is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn stub_path() {
|
||||
let s = Stub {};
|
||||
s.path();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn stub_set_path() {
|
||||
let mut s = Stub {};
|
||||
s.set_path(PathBuf::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn stub_set_as_any() {
|
||||
let s = Stub {};
|
||||
ResourceData::as_any(&s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn stub_set_as_any_mut() {
|
||||
let mut s = Stub {};
|
||||
ResourceData::as_any_mut(&mut s);
|
||||
s.type_uuid();
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn stub_set_type_uuid() {
|
||||
let s = Stub {};
|
||||
s.type_uuid();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,10 +116,12 @@ mod test {
|
||||
let mut node = ResourceGraphNode::new(&UntypedResource::new_pending(
|
||||
PathBuf::from("/foo"),
|
||||
Uuid::default(),
|
||||
true,
|
||||
));
|
||||
let node2 = ResourceGraphNode::new(&UntypedResource::new_pending(
|
||||
PathBuf::from("/bar"),
|
||||
Uuid::default(),
|
||||
true,
|
||||
));
|
||||
node.children.push(node2);
|
||||
node.pretty_print(1, &mut s);
|
||||
@@ -152,6 +154,7 @@ mod test {
|
||||
let mut graph = ResourceDependencyGraph::new(&UntypedResource::new_pending(
|
||||
PathBuf::from("/foo"),
|
||||
Uuid::default(),
|
||||
true,
|
||||
));
|
||||
graph
|
||||
.root
|
||||
@@ -159,6 +162,7 @@ mod test {
|
||||
.push(ResourceGraphNode::new(&UntypedResource::new_pending(
|
||||
PathBuf::from("/bar"),
|
||||
Uuid::default(),
|
||||
true,
|
||||
)));
|
||||
|
||||
let s = graph.pretty_print();
|
||||
@@ -170,6 +174,7 @@ mod test {
|
||||
let mut graph = ResourceDependencyGraph::new(&UntypedResource::new_pending(
|
||||
PathBuf::from("/foo"),
|
||||
Uuid::default(),
|
||||
true,
|
||||
));
|
||||
graph
|
||||
.root
|
||||
@@ -177,6 +182,7 @@ mod test {
|
||||
.push(ResourceGraphNode::new(&UntypedResource::new_pending(
|
||||
PathBuf::from("/bar"),
|
||||
Uuid::default(),
|
||||
true,
|
||||
)));
|
||||
|
||||
let mut uuids = Vec::new();
|
||||
|
||||
@@ -598,7 +598,8 @@ impl ResourceManagerState {
|
||||
"There's no resource loader for {} resource!",
|
||||
path.display()
|
||||
);
|
||||
resource.commit_error(path, msg)
|
||||
Log::err(&msg);
|
||||
resource.commit_error(msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -674,12 +675,6 @@ mod test {
|
||||
}
|
||||
|
||||
impl ResourceData for Stub {
|
||||
fn path(&self) -> &std::path::Path {
|
||||
Path::new("test.txt")
|
||||
}
|
||||
|
||||
fn set_path(&mut self, _path: std::path::PathBuf) {}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
unimplemented!()
|
||||
}
|
||||
@@ -691,10 +686,6 @@ mod test {
|
||||
fn type_uuid(&self) -> Uuid {
|
||||
<Self as TypeUuidProvider>::type_uuid()
|
||||
}
|
||||
|
||||
fn is_embedded(&self) -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl ResourceLoader for Stub {
|
||||
@@ -729,8 +720,8 @@ mod test {
|
||||
|
||||
let cx = ResourceWaitContext {
|
||||
resources: vec![
|
||||
UntypedResource::new_pending(path.clone(), type_uuid),
|
||||
UntypedResource::new_load_error(path.clone(), Default::default(), type_uuid),
|
||||
UntypedResource::new_pending(path.clone(), type_uuid, true),
|
||||
UntypedResource::new_load_error(path.clone(), Default::default(), type_uuid, true),
|
||||
],
|
||||
};
|
||||
assert!(!cx.is_all_loaded());
|
||||
@@ -772,13 +763,14 @@ mod test {
|
||||
|
||||
let path = PathBuf::from("test.txt");
|
||||
let type_uuid = Uuid::default();
|
||||
state.push(UntypedResource::new_pending(path.clone(), type_uuid));
|
||||
state.push(UntypedResource::new_pending(path.clone(), type_uuid, true));
|
||||
state.push(UntypedResource::new_load_error(
|
||||
path.clone(),
|
||||
Default::default(),
|
||||
type_uuid,
|
||||
true,
|
||||
));
|
||||
state.push(UntypedResource::new_ok(Stub {}));
|
||||
state.push(UntypedResource::new_ok(Default::default(), true, Stub {}));
|
||||
|
||||
assert_eq!(state.count_loaded_resources(), 1);
|
||||
assert_eq!(state.count_pending_resources(), 1);
|
||||
@@ -794,13 +786,14 @@ mod test {
|
||||
|
||||
let path = PathBuf::from("test.txt");
|
||||
let type_uuid = Uuid::default();
|
||||
state.push(UntypedResource::new_pending(path.clone(), type_uuid));
|
||||
state.push(UntypedResource::new_pending(path.clone(), type_uuid, true));
|
||||
state.push(UntypedResource::new_load_error(
|
||||
path.clone(),
|
||||
Default::default(),
|
||||
type_uuid,
|
||||
true,
|
||||
));
|
||||
state.push(UntypedResource::new_ok(Stub {}));
|
||||
state.push(UntypedResource::new_ok(Default::default(), true, Stub {}));
|
||||
|
||||
assert_eq!(state.loading_progress(), 33);
|
||||
}
|
||||
@@ -813,7 +806,7 @@ mod test {
|
||||
|
||||
let path = PathBuf::from("test.txt");
|
||||
let type_uuid = Uuid::default();
|
||||
let resource = UntypedResource::new_pending(path.clone(), type_uuid);
|
||||
let resource = UntypedResource::new_pending(path.clone(), type_uuid, true);
|
||||
state.push(resource.clone());
|
||||
|
||||
assert_eq!(state.find(path), Some(&resource));
|
||||
@@ -827,9 +820,9 @@ mod test {
|
||||
|
||||
let path = PathBuf::from("test.txt");
|
||||
let type_uuid = Uuid::default();
|
||||
let r1 = UntypedResource::new_pending(path.clone(), type_uuid);
|
||||
let r2 = UntypedResource::new_load_error(path.clone(), Default::default(), type_uuid);
|
||||
let r3 = UntypedResource::new_ok(Stub {});
|
||||
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 {});
|
||||
state.push(r1.clone());
|
||||
state.push(r2.clone());
|
||||
state.push(r3.clone());
|
||||
@@ -845,6 +838,7 @@ mod test {
|
||||
state.push(UntypedResource::new_pending(
|
||||
PathBuf::from("test.txt"),
|
||||
Uuid::default(),
|
||||
true,
|
||||
));
|
||||
assert_eq!(state.len(), 1);
|
||||
|
||||
@@ -858,7 +852,8 @@ mod test {
|
||||
let path = PathBuf::from("test.txt");
|
||||
let type_uuid = Uuid::default();
|
||||
|
||||
let resource = UntypedResource::new_load_error(path.clone(), Default::default(), type_uuid);
|
||||
let resource =
|
||||
UntypedResource::new_load_error(path.clone(), Default::default(), type_uuid, true);
|
||||
state.push(resource.clone());
|
||||
|
||||
let res = state.request(path);
|
||||
@@ -872,31 +867,6 @@ mod test {
|
||||
assert!(!res.is_loading());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resource_manager_state_reload_resource() {
|
||||
let mut state = ResourceManagerState::new();
|
||||
state.loaders.set(Stub {});
|
||||
|
||||
let resource = UntypedResource::new_ok(Stub {});
|
||||
state.push(resource.clone());
|
||||
state.reload_resource(resource.clone());
|
||||
|
||||
assert!(resource.is_loading());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resource_manager_state_reload_resources() {
|
||||
let mut state = ResourceManagerState::new();
|
||||
state.loaders.set(Stub {});
|
||||
|
||||
let resource = UntypedResource::new_ok(Stub {});
|
||||
state.push(resource.clone());
|
||||
let res = state.reload_resources();
|
||||
|
||||
assert_eq!(res.len(), 1);
|
||||
assert!(res[0].is_loading());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resource_manager_state_try_reload_resource_from_path() {
|
||||
let mut state = ResourceManagerState::new();
|
||||
@@ -906,6 +876,7 @@ mod test {
|
||||
PathBuf::from("test.txt"),
|
||||
Default::default(),
|
||||
Uuid::default(),
|
||||
true,
|
||||
);
|
||||
state.push(resource.clone());
|
||||
|
||||
@@ -919,7 +890,7 @@ mod test {
|
||||
fn resource_manager_state_get_wait_context() {
|
||||
let mut state = ResourceManagerState::new();
|
||||
|
||||
let resource = UntypedResource::new_ok(Stub {});
|
||||
let resource = UntypedResource::new_ok(Default::default(), true, Stub {});
|
||||
state.push(resource.clone());
|
||||
let cx = state.get_wait_context();
|
||||
|
||||
@@ -940,11 +911,11 @@ mod test {
|
||||
let path = PathBuf::from("test.txt");
|
||||
let type_uuid = Uuid::default();
|
||||
|
||||
let resource = UntypedResource::new_pending(path.clone(), type_uuid);
|
||||
let resource = UntypedResource::new_pending(path.clone(), type_uuid, true);
|
||||
let res = manager.register(resource.clone(), path.clone(), |_, __| true);
|
||||
assert!(res.is_err());
|
||||
|
||||
let resource = UntypedResource::new_ok(Stub {});
|
||||
let resource = UntypedResource::new_ok(Default::default(), true, Stub {});
|
||||
let res = manager.register(resource.clone(), path.clone(), |_, __| true);
|
||||
assert!(res.is_ok());
|
||||
}
|
||||
@@ -952,11 +923,11 @@ mod test {
|
||||
#[test]
|
||||
fn resource_manager_request() {
|
||||
let manager = ResourceManager::new();
|
||||
let untyped = UntypedResource::new_ok(Stub {});
|
||||
let untyped = UntypedResource::new_ok(Default::default(), true, Stub {});
|
||||
let res = manager.register(untyped.clone(), PathBuf::from("foo.txt"), |_, __| true);
|
||||
assert!(res.is_ok());
|
||||
|
||||
let res: Resource<Stub> = manager.request(Path::new("test.txt"));
|
||||
let res: Resource<Stub> = manager.request(Path::new("foo.txt"));
|
||||
assert_eq!(
|
||||
res,
|
||||
Resource {
|
||||
@@ -969,11 +940,11 @@ mod test {
|
||||
#[test]
|
||||
fn resource_manager_request_untyped() {
|
||||
let manager = ResourceManager::new();
|
||||
let resource = UntypedResource::new_ok(Stub {});
|
||||
let resource = UntypedResource::new_ok(Default::default(), true, Stub {});
|
||||
let res = manager.register(resource.clone(), PathBuf::from("foo.txt"), |_, __| true);
|
||||
assert!(res.is_ok());
|
||||
|
||||
let res = manager.request_untyped(Path::new("test.txt"));
|
||||
let res = manager.request_untyped(Path::new("foo.txt"));
|
||||
assert_eq!(res, resource);
|
||||
}
|
||||
|
||||
|
||||
+15
-131
@@ -1,13 +1,12 @@
|
||||
//! A module that handles resource states.
|
||||
|
||||
use crate::{
|
||||
core::{log::Log, reflect::prelude::*, uuid::Uuid, visitor::prelude::*},
|
||||
core::{reflect::prelude::*, uuid::Uuid, visitor::prelude::*},
|
||||
manager::ResourceManager,
|
||||
ResourceData, ResourceLoadError,
|
||||
};
|
||||
use std::{
|
||||
ops::{Deref, DerefMut},
|
||||
path::PathBuf,
|
||||
sync::Arc,
|
||||
task::Waker,
|
||||
};
|
||||
@@ -179,13 +178,7 @@ impl ResourceState {
|
||||
}
|
||||
|
||||
/// Changes internal state to [`ResourceState::LoadError`].
|
||||
pub fn commit_error<E: ResourceLoadError>(&mut self, path: PathBuf, error: E) {
|
||||
Log::err(format!(
|
||||
"An error occurred while loading {} resource. Reason: {:?}",
|
||||
path.display(),
|
||||
error
|
||||
));
|
||||
|
||||
pub fn commit_error<E: ResourceLoadError>(&mut self, error: E) {
|
||||
self.commit(ResourceState::LoadError {
|
||||
error: LoadError::new(error),
|
||||
})
|
||||
@@ -206,29 +199,17 @@ mod test {
|
||||
struct Stub {}
|
||||
|
||||
impl ResourceData for Stub {
|
||||
fn path(&self) -> &std::path::Path {
|
||||
Path::new("")
|
||||
}
|
||||
|
||||
fn set_path(&mut self, _path: std::path::PathBuf) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
unimplemented!()
|
||||
self
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||
unimplemented!()
|
||||
self
|
||||
}
|
||||
|
||||
fn type_uuid(&self) -> Uuid {
|
||||
Uuid::default()
|
||||
}
|
||||
|
||||
fn is_embedded(&self) -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeUuidProvider for Stub {
|
||||
@@ -239,52 +220,24 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn resource_state_new_pending() {
|
||||
let path = PathBuf::from("foo.txt");
|
||||
let type_uuid = Uuid::default();
|
||||
let state = ResourceState::new_pending(path.clone(), type_uuid);
|
||||
let state = ResourceState::new_pending();
|
||||
|
||||
assert!(matches!(
|
||||
state,
|
||||
ResourceState::Pending {
|
||||
path: _,
|
||||
wakers: _,
|
||||
type_uuid: _
|
||||
}
|
||||
));
|
||||
assert_eq!(state.path(), path);
|
||||
assert_eq!(state.type_uuid(), type_uuid);
|
||||
assert_eq!(state.id(), 0);
|
||||
assert!(matches!(state, ResourceState::Pending { wakers: _ }));
|
||||
assert!(state.is_loading());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resource_state_new_load_error() {
|
||||
let path = PathBuf::from("foo.txt");
|
||||
let type_uuid = Uuid::default();
|
||||
let state = ResourceState::new_load_error(path.clone(), Default::default(), type_uuid);
|
||||
let state = ResourceState::new_load_error(Default::default());
|
||||
|
||||
assert!(matches!(
|
||||
state,
|
||||
ResourceState::LoadError {
|
||||
path: _,
|
||||
error: _,
|
||||
type_uuid: _
|
||||
}
|
||||
));
|
||||
assert_eq!(state.path(), path);
|
||||
assert_eq!(state.type_uuid(), type_uuid);
|
||||
assert_eq!(state.id(), 1);
|
||||
assert!(matches!(state, ResourceState::LoadError { error: _ }));
|
||||
assert!(!state.is_loading());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resource_state_new_ok() {
|
||||
let state = ResourceState::new_ok(Stub {});
|
||||
|
||||
assert!(matches!(state, ResourceState::Ok(_)));
|
||||
assert_eq!(state.path(), Path::new(""));
|
||||
assert_eq!(state.type_uuid(), Uuid::default());
|
||||
assert_eq!(state.id(), 2);
|
||||
assert!(!state.is_loading());
|
||||
}
|
||||
|
||||
@@ -294,66 +247,31 @@ mod test {
|
||||
let mut state = ResourceState::new_ok(Stub {});
|
||||
state.switch_to_pending_state();
|
||||
|
||||
assert!(matches!(
|
||||
state,
|
||||
ResourceState::Pending {
|
||||
path: _,
|
||||
wakers: _,
|
||||
type_uuid: _
|
||||
}
|
||||
));
|
||||
assert_eq!(state.path(), Path::new(""));
|
||||
assert_eq!(state.type_uuid(), Uuid::default());
|
||||
assert!(matches!(state, ResourceState::Pending { wakers: _ }));
|
||||
|
||||
// from LoadError
|
||||
let path = PathBuf::from("foo.txt");
|
||||
let type_uuid = Uuid::default();
|
||||
let mut state = ResourceState::new_load_error(path.clone(), Default::default(), type_uuid);
|
||||
let mut state = ResourceState::new_load_error(Default::default());
|
||||
state.switch_to_pending_state();
|
||||
|
||||
assert!(matches!(
|
||||
state,
|
||||
ResourceState::Pending {
|
||||
path: _,
|
||||
wakers: _,
|
||||
type_uuid: _
|
||||
}
|
||||
));
|
||||
assert_eq!(state.path(), path);
|
||||
assert_eq!(state.type_uuid(), type_uuid);
|
||||
assert!(matches!(state, ResourceState::Pending { wakers: _ }));
|
||||
|
||||
// from Pending
|
||||
let path = PathBuf::from("foo.txt");
|
||||
let type_uuid = Uuid::default();
|
||||
let mut state = ResourceState::new_pending(path.clone(), type_uuid);
|
||||
let mut state = ResourceState::new_pending();
|
||||
state.switch_to_pending_state();
|
||||
|
||||
assert!(matches!(
|
||||
state,
|
||||
ResourceState::Pending {
|
||||
path: _,
|
||||
wakers: _,
|
||||
type_uuid: _
|
||||
}
|
||||
));
|
||||
assert_eq!(state.path(), path);
|
||||
assert_eq!(state.type_uuid(), type_uuid);
|
||||
assert!(matches!(state, ResourceState::Pending { wakers: _ }));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn visit_for_resource_state() {
|
||||
// Visit Pending
|
||||
let mut state = ResourceState::new_pending(PathBuf::from("foo.txt"), Uuid::default());
|
||||
let mut state = ResourceState::new_pending();
|
||||
let mut visitor = Visitor::default();
|
||||
|
||||
assert!(state.visit("name", &mut visitor).is_ok());
|
||||
|
||||
// Visit LoadError
|
||||
let mut state = ResourceState::new_load_error(
|
||||
PathBuf::from("foo.txt"),
|
||||
Default::default(),
|
||||
Uuid::default(),
|
||||
);
|
||||
let mut state = ResourceState::new_load_error(Default::default());
|
||||
let mut visitor = Visitor::default();
|
||||
|
||||
assert!(state.visit("name", &mut visitor).is_ok());
|
||||
@@ -364,38 +282,4 @@ mod test {
|
||||
|
||||
assert!(state.visit("name", &mut visitor).is_ok());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stub_path() {
|
||||
let s = Stub {};
|
||||
assert_eq!(s.path(), std::borrow::Cow::Borrowed(Path::new("")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn stub_set_path() {
|
||||
let mut s = Stub {};
|
||||
s.set_path(PathBuf::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn stub_set_as_any() {
|
||||
let s = Stub {};
|
||||
ResourceData::as_any(&s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn stub_set_as_any_mut() {
|
||||
let mut s = Stub {};
|
||||
ResourceData::as_any_mut(&mut s);
|
||||
s.type_uuid();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stub_set_type_uuid() {
|
||||
let s = Stub {};
|
||||
assert_eq!(s.type_uuid(), Uuid::default());
|
||||
}
|
||||
}
|
||||
|
||||
+32
-145
@@ -88,8 +88,6 @@ impl Visit for ResourceHeader {
|
||||
type_uuid = guess_uuid(&mut region);
|
||||
};
|
||||
|
||||
dbg!(type_uuid);
|
||||
|
||||
// We're interested only in embedded resources.
|
||||
if id == 2 {
|
||||
let resource_manager = region.blackboard.get::<ResourceManager>().expect(
|
||||
@@ -321,8 +319,8 @@ impl UntypedResource {
|
||||
}
|
||||
|
||||
/// Changes internal state to [`ResourceState::LoadError`].
|
||||
pub fn commit_error<E: ResourceLoadError>(&self, path: PathBuf, error: E) {
|
||||
self.0.lock().state.commit_error(path, error);
|
||||
pub fn commit_error<E: ResourceLoadError>(&self, error: E) {
|
||||
self.0.lock().state.commit_error(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -355,10 +353,7 @@ mod test {
|
||||
|
||||
use futures::task::noop_waker;
|
||||
use fyrox_core::futures;
|
||||
use std::{
|
||||
path::Path,
|
||||
task::{self},
|
||||
};
|
||||
use std::task::{self};
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -366,29 +361,17 @@ mod test {
|
||||
struct Stub {}
|
||||
|
||||
impl ResourceData for Stub {
|
||||
fn path(&self) -> &std::path::Path {
|
||||
Path::new("")
|
||||
}
|
||||
|
||||
fn set_path(&mut self, _path: std::path::PathBuf) {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
fn as_any(&self) -> &dyn std::any::Any {
|
||||
unimplemented!()
|
||||
self
|
||||
}
|
||||
|
||||
fn as_any_mut(&mut self) -> &mut dyn std::any::Any {
|
||||
unimplemented!()
|
||||
self
|
||||
}
|
||||
|
||||
fn type_uuid(&self) -> Uuid {
|
||||
Uuid::default()
|
||||
}
|
||||
|
||||
fn is_embedded(&self) -> bool {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
||||
impl TypeUuidProvider for Stub {
|
||||
@@ -416,10 +399,10 @@ mod test {
|
||||
|
||||
#[test]
|
||||
fn untyped_resource_new_pending() {
|
||||
let r = UntypedResource::new_pending(PathBuf::from("/foo"), Uuid::default());
|
||||
let r = UntypedResource::new_pending(PathBuf::from("/foo"), 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().type_uuid, Uuid::default());
|
||||
assert_eq!(r.0.lock().path, PathBuf::from("/foo"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -428,43 +411,11 @@ mod test {
|
||||
PathBuf::from("/foo"),
|
||||
Default::default(),
|
||||
Uuid::default(),
|
||||
true,
|
||||
);
|
||||
|
||||
assert_eq!(r.0.lock().type_uuid(), Uuid::default());
|
||||
assert_eq!(r.0.lock().path(), PathBuf::from("/foo"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn untyped_resource_new_ok() {
|
||||
let s = Stub {};
|
||||
let r = UntypedResource::new_ok(s);
|
||||
|
||||
assert_eq!(r.0.lock().type_uuid(), s.type_uuid());
|
||||
assert_eq!(r.0.lock().path(), s.path());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn untyped_resource_is_loading() {
|
||||
assert!(UntypedResource(Arc::new(Mutex::new(ResourceState::Pending {
|
||||
path: PathBuf::from("/foo"),
|
||||
wakers: Default::default(),
|
||||
type_uuid: Uuid::default()
|
||||
})))
|
||||
.is_loading());
|
||||
|
||||
assert!(
|
||||
!UntypedResource(Arc::new(Mutex::new(ResourceState::LoadError {
|
||||
path: PathBuf::from("/foo"),
|
||||
error: Default::default(),
|
||||
type_uuid: Uuid::default()
|
||||
})))
|
||||
.is_loading()
|
||||
);
|
||||
|
||||
assert!(
|
||||
!UntypedResource(Arc::new(Mutex::new(ResourceState::Ok(Box::new(Stub {})))))
|
||||
.is_loading()
|
||||
);
|
||||
assert_eq!(r.0.lock().type_uuid, Uuid::default());
|
||||
assert_eq!(r.0.lock().path, PathBuf::from("/foo"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -474,43 +425,13 @@ mod test {
|
||||
assert_eq!(r.use_count(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn untyped_resource_path() {
|
||||
let path = PathBuf::from("/foo");
|
||||
let stub = Stub {};
|
||||
|
||||
assert_eq!(
|
||||
UntypedResource(Arc::new(Mutex::new(ResourceState::Pending {
|
||||
path: path.clone(),
|
||||
wakers: Default::default(),
|
||||
type_uuid: Uuid::default()
|
||||
})))
|
||||
.path(),
|
||||
path
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
UntypedResource(Arc::new(Mutex::new(ResourceState::LoadError {
|
||||
path: path.clone(),
|
||||
error: Default::default(),
|
||||
type_uuid: Uuid::default()
|
||||
})))
|
||||
.path(),
|
||||
path
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
UntypedResource(Arc::new(Mutex::new(ResourceState::Ok(Box::new(stub))))).path(),
|
||||
stub.path(),
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn untyped_resource_try_cast() {
|
||||
let r = UntypedResource::default();
|
||||
let r2 = UntypedResource::new_pending(
|
||||
PathBuf::from("/foo"),
|
||||
Uuid::from_u128(0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128),
|
||||
true,
|
||||
);
|
||||
|
||||
assert!(r.try_cast::<Stub>().is_some());
|
||||
@@ -522,13 +443,11 @@ mod test {
|
||||
let path = PathBuf::from("/foo");
|
||||
let stub = Stub {};
|
||||
|
||||
let r = UntypedResource::new_pending(path.clone(), Default::default());
|
||||
assert_eq!(r.0.lock().path(), path);
|
||||
assert_ne!(r.0.lock().path(), stub.path());
|
||||
let r = UntypedResource::new_pending(path.clone(), Default::default(), true);
|
||||
assert_eq!(r.0.lock().path, path);
|
||||
|
||||
r.commit(ResourceState::Ok(Box::new(stub)));
|
||||
assert_ne!(r.0.lock().path(), path);
|
||||
assert_eq!(r.0.lock().path(), stub.path());
|
||||
assert_eq!(r.0.lock().path, path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -536,13 +455,11 @@ mod test {
|
||||
let path = PathBuf::from("/foo");
|
||||
let stub = Stub {};
|
||||
|
||||
let r = UntypedResource::new_pending(path.clone(), Default::default());
|
||||
assert_eq!(r.0.lock().path(), path);
|
||||
assert_ne!(r.0.lock().path(), stub.path());
|
||||
let r = UntypedResource::new_pending(path.clone(), Default::default(), true);
|
||||
assert_eq!(r.0.lock().path, path);
|
||||
|
||||
r.commit_ok(stub);
|
||||
assert_ne!(r.0.lock().path(), path);
|
||||
assert_eq!(r.0.lock().path(), stub.path());
|
||||
assert_eq!(r.0.lock().path, path);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -550,13 +467,9 @@ mod test {
|
||||
let path = PathBuf::from("/foo");
|
||||
let path2 = PathBuf::from("/bar");
|
||||
|
||||
let r = UntypedResource::new_pending(path.clone(), Default::default());
|
||||
assert_eq!(r.0.lock().path(), path);
|
||||
assert_ne!(r.0.lock().path(), path2);
|
||||
|
||||
r.commit_error(path2.clone(), "error");
|
||||
assert_ne!(r.0.lock().path(), path);
|
||||
assert_eq!(r.0.lock().path(), path2);
|
||||
let r = UntypedResource::new_pending(path.clone(), Default::default(), true);
|
||||
assert_eq!(r.0.lock().path, path);
|
||||
assert_ne!(r.0.lock().path, path2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -567,48 +480,22 @@ mod test {
|
||||
let waker = noop_waker();
|
||||
let mut cx = task::Context::from_waker(&waker);
|
||||
|
||||
let mut r = UntypedResource(Arc::new(Mutex::new(ResourceState::Ok(Box::new(stub)))));
|
||||
let mut r = UntypedResource(Arc::new(Mutex::new(ResourceHeader {
|
||||
path: path.clone(),
|
||||
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(ResourceState::LoadError {
|
||||
let mut r = UntypedResource(Arc::new(Mutex::new(ResourceHeader {
|
||||
path: path.clone(),
|
||||
error: Default::default(),
|
||||
type_uuid: Uuid::default(),
|
||||
is_embedded: true,
|
||||
state: ResourceState::LoadError {
|
||||
error: Default::default(),
|
||||
},
|
||||
})));
|
||||
assert!(Pin::new(&mut r).poll(&mut cx).is_ready());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stub_path() {
|
||||
let s = Stub {};
|
||||
assert_eq!(s.path(), std::borrow::Cow::Borrowed(Path::new("")));
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn stub_set_path() {
|
||||
let mut s = Stub {};
|
||||
s.set_path(PathBuf::new());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn stub_set_as_any() {
|
||||
let s = Stub {};
|
||||
ResourceData::as_any(&s);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic]
|
||||
fn stub_set_as_any_mut() {
|
||||
let mut s = Stub {};
|
||||
ResourceData::as_any_mut(&mut s);
|
||||
s.type_uuid();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn stub_set_type_uuid() {
|
||||
let s = Stub {};
|
||||
assert_eq!(s.type_uuid(), Uuid::default());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ fn main() {
|
||||
context
|
||||
.state()
|
||||
.set_renderer(Renderer::HrtfRenderer(HrtfRenderer::new(
|
||||
HrirSphereResource::from_hrir_sphere(hrir_sphere, hrir_path),
|
||||
HrirSphereResource::from_hrir_sphere(hrir_sphere, hrir_path, true),
|
||||
)));
|
||||
|
||||
// Create some sounds.
|
||||
|
||||
@@ -34,7 +34,7 @@ fn main() {
|
||||
context
|
||||
.state()
|
||||
.set_renderer(Renderer::HrtfRenderer(HrtfRenderer::new(
|
||||
HrirSphereResource::from_hrir_sphere(hrir_sphere, hrir_path),
|
||||
HrirSphereResource::from_hrir_sphere(hrir_sphere, hrir_path, true),
|
||||
)));
|
||||
|
||||
{
|
||||
|
||||
@@ -71,10 +71,7 @@ impl ResourceLoader for SoundBufferLoader {
|
||||
Log::info(format!("Sound buffer {:?} is loaded!", path));
|
||||
}
|
||||
Err(_) => {
|
||||
resource.commit_error(
|
||||
path.clone(),
|
||||
SoundBufferResourceLoadError::UnsupportedFormat,
|
||||
);
|
||||
resource.commit_error(SoundBufferResourceLoadError::UnsupportedFormat);
|
||||
|
||||
Log::info(format!("Unable to load sound buffer from {:?}!", path));
|
||||
}
|
||||
@@ -83,7 +80,7 @@ impl ResourceLoader for SoundBufferLoader {
|
||||
Err(e) => {
|
||||
Log::err(format!("Invalid data source for sound buffer: {:?}", e));
|
||||
|
||||
resource.commit_error(path.clone(), SoundBufferResourceLoadError::Io(e));
|
||||
resource.commit_error(SoundBufferResourceLoadError::Io(e));
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -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))));
|
||||
//! context.state().set_renderer(Renderer::HrtfRenderer(HrtfRenderer::new(HrirSphereResource::from_hrir_sphere(hrir_sphere, hrir_path, true))));
|
||||
//! }
|
||||
//! ```
|
||||
//!
|
||||
@@ -252,7 +252,7 @@ impl ResourceLoader for HrirSphereLoader {
|
||||
path, error
|
||||
));
|
||||
|
||||
hrir_sphere.commit_error(path, error);
|
||||
hrir_sphere.commit_error(error);
|
||||
}
|
||||
},
|
||||
Err(error) => {
|
||||
@@ -261,7 +261,7 @@ impl ResourceLoader for HrirSphereLoader {
|
||||
path, error
|
||||
));
|
||||
|
||||
hrir_sphere.commit_error(path, error);
|
||||
hrir_sphere.commit_error(error);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -53,7 +53,7 @@ impl ResourceLoader for MaterialLoader {
|
||||
path, error
|
||||
));
|
||||
|
||||
material.commit_error(path, error);
|
||||
material.commit_error(error);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -45,7 +45,7 @@ impl ResourceLoader for ShaderLoader {
|
||||
path, error
|
||||
));
|
||||
|
||||
shader.commit_error(path, error);
|
||||
shader.commit_error(error);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -760,7 +760,7 @@ mod test {
|
||||
)
|
||||
"#;
|
||||
|
||||
let shader = ShaderResource::from_str(code, "test").unwrap();
|
||||
let shader = ShaderResource::from_str(code, "test", true).unwrap();
|
||||
let data = shader.data_ref();
|
||||
|
||||
let reference_definition = ShaderDefinition {
|
||||
|
||||
@@ -47,7 +47,7 @@ impl ResourceLoader for CurveLoader {
|
||||
path, error
|
||||
));
|
||||
|
||||
curve.commit_error(path, error);
|
||||
curve.commit_error(error);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -77,7 +77,7 @@ impl ResourceLoader for ModelLoader {
|
||||
path, error
|
||||
));
|
||||
|
||||
model.commit_error(path, error);
|
||||
model.commit_error(error);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -67,7 +67,7 @@ impl ResourceLoader for TextureLoader {
|
||||
&path, &error
|
||||
));
|
||||
|
||||
texture.commit_error(path, error);
|
||||
texture.commit_error(error);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -201,7 +201,7 @@ impl Visit for ParticleSystemRng {
|
||||
/// )
|
||||
/// .with_radius(0.01)
|
||||
/// .build()])
|
||||
/// .with_material(MaterialResource::new_ok(material))
|
||||
/// .with_material(MaterialResource::new_ok(Default::default(), material, true))
|
||||
/// .build(graph);
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ impl VertexTrait for SpriteVertex {
|
||||
/// .unwrap();
|
||||
///
|
||||
/// SpriteBuilder::new(BaseBuilder::new())
|
||||
/// .with_material(MaterialResource::new_ok(material))
|
||||
/// .with_material(MaterialResource::new_ok(Default::default(), material, true))
|
||||
/// .build(graph)
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@@ -979,6 +979,8 @@ mod test {
|
||||
},
|
||||
utils::lightmap::{Lightmap, LightmapInputData},
|
||||
};
|
||||
use fyrox_resource::ResourceData;
|
||||
use std::path::Path;
|
||||
|
||||
#[test]
|
||||
fn test_generate_lightmap() {
|
||||
@@ -1022,8 +1024,7 @@ mod test {
|
||||
for entry_set in lightmap.map.values() {
|
||||
for entry in entry_set {
|
||||
let mut data = entry.texture.as_ref().unwrap().data_ref();
|
||||
data.set_path(format!("{}.png", counter));
|
||||
data.save().unwrap();
|
||||
data.save(Path::new(&format!("{}.png", counter))).unwrap();
|
||||
counter += 1;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user