ldtk_rust icon indicating copy to clipboard operation
ldtk_rust copied to clipboard

Use BufReader when loading files for a big speedup

Open jornvandebeek opened this issue 2 years ago • 4 comments

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 Files 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");

jornvandebeek avatar Mar 16 '22 16:03 jornvandebeek

Thanks for this tip. I'll test locally, seems like a nice refinement.

estivate avatar Apr 01 '22 11:04 estivate

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.

stinkytoe avatar May 28 '22 17:05 stinkytoe

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
    }

estivate avatar Jun 05 '22 16:06 estivate

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.

stinkytoe avatar Jun 05 '22 23:06 stinkytoe