Reorganize project structure
This commit is contained in:
parent
be8ac84e36
commit
8cc1f7bf3e
13 changed files with 178 additions and 134 deletions
|
|
@ -1,64 +0,0 @@
|
|||
use std::time::Duration;
|
||||
|
||||
use anyhow::Result;
|
||||
use flax::World;
|
||||
|
||||
use crate::core::events::Events;
|
||||
|
||||
pub trait Module {
|
||||
fn on_update(&mut self, world: &mut World, events: &mut Events, frame_time: Duration) -> Result<()>;
|
||||
}
|
||||
|
||||
pub struct ModulesStack {
|
||||
modules: Vec<Box<dyn Module>>,
|
||||
}
|
||||
|
||||
impl ModulesStack {
|
||||
pub fn new() -> Self {
|
||||
Self { modules: Vec::new() }
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> std::slice::Iter<Box<dyn Module>> {
|
||||
self.modules.iter()
|
||||
}
|
||||
|
||||
pub fn iter_mut(&mut self) -> std::slice::IterMut<Box<dyn Module>> {
|
||||
self.modules.iter_mut()
|
||||
}
|
||||
|
||||
pub fn push<T: 'static + Module>(&mut self, layer: T) {
|
||||
let layer = Box::new(layer);
|
||||
self.modules.push(layer);
|
||||
}
|
||||
|
||||
pub fn insert<T: 'static + Module>(&mut self, index: usize, layer: T) {
|
||||
let layer = Box::new(layer);
|
||||
self.modules.insert(index, layer);
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for ModulesStack {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a ModulesStack {
|
||||
type Item = &'a Box<dyn Module>;
|
||||
|
||||
type IntoIter = std::slice::Iter<'a, Box<dyn Module>>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter()
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> IntoIterator for &'a mut ModulesStack {
|
||||
type Item = &'a mut Box<dyn Module>;
|
||||
|
||||
type IntoIter = std::slice::IterMut<'a, Box<dyn Module>>;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.iter_mut()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue