Created
August 24, 2017 10:27
-
-
Save Archina/ce1374709b7a683eb56e67322b4420f3 to your computer and use it in GitHub Desktop.
Draft for a Entity-Component-System in Rust
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::vec::Vec; | |
use std::rc::{Weak,Rc}; | |
struct Component{ | |
parent: Weak<Compound>, | |
active_site: Option< Box< ActiveSite > >, | |
} | |
impl Component{ | |
fn update(&self){ | |
if self.active_site.is_some() { | |
self.active_site.as_ref().unwrap().update(self); | |
} | |
} | |
} | |
trait ActiveSite{ | |
fn update( &self, root: &Component); | |
} | |
struct Compound{ | |
components: Vec< Rc< Component > >, | |
} | |
impl Compound{ | |
/// Moves component and bind it's as part of the compound. | |
fn addComponent(&mut self, c: Component){ | |
self.components.push(Rc::new(c)); | |
} | |
fn removeComponent(&mut self, c: &mut Component ){ | |
self.components.remove(0); | |
} | |
} | |
#[test] | |
fn validate(){ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment