ldtk_rust
ldtk_rust copied to clipboard
Use BufReader when loading files for a big speedup
Hey, first of all, thanks for making this crate, it works great and is well documented.
I wanted to quickly share that using a buffered reader on the File
s speeds loading up by a big amount, for me on windows at least.
So, for example this:
use std::io::BufReader;
...
let file = BufReader::new(File::open(f).expect("level file not found"));
instead of this:
let file = File::open(f).expect("level file not found");
Thanks for this tip. I'll test locally, seems like a nice refinement.
Also, great project and I look forward to building my little hobby game using it.
As ad addition, would it be possible to expose a separate Project::from_buf(...) or similar, which either takes a BufReader or a &[u8]?
I ask because, this would allow us to hook into Bevy's AssetLoader system, allowing async loading of the file in addition to hot reloading.
I've checked in the following code, not sure if this is what you are looking for here?
pub fn from_buf(b: BufReader<File>) -> Self {
let o: Project = serde_json::from_reader(b).expect("error while reading");
o
}
I will try it shortly and let you know. I presume this won't allow the use of external maps? That's fine with me if it doesn't.