New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework assets crate #416

Merged
merged 40 commits into from Oct 16, 2017

Conversation

@torkleyy
Member

torkleyy commented Oct 14, 2017

Changes

  • Access sources from Format
  • Let the user handle future assets and loaded assets the same (Handle)
  • Add Progress struct to allow loading screens and similar stuff
  • Add asset storages, which will greatly simplify hot reloading
  • Improve examples
  • Rename Store to Source

TODO

  • Fix docs, especially outdated descriptions
  • Rewrite other crates to use new API
  • Cleanup
@torkleyy

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

FWIW I like it! Gonna hold off until the PR is done to do a full review, but do far it looks good.

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 15, 2017

Member

Should return mat also

Should return mat also

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 15, 2017

Member

Yeah, did locally already ;)

Member

torkleyy replied Oct 15, 2017

Yeah, did locally already ;)

amethyst_assets/src/asset.rs
- /// Request for clearing the whole cache.
- fn clear_all(&self) {}
-}
-
/// A format, providing a conversion from bytes to asset data, which is then
/// in turn accepted by `Asset::from_data`. Examples for formats are

This comment has been minimized.

@omni-viral

omni-viral Oct 15, 2017

Member

No such method.
How to convert Asset::Data into Asset now?

@omni-viral

omni-viral Oct 15, 2017

Member

No such method.
How to convert Asset::Data into Asset now?

This comment has been minimized.

@Rhuagh

Rhuagh Oct 15, 2017

Member

Check RenderSystem

@Rhuagh

Rhuagh Oct 15, 2017

Member

Check RenderSystem

This comment has been minimized.

@torkleyy

torkleyy Oct 15, 2017

Member

The advantage is that now systems can do that. So the problem you complained about (meshes taking two frames to be displayed) is fixed now.

@torkleyy

torkleyy Oct 15, 2017

Member

The advantage is that now systems can do that. So the problem you complained about (meshes taking two frames to be displayed) is fixed now.

camera: Option<Fetch<'a, Camera>>,
- mesh: ReadStorage<'a, M>,
- material: ReadStorage<'a, N>,
+ mesh_storage: Fetch<'a, AssetStorage<Mesh>>,

This comment has been minimized.

@omni-viral

omni-viral Oct 15, 2017

Member

You need AssetStorage<Texture> as well

@omni-viral

omni-viral Oct 15, 2017

Member

You need AssetStorage<Texture> as well

This comment has been minimized.

@torkleyy

torkleyy Oct 15, 2017

Member

I know, it's WIP

@torkleyy

torkleyy Oct 15, 2017

Member

I know, it's WIP

This comment has been minimized.

@torkleyy

torkleyy Oct 15, 2017

Member

Nearly done the passes though

@torkleyy

torkleyy Oct 15, 2017

Member

Nearly done the passes though

@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 15, 2017

Member

@omni-viral Now passes should be fixed. Code is not very organized, but logically it should be all there now.

Member

torkleyy commented Oct 15, 2017

@omni-viral Now passes should be fixed. Code is not very organized, but logically it should be all there now.

@omni-viral

This comment has been minimized.

Show comment
Hide comment
@omni-viral

omni-viral Oct 15, 2017

Member

@torkleyy so new system doesn't require any notification mechanism?

Member

omni-viral commented Oct 15, 2017

@torkleyy so new system doesn't require any notification mechanism?

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 15, 2017

Member

It's pull based, the asset loading systems will call process and be handed the data that has finished loading, and process them, turning them into assets

Member

Rhuagh commented Oct 15, 2017

It's pull based, the asset loading systems will call process and be handed the data that has finished loading, and process them, turning them into assets

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 15, 2017

Member

There's a simple implementation of a loading system that can be used for simple assets, check Processor

Member

Rhuagh commented Oct 15, 2017

There's a simple implementation of a loading system that can be used for simple assets, check Processor

@jojolepro

This comment has been minimized.

Show comment
Hide comment
@jojolepro

jojolepro Oct 15, 2017

Collaborator

A benchmark would be great. ;)

Collaborator

jojolepro commented Oct 15, 2017

A benchmark would be great. ;)

@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 15, 2017

Member

@jojolepro I'm pretty sure it's faster than before, but yes, we could really use some benchmarks. That said, I don't think I'll include them in this PR. It's already big enough.

Member

torkleyy commented Oct 15, 2017

