Skip to content

Instantly share code, notes, and snippets.

@Archina
Created August 24, 2017 10:27
Show Gist options
  • Save Archina/ce1374709b7a683eb56e67322b4420f3 to your computer and use it in GitHub Desktop.
Save Archina/ce1374709b7a683eb56e67322b4420f3 to your computer and use it in GitHub Desktop.
Draft for a Entity-Component-System in Rust
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