Handle::from_untyped
This commit is contained in:
parent
ed9eb88835
commit
2d0bff97a8
@ -22,6 +22,14 @@ impl<T> Handle<T> {
|
|||||||
marker: PhantomData,
|
marker: PhantomData,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn from_untyped(untyped_handle: HandleUntyped) -> Option<Handle<T>> where T: 'static {
|
||||||
|
if TypeId::of::<T>() == untyped_handle.type_id {
|
||||||
|
Some(Handle::new(untyped_handle.id))
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T> Hash for Handle<T> {
|
impl<T> Hash for Handle<T> {
|
||||||
@ -88,11 +96,7 @@ where
|
|||||||
T: 'static,
|
T: 'static,
|
||||||
{
|
{
|
||||||
fn from(handle: HandleUntyped) -> Self {
|
fn from(handle: HandleUntyped) -> Self {
|
||||||
if TypeId::of::<T>() != handle.type_id {
|
Handle::from_untyped(handle).expect("attempted to convert untyped handle to incorrect typed handle")
|
||||||
panic!("attempted to convert untyped handle to incorrect typed handle");
|
|
||||||
}
|
|
||||||
|
|
||||||
Handle::new(handle.id)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,4 +1,7 @@
|
|||||||
use crate::{asset::HandleUntyped, render::render_resource::RenderResourceAssignments};
|
use crate::{
|
||||||
|
asset::{Handle, HandleUntyped},
|
||||||
|
render::render_resource::RenderResourceAssignments,
|
||||||
|
};
|
||||||
use legion::prelude::Entity;
|
use legion::prelude::Entity;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
|
|
||||||
@ -23,4 +26,12 @@ impl Batch {
|
|||||||
self.current_instanced_entity_index += 1;
|
self.current_instanced_entity_index += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_handle<T>(&self) -> Option<Handle<T>> where T: 'static {
|
||||||
|
self.handles
|
||||||
|
.iter()
|
||||||
|
.map(|h| Handle::from_untyped(*h))
|
||||||
|
.find(|h| h.is_some())
|
||||||
|
.map(|h| h.unwrap())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user