Skip to content

Commit

Permalink
Add custom drop to AssetStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
torkleyy committed Oct 22, 2017
1 parent 220833a commit ec4a05e
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions amethyst_assets/src/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,21 @@ impl<A: Asset> AssetStorage<A> {
}

/// Process finished asset data and maintain the storage.
pub fn process<F>(&mut self, mut f: F, errors: &Errors)
pub fn process<F>(&mut self, f: F, errors: &Errors)
where
F: FnMut(A::Data) -> Result<A, BoxedErr>,
{

self.process_custom_drop(f, |_| {}, errors);
}

/// Process finished asset data and maintain the storage.
/// This calls the `drop_fn` closure for assets that were removed from the storage.
pub fn process_custom_drop<F, D>(&mut self, mut f: F, mut drop_fn: D, errors: &Errors)
where
D: FnMut(A),
F: FnMut(A::Data) -> Result<A, BoxedErr>,
{
while let Some(processed) = self.processed.try_pop() {
let Processed {
data,
Expand Down Expand Up @@ -148,7 +159,7 @@ impl<A: Asset> AssetStorage<A> {
let old = self.handles.swap_remove(i);
let id = i as u32;
unsafe {
self.assets.remove(id);
drop_fn(self.assets.remove(id));
}
self.bitset.remove(id);
self.unused_handles.push(old);
Expand Down

0 comments on commit ec4a05e

Please sign in to comment.