Entity structure

This commit is contained in:
2025-11-26 10:57:21 +01:00
parent fde5f11568
commit df7c547ea4
3 changed files with 41 additions and 1 deletions
+16 -1
View File
@@ -1,4 +1,19 @@
use osmium::entity::Component;
pub struct Velocity(pub i32);
impl Component for Velocity {
fn tick(&mut self) {}
}
fn main() { fn main() {
let mut engine = osmium::init(); let mut engine = osmium::init();
engine.thread("Main.event", move || {});
engine.thread("Main.tick", || {});
let mut my_rect = engine.draw(|r| {
// r.draw_rect(0, 0, 10, 10);
});
my_rect.component(Velocity(10));
} }
+13
View File
@@ -0,0 +1,13 @@
pub trait Component {
fn init_add(&mut self) {}
fn init(&mut self) {}
fn tick(&mut self) {}
}
pub struct Entity(pub Vec<Box<dyn Component>>);
impl Entity {
pub fn component<C: Component + 'static>(&mut self, c: C) {
self.0.push(Box::new(c));
}
}
+12
View File
@@ -1,17 +1,29 @@
pub mod entity;
use std::collections::HashMap; use std::collections::HashMap;
pub fn init() -> Engine { pub fn init() -> Engine {
Engine { Engine {
threads: HashMap::new(), threads: HashMap::new(),
entities: Vec::new(),
} }
} }
pub struct Engine { pub struct Engine {
threads: HashMap<String, Box<dyn FnMut() + Send + Sync>>, threads: HashMap<String, Box<dyn FnMut() + Send + Sync>>,
entities: Vec<entity::Entity>,
} }
pub struct Renderer {}
impl Engine { impl Engine {
pub fn thread<F: FnMut() + Send + Sync + 'static>(&mut self, label: &str, f: F) { pub fn thread<F: FnMut() + Send + Sync + 'static>(&mut self, label: &str, f: F) {
self.threads.insert(label.to_string(), Box::new(f)); self.threads.insert(label.to_string(), Box::new(f));
} }
pub fn draw<F: FnMut(&mut Renderer) + 'static>(&self, mut f: F) -> entity::Entity {
let mut renderer = Renderer {};
(f)(&mut renderer);
entity::Entity(Vec::new())
}
} }