@jojolepro I'm pretty sure it's faster than before, but yes, we could really use some benchmarks. That said, I don't think I'll include them in this PR. It's already big enough.

src/ecs/audio/bundle.rs
@@ -21,14 +21,15 @@ use shred::ResourceId;
///
/// Panics during `DjSystem` registration if the bundle is applied twice.
///
-pub struct DjBundle<'a> {
+pub struct DjBundle<'a, F> {

This comment has been minimized.

@jojolepro

jojolepro Oct 15, 2017

Collaborator

Since Dj is gone, maybe rename to AudioBundle?

@jojolepro

jojolepro Oct 15, 2017

Collaborator

Since Dj is gone, maybe rename to AudioBundle?

This comment has been minimized.

@torkleyy

torkleyy Oct 15, 2017

Member

But there's still DjSystem.

@torkleyy

torkleyy Oct 15, 2017

Member

But there's still DjSystem.

This comment has been minimized.

@torkleyy

torkleyy Oct 15, 2017

Member

Nah, okay, let's rename it.

@torkleyy

torkleyy Oct 15, 2017

Member

Nah, okay, let's rename it.

@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 15, 2017

Member

Right now things are still verbose, but it's getting better. I really hope that I can increase the expressibility in future PRs, not limited to the assets crate.

Member

torkleyy commented Oct 15, 2017

Right now things are still verbose, but it's getting better. I really hope that I can increase the expressibility in future PRs, not limited to the assets crate.

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 16, 2017

Member

Yeah, we could have all asset resources in examples/resources

Member

Rhuagh commented Oct 16, 2017

Yeah, we could have all asset resources in examples/resources

@omni-viral

I can't wait to see this in action.

@jojolepro

This comment has been minimized.

Show comment
Hide comment
@jojolepro

jojolepro Oct 16, 2017

Collaborator

I'll hold on reviewing, as I don't have anywhere enough time to check that much code. Following the discussions on gitter, conceptually this PR is good. 👍

Collaborator

jojolepro commented Oct 16, 2017

I'll hold on reviewing, as I don't have anywhere enough time to check that much code. Following the discussions on gitter, conceptually this PR is good. 👍

@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 16, 2017

Member

Thanks @jojolepro . I'm not sure I understood you correctly, are you self-requesting a review but saying you can't do the review now, or are you saying you can't do a full review because you don't have enough time?

Member

torkleyy commented Oct 16, 2017

Thanks @jojolepro . I'm not sure I understood you correctly, are you self-requesting a review but saying you can't do the review now, or are you saying you can't do a full review because you don't have enough time?

@jojolepro

This comment has been minimized.

Show comment
Hide comment
@jojolepro

jojolepro Oct 16, 2017

Collaborator

Can't fully review.

Collaborator

jojolepro commented Oct 16, 2017

Can't fully review.

log = "0.3.8"
parking_lot = "0.4.4"
rayon = "0.8"
specs = { version = "0.10", features = ["common"] }
+
+[dev-dependencies]
+ron = "0.1.4"

This comment has been minimized.

@omni-viral

omni-viral Oct 16, 2017

Member

Why don't you specify less strict versionron = "0.1"

@omni-viral

omni-viral Oct 16, 2017

Member

Why don't you specify less strict versionron = "0.1"

This comment has been minimized.

@torkleyy

torkleyy Oct 16, 2017

Member

That's because 0.1.3 had a a bug which has been fixed in 0.1.4, so I thought it would be important to require that version.

@torkleyy

torkleyy Oct 16, 2017

Member

That's because 0.1.3 had a a bug which has been fixed in 0.1.4, so I thought it would be important to require that version.

This comment has been minimized.

@omni-viral

omni-viral Oct 16, 2017

Member

Then use ^0.1.4
Otherwise it will be locked on 0.1.4

@omni-viral

omni-viral Oct 16, 2017

Member

Then use ^0.1.4
Otherwise it will be locked on 0.1.4

This comment has been minimized.

@torkleyy

torkleyy Oct 16, 2017

Member

No, 0.1.4 implies ^0.1.4.

@torkleyy

torkleyy Oct 16, 2017

Member

No, 0.1.4 implies ^0.1.4.

This comment has been minimized.

@torkleyy

torkleyy Oct 16, 2017

Member

=0.1.4 would lock it.

@torkleyy

torkleyy Oct 16, 2017

Member

=0.1.4 would lock it.

This comment has been minimized.

@omni-viral

omni-viral Oct 16, 2017

Member

Indeed ¯\_(ツ)_/¯

@omni-viral

omni-viral Oct 16, 2017

Member

Indeed ¯\_(ツ)_/¯

@omni-viral

I have a little concern in mind.
If an error occur in Source::load, Format::import and ends Errors passed in AssetStorage::process how user would know what Handle will never give him loaded asset?

amethyst_assets/src/storage.rs
+ errors.execute::<AssetError, _>(|| {
+ println!("Got asset with name {}", &name);
+
+ let asset = data.and_then(|d| f(d))

This comment has been minimized.

@omni-viral

omni-viral Oct 16, 2017

Member

Maybe and_then(f) ?

@omni-viral

omni-viral Oct 16, 2017

Member

Maybe and_then(f) ?

@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 16, 2017

Member

how user would know what Handle will never give him loaded asset

This actually is a problem, I know. You'd basically check the errors. So it's not the most ergonomic thing, but before the error was also just added to Errors.

Member

torkleyy commented Oct 16, 2017

how user would know what Handle will never give him loaded asset

This actually is a problem, I know. You'd basically check the errors. So it's not the most ergonomic thing, but before the error was also just added to Errors.

amethyst_assets/src/storage.rs
+ let bitset = &mut self.bitset;
+ let handles = &mut self.handles;
+ errors.execute::<AssetError, _>(|| {
+ let asset = data.and_then(|d| f(d))

This comment has been minimized.

@omni-viral

omni-viral Oct 16, 2017

Member

Maybe and_then(f)?

@omni-viral

omni-viral Oct 16, 2017

Member

Maybe and_then(f)?

This comment has been minimized.

@torkleyy

torkleyy Oct 16, 2017

Member

Tried, doesn't work since it would move the closure.

@torkleyy

torkleyy Oct 16, 2017

Member

Tried, doesn't work since it would move the closure.

This comment has been minimized.

@omni-viral

omni-viral Oct 16, 2017

Member

Ah. It's in loop.
and_then(&mut f) in this case.
Shows borrowing more explicitly.

@omni-viral

omni-viral Oct 16, 2017

Member

Ah. It's in loop.
and_then(&mut f) in this case.
Shows borrowing more explicitly.

This comment has been minimized.

@torkleyy

torkleyy Oct 16, 2017

Member

Is FnMut implemented for &mut T where T: FnMut? I think not, will try later.

@torkleyy

torkleyy Oct 16, 2017

Member

Is FnMut implemented for &mut T where T: FnMut? I think not, will try later.

@omni-viral

This comment has been minimized.

Show comment
Hide comment
@omni-viral

omni-viral Oct 16, 2017

Member

You'd basically check the errors.

How you can find connection between error in Errors (BoxedErr) and Handles?

Member

omni-viral commented Oct 16, 2017

You'd basically check the errors.

How you can find connection between error in Errors (BoxedErr) and Handles?

@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 16, 2017

Member

As I said, this is not fully resolved yet. To be honest, I don't know a very good solution right now; as I said, this problem existed before, so this is neither making the problem worse nor solves it.

Member

torkleyy commented Oct 16, 2017

As I said, this is not fully resolved yet. To be honest, I don't know a very good solution right now; as I said, this problem existed before, so this is neither making the problem worse nor solves it.

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 16, 2017

Member

Couldn't we use Progress for this? Push Handle<..> and the Error and have a separate function for it ?

Member

Rhuagh commented Oct 16, 2017

Couldn't we use Progress for this? Push Handle<..> and the Error and have a separate function for it ?

@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 16, 2017

Member

@Rhuagh This is a very, very, very good idea!

Member

torkleyy commented Oct 16, 2017

@Rhuagh This is a very, very, very good idea!

@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 16, 2017

Member

I actually thought about adding such a method, but I didn't realize it would solve this problem 😄

Member

torkleyy commented Oct 16, 2017

I actually thought about adding such a method, but I didn't realize it would solve this problem 😄

@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 16, 2017

Member

Again, this is great! 👍 I'll implement it!

Member

torkleyy commented Oct 16, 2017

Again, this is great! 👍 I'll implement it!

@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 16, 2017

Member

The only question that is left is should

  1. the progress tracker get the full BoxedErr or should we
  2. give it to Errors and give Progress only a description of the error?
Member

torkleyy commented Oct 16, 2017

The only question that is left is should

  1. the progress tracker get the full BoxedErr or should we
  2. give it to Errors and give Progress only a description of the error?
@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 16, 2017

Member

I'm not sure. Whichever way is easiest for now, we can improve on it later.

Member

Rhuagh commented Oct 16, 2017

I'm not sure. Whichever way is easiest for now, we can improve on it later.

@Aceeri Aceeri self-requested a review Oct 16, 2017

@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 16, 2017

Member

I've addressed all review comments, so please give it a final review. @Aceeri self-requested, so we need to wait for their review before merging.

Member

torkleyy commented Oct 16, 2017

I've addressed all review comments, so please give it a final review. @Aceeri self-requested, so we need to wait for their review before merging.

@torkleyy torkleyy requested a review from Rhuagh Oct 16, 2017

+ fn create_tracker(self) -> Self::Tracker;
+}
+
+impl Progress for () {

This comment has been minimized.

@torkleyy

torkleyy Oct 16, 2017

Member

So basically now you can also pass () if you don't care and just want the assets to pop in once they're there.

@torkleyy

torkleyy Oct 16, 2017

Member

So basically now you can also pass () if you don't care and just want the assets to pop in once they're there.

This comment has been minimized.

@torkleyy

torkleyy Oct 16, 2017

Member

Error handling needs improvements, but I think one can see that this design at least allows them, thus we should do that in a future PR.

@torkleyy

torkleyy Oct 16, 2017

Member

Error handling needs improvements, but I think one can see that this design at least allows them, thus we should do that in a future PR.

@Rhuagh

Rhuagh approved these changes Oct 16, 2017

Like you said, error handling needs improvement but let's do that in a separate PR.

@Xaeroxe

I would prefer that we fix music in pong prior to merging, otherwise looks great!

@Rhuagh

Rhuagh approved these changes Oct 16, 2017

@Aceeri

Aceeri approved these changes Oct 16, 2017

Looks like a great improvement to me.

amethyst_assets/examples/hl.rs
+}
+
+impl State {
+ /// Returns `true` if the app should quit.

This comment has been minimized.

@Aceeri

Aceeri Oct 16, 2017

Member

Its an example, but this should probably be "Returns Some(_) ..."

@Aceeri

Aceeri Oct 16, 2017

Member

Its an example, but this should probably be "Returns Some(_) ..."

amethyst_assets/src/storage.rs
+ self.bitset.remove(id);
+ self.unused_handles.push(old);
+
+ println!("Removed value!");

This comment has been minimized.

@Aceeri

Aceeri Oct 16, 2017

Member

Debug print? or logging?

@Aceeri

Aceeri Oct 16, 2017

Member

Debug print? or logging?

This comment has been minimized.

@torkleyy

torkleyy Oct 16, 2017

Member

Oops, will remove. I figure I used it for debugging.

@torkleyy

torkleyy Oct 16, 2017

Member

Oops, will remove. I figure I used it for debugging.

@Xaeroxe

LGTM! Thanks!

@torkleyy

This comment has been minimized.

Show comment
Hide comment
@torkleyy

torkleyy Oct 16, 2017

Member

So I assigned @Rhuagh for merging this when it's ready, and I assigned myself for 💤

Member

torkleyy commented Oct 16, 2017

So I assigned @Rhuagh for merging this when it's ready, and I assigned myself for 💤

@Rhuagh

This comment has been minimized.

Show comment
Hide comment
@Rhuagh

Rhuagh Oct 16, 2017

Member

bors r+

Member

Rhuagh commented Oct 16, 2017

bors r+

bors bot added a commit that referenced this pull request Oct 16, 2017

Merge #416
416: Rework assets crate r=Rhuagh a=torkleyy

## Changes

* Access sources from `Format`
* Let the user handle future assets and loaded assets the same (`Handle`)
* Add `Progress` struct to allow loading screens and similar stuff
* Add asset storages, which will greatly simplify hot reloading
* Improve examples
* Rename `Store` to `Source`

## TODO

* Fix docs, especially outdated descriptions
* Rewrite other crates to use new API
* Cleanup
@bors

This comment has been minimized.

Show comment
Hide comment

@bors bors bot merged commit f8355db into amethyst:develop Oct 16, 2017

3 checks passed

bors Build succeeded
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment