summaryrefslogtreecommitdiff
path: root/src/file.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/file.rs')
-rw-r--r--src/file.rs16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/file.rs b/src/file.rs
index 42fecfa..2963879 100644
--- a/src/file.rs
+++ b/src/file.rs
@@ -1,4 +1,4 @@
-use std::{ffi::OsStr, path::Path, sync::Arc};
+use std::{ffi::OsStr, path::Path};
use rustc_hash::FxHashMap;
use serde::{Deserialize, Serialize};
@@ -9,7 +9,6 @@ use crate::scene::{Scene, scene_id_by_name};
type FileTask = Task<std::io::Result<FileData>>;
pub struct FileManager {
- pub wasm_compiler: Arc<wasmi::Engine>,
active_tasks: FxHashMap<Box<Path>, FileTask>,
cache: FxHashMap<Box<Path>, FileData>,
}
@@ -87,17 +86,20 @@ impl FileData {
impl FileManager {
pub fn new() -> Self {
Self {
- wasm_compiler: Arc::new(wasmi::Engine::default()),
active_tasks: FxHashMap::default(),
cache: FxHashMap::default(),
}
}
- pub fn load_file(&mut self, path: Box<Path>) -> std::io::Result<&FileData> {
+ pub fn load_file(
+ &mut self,
+ path: Box<Path>,
+ wasm_compiler: &wasmi::Engine,
+ ) -> std::io::Result<&FileData> {
let data = compile_data(
path.as_ref(),
&std::fs::read(path.as_ref()).map(Vec::into_boxed_slice)?,
- &self.wasm_compiler.clone(),
+ wasm_compiler,
)?;
self.cache.entry(path.clone()).insert_entry(data);
Ok(self.cache.get(&path).unwrap())
@@ -120,9 +122,9 @@ impl FileManager {
}
}
- pub fn start_loading_file(&mut self, path: impl AsRef<Path>) {
+ pub fn start_loading_file(&mut self, path: impl AsRef<Path>, wasm_compiler: &wasmi::Engine) {
let boxed_path = Box::from(path.as_ref());
- let compiler = self.wasm_compiler.clone();
+ let compiler = wasm_compiler.clone();
let task = unblock(move || {
compile_data(
&boxed_path,