engine structure
This commit is contained in:
+32
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user