engine: abstract resource loading

ecs
q3k 2020-04-04 22:18:26 +02:00
parent dfb3335d64
commit fab5855aaa
3 changed files with 14 additions and 6 deletions

View File

@ -5,7 +5,6 @@ use std::io::prelude::*;
use std::sync::Arc;
use std::path;
use runfiles::Runfiles;
use vulkano::descriptor::descriptor as vdd;
use vulkano::descriptor::pipeline_layout as vdp;
use vulkano::device as vd;
@ -24,11 +23,7 @@ impl ShaderDefinition {
pub fn load_into(self, device: Arc<vd::Device>) -> Result<LoadedShader, String> {
fn stringify(x: std::io::Error) -> String { format!("IO error: {}", x) }
let path = match Runfiles::create().map_err(stringify) {
Err(_) => path::Path::new(".").join("shaders").join(self.name.clone()),
Ok(r) => r.rlocation(format!("abrasion/engine/shaders/{}", self.name))
};
let path = &crate::util::file::resource_path(self.name.clone());
log::info!("Loading shader {}", path.to_str().unwrap_or("UNKNOWN"));
let mut f = File::open(path).map_err(stringify)?;

12
engine/src/util/file.rs Normal file
View File

@ -0,0 +1,12 @@
use std::path;
use runfiles::Runfiles;
pub fn resource_path(name: String) -> path::PathBuf {
fn stringify(x: std::io::Error) -> String { format!("IO error: {}", x) }
match Runfiles::create().map_err(stringify) {
Err(_) => path::Path::new(".").join("shaders").join(name),
Ok(r) => r.rlocation(format!("abrasion/engine/shaders/{}", name))
}
}

View File

@ -1 +1,2 @@
pub mod counter;
pub mod file;