Giter Club home page Giter Club logo

Comments (15)

aleokdev avatar aleokdev commented on September 27, 2024 1

@aleokdev Maybe it would make sense to do a 0.11 release, even when not all its goals have been met yet?

I'll try to review all the changes done in the next branch this week, and publish a version if I don't see any major issues. Might even bundle the changes done in the unreleased current version along with it.

from rs-tiled.

bjorn avatar bjorn commented on September 27, 2024 1

@aleokdev I've opened #246 for merging current into next, but due to the deprecation of Tile::tile_type and Object::obj_type I think it would make sense to make a 0.10.3 release as well, at least if we want to then remove those deprecated members with the 0.11 release. If we can wait with that until 0.12 then I guess a 0.10.3 isn't really useful.

from rs-tiled.

aleokdev avatar aleokdev commented on September 27, 2024 1

Closing this as next is now merged: 0.11.0 has better load utils, which are more compatible with WASM binaries.

from rs-tiled.

aleokdev avatar aleokdev commented on September 27, 2024

Just as a workaround you can use the next branch for now and implement your own ResourceReader which doesn't use File. There is no future support though so you'll need to embed the map into the executable.

from rs-tiled.

Pietrek14 avatar Pietrek14 commented on September 27, 2024

Thanks you. Do you have any idea when it's going to be officially included in the crate?

from rs-tiled.

aleokdev avatar aleokdev commented on September 27, 2024

Hopefully on 0.12. Futures are a bit tricky to implement. 0.11 will have support for custom sync readers though.

from rs-tiled.

aleokdev avatar aleokdev commented on September 27, 2024

Leaving this here for other users, as a workaround for the crate to work with wasm you'll need to disable the zstd feature and a fully embedded map (Doesn't refer to external files, with the exception of images).
To disable the zstd feature turn the default features off: tiled = { /* ... */, default-features = false }
If you need to work with external files, then you'll need to use the next branch and implement your own ResourceReader. However, beware that futures are still not supported in the crate so you'll have a bad time trying to load anything that isn't embed in the executable itself.

from rs-tiled.

aleokdev avatar aleokdev commented on September 27, 2024

Sorry I didn't mention the embedded map thing before, I immediately assumed you needed to refer to external files given your description. If you can choose to use fully embedded maps instead, I recommend using those instead. The crate won't call File::open unless it is required to do so. (It doesn't call it for images either.)

from rs-tiled.

bjorn avatar bjorn commented on September 27, 2024

For the record, "embedded map" here is referring to storing a map with all tilesets embedded. However, I would not recommend embedding the tilesets in the working copy of your map if you're sharing them between multiple maps. Instead, you can export the map (File > Export) and rely on the "Embed tilesets" export option (Preferences > General > Export Options).

If you're using templates, be sure to enable the "Detach templates" export option as well.

from rs-tiled.

petersn avatar petersn commented on September 27, 2024

I was curious if a very small change would suffice, so I tried adjusting TMX parsing to first check the cache, then use File::open when load_tmx_map_from is called. The idea here is that in your browser build you simply preload all of the tilesets you'll need ahead of time into the cache, then load_tmx_map_from can simply grab these without touching the filesystem.

This is a very small change to the code base, here: current...petersn:rs-tiled:current

I added populate_tsx_cache_from with the same arguments as load_tsx_tileset_from, except that it populates the cache. You can use it like:

use tiled::Loader;

const TSX_PATH: &str = "assets/tilesheet.tsx";
const TSX_CONTENTS: &[u8] = include_bytes!(TSX_PATH);
const TMX_PATH: &str = "assets/map.tmx";
const TMX_CONTENTS: &[u8] = include_bytes!(TMX_PATH);

let mut loader = Loader::new();
let tileset = loader.populate_tsx_cache_from(&TSX_CONTENTS[..], TSX_PATH).unwrap();
// Now that the tileset is preloaded into the cache we may load the map without crashing.
let map = loader.load_tmx_map_from(&TMX_CONTENTS[..], TMX_PATH).unwrap();

If you add

tiled = { git = "https://github.com/petersn/rs-tiled", default-features = false }

to Cargo.toml you can try out this version as a workaround for browser wasm-bindgen builds.

I could turn this into a PR if folks are interested, but I assume that the goal would be to do something less hacky, in particular with this next branch?

from rs-tiled.

bjorn avatar bjorn commented on September 27, 2024

@petersn That's a nice approach, and I think actually this can already be done without any changes to rs-tiled when you use the next branch. Since Map was already adjusted to check first, before trying to read a file:

rs-tiled/src/map.rs

Lines 156 to 163 in bfd67ca

EmbeddedParseResultType::ExternalReference { tileset_path } => {
let tileset = if let Some(ts) = cache.get_tileset(&tileset_path) {
ts
} else {
let tileset = Arc::new(crate::parse::xml::parse_tileset(&tileset_path, reader, cache)?);
cache.insert_tileset(tileset_path.clone(), tileset.clone());
tileset
};

The Loader provides a mutable reference to the Cache:

rs-tiled/src/loader.rs

Lines 159 to 162 in bfd67ca

/// Returns a mutable reference to the loader's internal [`ResourceCache`].
pub fn cache_mut(&mut self) -> &mut Cache {
&mut self.cache
}

And the Cache provides a function to insert tilesets:

rs-tiled/src/cache.rs

Lines 42 to 45 in bfd67ca

/// Insert a new tileset into the cache.
///
/// See [`Self::get_tileset()`] for an example.
fn insert_tileset(&mut self, path: impl AsRef<ResourcePath>, tileset: Arc<Tileset>);

Maybe you could let us know whether this already suffices.

from rs-tiled.

petersn avatar petersn commented on September 27, 2024

@bjorn Thanks for the pointers, that looks great. Seems like it'll already suffice for my purposes, I'll switch to next. Are there any other gotchas I should be aware of on this branch?

from rs-tiled.

bjorn avatar bjorn commented on September 27, 2024

@petersn Check out the 0.11 changelog for a high-level overview of the changes: https://github.com/mapeditor/rs-tiled/blob/next/CHANGELOG.md

@aleokdev Maybe it would make sense to do a 0.11 release, even when not all its goals have been met yet?

from rs-tiled.

aleokdev avatar aleokdev commented on September 27, 2024

@aleokdev I've opened #246 for merging current into next, but due to the deprecation of Tile::tile_type and Object::obj_type I think it would make sense to make a 0.10.3 release as well, at least if we want to then remove those deprecated members with the 0.11 release. If we can wait with that until 0.12 then I guess a 0.10.3 isn't really useful.

@bjorn Apparently the change in TileData is breaking as we are adding a new public member to a fully public struct, so we need to bundle that with 0.11 anyway. I can stash that change and release 0.10.3 with the other changes.

from rs-tiled.

bjorn avatar bjorn commented on September 27, 2024

@aleokdev Ok, then I don't see much value in doing a 0.10.3 and think we could just go for 0.11.0, but up to you.

from rs-tiled.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.