hadronized / spectra

Rust demoscene engine (currently on hold)
122 stars 6 forks source link

Proxy resources #21

Closed hadronized closed 7 years ago

hadronized commented 7 years ago

I want a way to get a resource and if the loading fails, I still want to inject the resource in the cache by using a proxy resource. This is uber useful, especially when bootstrapping projects. You write the code without the data and you get proxies everywhere with a running application. You just have to create the files / modify the data to make the demo “pop out” of it! With the current implementation, if a resource fails to load at the first get, because we unwrap the result, we get a panic and the application stops.

The mechanism should be simple to work with. Maybe a new trait could work, like the following:

let super_texture = cache
  .get("super_texture", sampler_param)
  .unwrap_or_proxy(cache, proxy_texture.clone());
hadronized commented 7 years ago

Implemented but fails with hot-reloading.

hadronized commented 7 years ago

Hot reloading partially fixed. The problem is that I use Path::canonicalize to handle paths in a canonicalized way. Even though this is a nice solution, it won’t work with proxied resources because their paths might not exist (then there’s no way to canonicalize them).

The fix is actually pretty simple: upon creating the ResCache, we have to canonicalize the root path (and prevent from creating a ResCache if it doesn’t resolve to something that exists). Once we have that, we can use paths like data/splines/foo.json: they always resolve to the same because we have the canonicalized version of data, hence we can just append the relative path to the canonicalized one and end up on our feet.

hadronized commented 7 years ago

Fixed. I need to rebase, squash and clean up all the commits, and then we’re done.

hadronized commented 7 years ago

Fixed, I’ll release on crates.io as soon as possible.