From e459b424187e72bce0bd859d7b93d5a9460795bf Mon Sep 17 00:00:00 2001 From: Carter Anderson Date: Wed, 6 May 2020 19:26:28 -0700 Subject: [PATCH] handle::new now creates a new random handle --- crates/bevy_asset/src/handle.rs | 11 +++++++++-- crates/bevy_asset/src/lib.rs | 4 ++-- crates/bevy_render/src/batch/batcher.rs | 12 ++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/crates/bevy_asset/src/handle.rs b/crates/bevy_asset/src/handle.rs index dfeaa3d839..5cd3c3d538 100644 --- a/crates/bevy_asset/src/handle.rs +++ b/crates/bevy_asset/src/handle.rs @@ -23,7 +23,14 @@ pub struct Handle { } impl Handle { - pub const fn new(id: HandleId) -> Self { + pub fn new() -> Self { + Handle { + id: HandleId::new(), + marker: PhantomData, + } + } + + pub const fn from_id(id: HandleId) -> Self { Handle { id, marker: PhantomData, @@ -49,7 +56,7 @@ impl Handle { T: 'static, { if TypeId::of::() == untyped_handle.type_id { - Some(Handle::new(untyped_handle.id)) + Some(Handle::from_id(untyped_handle.id)) } else { None } diff --git a/crates/bevy_asset/src/lib.rs b/crates/bevy_asset/src/lib.rs index e60f3e10a2..32a68a3d27 100644 --- a/crates/bevy_asset/src/lib.rs +++ b/crates/bevy_asset/src/lib.rs @@ -28,7 +28,7 @@ impl AssetStorage { pub fn add(&mut self, asset: T) -> Handle { let id = HandleId::new(); self.assets.insert(id, asset); - Handle::new(id) + Handle::from_id(id) } pub fn add_with_handle(&mut self, handle: Handle, asset: T) { @@ -61,7 +61,7 @@ impl AssetStorage { } pub fn iter(&self) -> impl Iterator, &T)> { - self.assets.iter().map(|(k, v)| (Handle::new(*k), v)) + self.assets.iter().map(|(k, v)| (Handle::from_id(*k), v)) } } diff --git a/crates/bevy_render/src/batch/batcher.rs b/crates/bevy_render/src/batch/batcher.rs index 2945f34050..b0eaed9db2 100644 --- a/crates/bevy_render/src/batch/batcher.rs +++ b/crates/bevy_render/src/batch/batcher.rs @@ -154,7 +154,7 @@ where #[cfg(test)] mod tests { use super::{Batch, BatchKey, Batcher}; - use bevy_asset::{Handle, HandleId, HandleUntyped}; + use bevy_asset::{Handle, HandleUntyped}; #[derive(Debug, Eq, PartialEq)] struct A; @@ -177,12 +177,12 @@ mod tests { let e2 = Entity(2); let e3 = Entity(3); - let a1: HandleUntyped = Handle::::new(HandleId::new()).into(); - let b1: HandleUntyped = Handle::::new(HandleId::new()).into(); - let c1: HandleUntyped = Handle::::new(HandleId::new()).into(); + let a1: HandleUntyped = Handle::::new().into(); + let b1: HandleUntyped = Handle::::new().into(); + let c1: HandleUntyped = Handle::::new().into(); - let a2: HandleUntyped = Handle::::new(HandleId::new()).into(); - let b2: HandleUntyped = Handle::::new(HandleId::new()).into(); + let a2: HandleUntyped = Handle::::new().into(); + let b2: HandleUntyped = Handle::::new().into(); let a1_b1 = BatchKey::key2(a1, b1); let a2_b2 = BatchKey::key2(a2, b2);