Box shit up to spare the stack
This commit is contained in:
parent
05bc8cb7d6
commit
0676fc075b
@ -19,10 +19,10 @@ pub trait Childbearing<T> { // TODO remove this
|
||||
|
||||
impl Node {
|
||||
pub fn find_node(&mut self, name: &str) -> Option<NodeRef> {
|
||||
match self.children.iter().find(|node| node.borrow().name == name) {
|
||||
Some(node) => Some(Rc::clone(node)),
|
||||
None => None
|
||||
}
|
||||
self.children
|
||||
.iter()
|
||||
.find(|node| node.borrow().name == name)
|
||||
.map(|node| Rc::clone(node))
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ macro_rules! impl_childbearing {
|
||||
($t:ty, $e:path) => {
|
||||
impl Childbearing<$t> for Node {
|
||||
fn add_child(&mut self, name: &str, child: $t) {
|
||||
self.children.push(Rc::new(RefCell::new(Node::new(name.to_string(), $e(child)))));
|
||||
self.children.push(Rc::new(RefCell::new(Node::new(name.to_string(), $e(Box::new(child))))));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -50,8 +50,8 @@ impl Node {
|
||||
|
||||
pub enum GameObject {
|
||||
Null,
|
||||
Camera(Camera),
|
||||
Mesh(Mesh),
|
||||
Camera(Box<Camera>),
|
||||
Mesh(Box<Mesh>),
|
||||
}
|
||||
|
||||
impl GameObject {
|
||||
|
14
src/main.rs
14
src/main.rs
@ -93,19 +93,7 @@ fn main() {
|
||||
GameObject::Mesh(mesh) => mesh,
|
||||
_ => panic!("cube is not a mesh"),
|
||||
};
|
||||
let mut transform = cube.get_transform();
|
||||
if device_manager.is_pressed(&device::Key::W) {
|
||||
transform.position.z += 1.0 * delta;
|
||||
} else if device_manager.is_pressed(&device::Key::S) {
|
||||
transform.position.z -= 1.0 * delta;
|
||||
}
|
||||
if device_manager.is_pressed(&device::Key::A) {
|
||||
transform.rotation.x += 1.0 * delta;
|
||||
} else if device_manager.is_pressed(&device::Key::D) {
|
||||
transform.rotation.x -= 1.0 * delta;
|
||||
}
|
||||
|
||||
cube.set_transform(transform);
|
||||
// TODO, do this over the whole scene tree
|
||||
let mvp = glm::perspective::<f32>(4.0/3.0, 45.0_f32.to_radians(), 0.2, 100.0);
|
||||
let mvp = glm::translate::<f32>(&mvp, &cube.get_transform().position);
|
||||
let mvp = glm::rotate_x(&mvp, cube.get_transform().rotation.x);
|
||||
|
Loading…
Reference in New Issue
Block a user