Something went wrong. Try again.
A new game engine written in rust meant to be used in other personal projects
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273use std::collections::HashMap;
use snafu::prelude::*;use winit::{ application::ApplicationHandler, error::{EventLoopError, OsError}, event::{StartCause, WindowEvent}, event_loop::{ActiveEventLoop, EventLoop, EventLoopProxy}, window::WindowId,};
use crate::{event::Event, window::WindowContext};
#[derive(Debug, Snafu)]pub enum Error { #[snafu(display("failure to create the initial window"))] CreateInitialWindow { source: OsError }, #[snafu(display("failure to initialize event loop"))] InitializeEventLoop { source: EventLoopError },}
#[derive(Debug)]pub struct Processor { windows: HashMap<WindowId, WindowContext>, proxy: EventLoopProxy<Event>, initial_window_error: Option<OsError>,}
impl Processor { #[must_use] pub fn new(event_loop: &EventLoop<Event>) -> Self { Self { windows: Default::default(), proxy: event_loop.create_proxy(), initial_window_error: None, } }
pub fn create_window(&mut self, event_loop: &ActiveEventLoop) -> Result<(), OsError> { let window_context = WindowContext::new(event_loop)?; self.windows.insert(window_context.id(), window_context); Ok(()) }
pub fn run(&mut self, event_loop: EventLoop<Event>) -> Result<(), Error> { event_loop.run_app(self).context(InitializeEventLoopSnafu)?; match self.initial_window_error.take() { Some(initial_window_error) => { Err(initial_window_error).context(CreateInitialWindowSnafu) } None => Ok(()), } }}
impl ApplicationHandler<Event> for Processor { fn resumed(&mut self, event_loop: &ActiveEventLoop) { if let Err(err) = self.create_window(event_loop) { self.initial_window_error = Some(err); event_loop.exit(); return; } }
fn window_event( &mut self, event_loop: &ActiveEventLoop, window_id: WindowId, event: WindowEvent, ) { }}