summaryrefslogtreecommitdiff
path: root/client/src/window.rs
diff options
context:
space:
mode:
Diffstat (limited to 'client/src/window.rs')
-rw-r--r--client/src/window.rs36
1 files changed, 26 insertions, 10 deletions
diff --git a/client/src/window.rs b/client/src/window.rs
index 20300d5..5f2e7f8 100644
--- a/client/src/window.rs
+++ b/client/src/window.rs
@@ -1,4 +1,6 @@
-use crate::renderer::Renderer;
+use crate::state::State;
+use log::{info, warn};
+use std::net::TcpStream;
use winit::{
application::ApplicationHandler,
event::WindowEvent,
@@ -7,21 +9,28 @@ use winit::{
};
pub struct WindowState {
- window: Option<(Window, Renderer<'static>)>,
+ init: Option<TcpStream>,
+ window: Option<(Window, State<'static>)>,
}
impl WindowState {
- pub fn new() -> Self {
- Self { window: None }
+ pub fn new(init: TcpStream) -> Self {
+ Self {
+ window: None,
+ init: Some(init),
+ }
}
}
impl ApplicationHandler for WindowState {
fn resumed(&mut self, event_loop: &ActiveEventLoop) {
+ info!("app resumed");
let win = event_loop
.create_window(WindowAttributes::default().with_maximized(true))
.unwrap();
- let ren = Renderer::new(unsafe { std::mem::transmute::<&Window, &'static Window>(&win) })
- .unwrap();
- self.window = Some((win, ren))
+ let sta = State::new(self.init.take().unwrap(), unsafe {
+ std::mem::transmute::<&Window, &'static Window>(&win)
+ })
+ .unwrap();
+ self.window = Some((win, sta))
}
fn window_event(
&mut self,
@@ -29,12 +38,12 @@ impl ApplicationHandler for WindowState {
_window_id: WindowId,
event: WindowEvent,
) {
- if let Some((_win, ren)) = &mut self.window {
+ if let Some((_win, sta)) = &mut self.window {
match event {
WindowEvent::Resized(size) => {
- ren.resize(size.width, size.height);
+ sta.renderer.resize(size.width, size.height);
}
- WindowEvent::RedrawRequested => ren.draw().unwrap(),
+ WindowEvent::RedrawRequested => sta.renderer.draw().unwrap(),
WindowEvent::CloseRequested => {
event_loop.exit();
}
@@ -42,4 +51,11 @@ impl ApplicationHandler for WindowState {
}
}
}
+ fn about_to_wait(&mut self, _event_loop: &ActiveEventLoop) {
+ if let Some((_win, sta)) = &mut self.window {
+ if let Err(e) = sta.update() {
+ warn!("update failed: {e}")
+ }
+ }
+ }
}