engine structure

This commit is contained in:
2025-11-26 19:51:09 +01:00
parent f959114327
commit 23144fb802
4 changed files with 44 additions and 4 deletions
+32
View File
@@ -18,6 +18,10 @@ pub struct Engine {
entities: Vec<entity::Entity>,
}
pub fn sleep(ms: u64) {
std::thread::sleep(std::time::Duration::from_millis(ms));
}
impl Engine {
pub fn thread<F: FnMut() + Send + Sync + 'static>(&mut self, label: &str, f: F) {
self.threads.insert(label.to_string(), Box::new(f));
@@ -30,4 +34,32 @@ impl Engine {
.last_mut()
.expect("Unable to obtain entity (unspawned)")
}
pub fn render(&mut self) {
terminal::clear().unwrap();
let mut renderer = renderer::Renderer::new();
for entity in &mut self.entities {
entity.render(&mut renderer);
}
}
pub fn tick(&mut self) {
terminal::clear().unwrap();
for entity in &mut self.entities {
entity.tick();
}
}
pub fn start(&mut self) {
for thr in &mut self.threads.values() {
// std::thread::spawn(thr);
}
loop {
self.render();
sleep(16);
}
}
}