use log::debug;
use std::sync::Arc;
use winit::window::Window;
use crate::errors::AleaticoResult;
use crate::renderer::ctx::GPUContext;
#[cfg(target_arch = "wasm32")]
use wasm_bindgen::prelude::*;
#[cfg(target_arch = "wasm32")]
use winit::platform::web::EventLoopExtWebSys;
pub struct State {
window: Arc<Window>,
gpu_context: GPUContext,
}
impl State {
pub async fn new(window: Arc<Window>) -> AleaticoResult<Self> {
let gpu_context = GPUContext::new(window.clone()).await?;
Ok(Self {
window,
gpu_context,
})
}
pub fn resize(&mut self, width: u32, height: u32) {
debug!("can we pretend to leave and then we'll meet again when both our cars collide?");
if width > 0 && height > 0 {
self.gpu_context.surface.config.width = width;
self.gpu_context.surface.config.height = height;
self.gpu_context.surface.inner.configure(
&self.gpu_context.surface.device,
&self.gpu_context.surface.config,
);
self.gpu_context.surface.is_configured = true;
}
}
pub fn update(&mut self) {}
pub fn render(&mut self) -> AleaticoResult<()> {
self.window.request_redraw();
self.gpu_context.render()
}
}