From df7c547ea443cad2335a865a7f276125fddc8f93 Mon Sep 17 00:00:00 2001 From: Leo dev Date: Wed, 26 Nov 2025 10:57:21 +0100 Subject: [PATCH] Entity structure --- examples/cube.rs | 17 ++++++++++++++++- src/entity.rs | 13 +++++++++++++ src/lib.rs | 12 ++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/entity.rs diff --git a/examples/cube.rs b/examples/cube.rs index 886cf0e..cbcdcb7 100644 --- a/examples/cube.rs +++ b/examples/cube.rs @@ -1,4 +1,19 @@ +use osmium::entity::Component; + +pub struct Velocity(pub i32); + +impl Component for Velocity { + fn tick(&mut self) {} +} + fn main() { 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)); } diff --git a/src/entity.rs b/src/entity.rs new file mode 100644 index 0000000..7cf9361 --- /dev/null +++ b/src/entity.rs @@ -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>); + +impl Entity { + pub fn component(&mut self, c: C) { + self.0.push(Box::new(c)); + } +} diff --git a/src/lib.rs b/src/lib.rs index 8ccb268..7bfc07e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,17 +1,29 @@ +pub mod entity; + use std::collections::HashMap; pub fn init() -> Engine { Engine { threads: HashMap::new(), + entities: Vec::new(), } } pub struct Engine { threads: HashMap>, + entities: Vec, } +pub struct Renderer {} + impl Engine { pub fn thread(&mut self, label: &str, f: F) { self.threads.insert(label.to_string(), Box::new(f)); } + + pub fn draw(&self, mut f: F) -> entity::Entity { + let mut renderer = Renderer {}; + (f)(&mut renderer); + entity::Entity(Vec::new()) + } }