mod misc; mod render; mod resources; mod systems; use specs::{Dispatcher, DispatcherBuilder, World}; use crate::Error; use misc::{Events, TextManager, Window}; use render::{Debug, Init, Test}; use resources::{Camera, Geometry, State}; use systems::StateUpdate; pub struct App<'a, 'b> { is_running: bool, events: Events, window: Window, dispatcher: Dispatcher<'a, 'b>, } impl<'a, 'b> App<'a, 'b> { pub fn new(world: &mut World) -> Result { let events = Events::new(world); let window = Window::new(events.handle())?; world.insert(Camera::new()?); world.insert(Geometry::new()?); world.insert(State::default()); let text_manager = TextManager::new(world)?; let mut dispatcher = DispatcherBuilder::new() .with(StateUpdate::new(world)?, "state_update", &[]) .with_thread_local(Init::new(world)?) .with_thread_local(Test::new(world)?) .with_thread_local(Debug::new(&text_manager)?) .build(); dispatcher.setup(world); Ok(Self { is_running: true, events, window, dispatcher, }) } pub fn is_running(&self) -> bool { self.is_running } pub fn process(&mut self, world: &World) -> Result<(), Error> { self.events.process(world); self.dispatcher.dispatch(world); self.window.swap_buffers()?; self.is_running = !world.fetch::().close_requested; Ok(()) } }