replaced custom type casting to `downcast_ref/mut` for nodes
this was an artifact from scripting branch that somehow got into master
it was super slow, and caused massive performance issues because `T::type_uuid` using `Uuid::from_str`
@@ -309,12 +309,8 @@ impl Node {
/// node.cast::<Mesh>().expect("Expected to be an instance of Mesh")
/// }
/// ```
- pub fn cast<T: NodeTrait + TypeUuidProvider>(&self) -> Option<&T> {
- if self.id() == T::type_uuid() {
- unsafe { Some(&*(&*self.0 as *const dyn NodeTrait as *const T)) }
- } else {
- None
- }
+ pub fn cast<T: NodeTrait>(&self) -> Option<&T> {
+ self.0.as_any().downcast_ref::<T>()
}
/// Performs downcasting to a particular type.
@@ -329,12 +325,8 @@ impl Node {
/// node.cast_mut::<Mesh>().expect("Expected to be an instance of Mesh")
/// }
/// ```
- pub fn cast_mut<T: NodeTrait + TypeUuidProvider>(&mut self) -> Option<&mut T> {
- if self.id() == T::type_uuid() {
- unsafe { Some(&mut *(&mut *self.0 as *mut dyn NodeTrait as *mut T)) }
- } else {
- None
- }
+ pub fn cast_mut<T: NodeTrait>(&mut self) -> Option<&mut T> {
+ self.0.as_any_mut().downcast_mut::<T>()
}
/// Allows a node to provide access to a component of specified type.
