refactor(spatial): store weak reference to parent node

This commit is contained in:
Nova
2022-05-22 12:35:22 -04:00
parent 73a0c6ff7a
commit 1709d19da2
4 changed files with 30 additions and 41 deletions

View File

@@ -4,12 +4,12 @@ use anyhow::Result;
use vek::mat::repr_c::row_major::Mat4;
pub struct Spatial<'a> {
node: &'a Node<'a>,
node: NodeRef<'a>,
transform: Mat4<f32>,
}
impl<'a> Spatial<'a> {
pub fn new(node: &'a Node<'a>, transform: Mat4<f32>) -> Self {
pub fn new(node: NodeRef<'a>, transform: Mat4<f32>) -> Self {
Spatial { node, transform }
}
@@ -18,8 +18,8 @@ impl<'a> Spatial<'a> {
path: &str,
transform: Mat4<f32>,
) -> Result<NodeRef<'a>> {
let node = Node::from_path(client, path)?;
node.upgrade().unwrap().borrow_mut().spatial = Some(Spatial::new(transform));
Ok(node)
Node::from_path(client, path, move |node| {
NodeData::Spatial(Spatial::new(node, transform))
})
}
}