From 3388dd64915f564fe03a2f8e2eb63304b75ddc2c Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 21 Nov 2023 17:03:50 +0100 Subject: [PATCH] get it to compile --- kubi/src/cursor_lock.rs | 15 +++--- kubi/src/events.rs | 13 ++--- kubi/src/input.rs | 24 ++++----- kubi/src/lib.rs | 19 ++++--- kubi/src/loading_screen.rs | 6 +-- kubi/src/networking.rs | 26 ++++------ kubi/src/rendering.rs | 103 +++++++++++++++++++------------------ 7 files changed, 105 insertions(+), 101 deletions(-) diff --git a/kubi/src/cursor_lock.rs b/kubi/src/cursor_lock.rs index 1951598..97b0ce0 100644 --- a/kubi/src/cursor_lock.rs +++ b/kubi/src/cursor_lock.rs @@ -13,13 +13,14 @@ pub fn update_cursor_lock_state( return } if lock.is_inserted_or_modified() { - let gl_window = display.display.gl_window(); - let window = gl_window.window(); - window.set_cursor_grab(match lock.0 { - true => CursorGrabMode::Confined, - false => CursorGrabMode::None, - }).expect("Failed to change cursor grab state"); - window.set_cursor_visible(!lock.0); + //TODO MIGRATION + // let gl_window = display.display.gl_window(); + // let window = gl_window.window(); + // window.set_cursor_grab(match lock.0 { + // true => CursorGrabMode::Confined, + // false => CursorGrabMode::None, + // }).expect("Failed to change cursor grab state"); + // window.set_cursor_visible(!lock.0); } } diff --git a/kubi/src/events.rs b/kubi/src/events.rs index 1e209b1..855ed3d 100644 --- a/kubi/src/events.rs +++ b/kubi/src/events.rs @@ -67,12 +67,13 @@ pub fn process_glutin_events(world: &mut World, event: &Event<()>) { )); }, - Event::LoopDestroyed => { - world.add_entity(( - EventComponent, - OnBeforeExitEvent - )); - }, + //TODO MIGRATION + // Event::LoopDestroyed => { + // world.add_entity(( + // EventComponent, + // OnBeforeExitEvent + // )); + // }, _ => (), } diff --git a/kubi/src/input.rs b/kubi/src/input.rs index cf75422..178cd2a 100644 --- a/kubi/src/input.rs +++ b/kubi/src/input.rs @@ -1,7 +1,7 @@ use gilrs::{Gilrs, GamepadId, Button, Event, Axis}; use glam::{Vec2, DVec2, vec2, dvec2}; use winit::{ - keyboard::Key, + keyboard::{KeyCode, PhysicalKey}, event::{DeviceEvent, DeviceId, ElementState, TouchPhase} }; use hashbrown::HashMap; @@ -97,21 +97,21 @@ fn process_events( ) { input_state.mouse_delta = DVec2::ZERO; for event in device_events.iter() { - match event.event { + match &event.event { DeviceEvent::MouseMotion { delta } => { - input_state.mouse_delta = DVec2::from(delta); + input_state.mouse_delta = DVec2::from(*delta); }, DeviceEvent::Key(input) => { - if let Some(keycode) = input.virtual_keycode { + if let PhysicalKey::Code(code) = input.physical_key { match input.state { - ElementState::Pressed => input_state.keyboard_state.insert(keycode as u32), - ElementState::Released => input_state.keyboard_state.remove(keycode as u32), + ElementState::Pressed => input_state.keyboard_state.insert(code as u32), + ElementState::Released => input_state.keyboard_state.remove(code as u32), }; } }, DeviceEvent::Button { button, state } => { - if button < 32 { - input_state.button_state[button as usize] = matches!(state, ElementState::Pressed); + if *button < 32 { + input_state.button_state[*button as usize] = matches!(*state, ElementState::Pressed); } }, _ => () @@ -176,10 +176,10 @@ fn update_input_state ( mut inputs: UniqueViewMut, ) { inputs.movement += Vec2::new( - raw_inputs.keyboard_state.contains(Key::D as u32) as u32 as f32 - - raw_inputs.keyboard_state.contains(Key::A as u32) as u32 as f32, - raw_inputs.keyboard_state.contains(Key::W as u32) as u32 as f32 - - raw_inputs.keyboard_state.contains(Key::S as u32) as u32 as f32 + raw_inputs.keyboard_state.contains(KeyCode::KeyD as u32) as u32 as f32 - + raw_inputs.keyboard_state.contains(KeyCode::KeyA as u32) as u32 as f32, + raw_inputs.keyboard_state.contains(KeyCode::KeyW as u32) as u32 as f32 - + raw_inputs.keyboard_state.contains(KeyCode::KeyS as u32) as u32 as f32 ); inputs.look += raw_inputs.mouse_delta.as_vec2(); inputs.action_a |= raw_inputs.button_state[1]; diff --git a/kubi/src/lib.rs b/kubi/src/lib.rs index d00999f..9e2ff0a 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -194,7 +194,7 @@ pub fn kubi_main() { world.run_workload(pre_startup).unwrap(); //Create event loop - let event_loop = EventLoop::new(); + let event_loop = EventLoop::new().unwrap(); //Initialize renderer { @@ -215,19 +215,21 @@ pub fn kubi_main() { //Run the event loop let mut last_update = Instant::now(); - event_loop.run(move |event, _, control_flow| { - *control_flow = ControlFlow::Poll; + event_loop.run(move |event, _| { + //TODO MIGRATION + //*control_flow = ControlFlow::Poll; process_glutin_events(&mut world, &event); #[allow(clippy::collapsible_match, clippy::single_match)] match event { Event::WindowEvent { event, .. } => match event { WindowEvent::CloseRequested => { log::info!("exit requested"); - *control_flow = ControlFlow::Exit; + //TODO MIGRATION + // *control_flow = ControlFlow::Exit; }, _ => (), }, - Event::MainEventsCleared => { + Event::AboutToWait => { //Update delta time (maybe move this into a system?) { let mut dt_view = world.borrow::>().unwrap(); @@ -235,10 +237,10 @@ pub fn kubi_main() { dt_view.0 = now - last_update; last_update = now; } - + //Run update workflows world.run_workload(update).unwrap(); - + //Start rendering (maybe use custom views for this?) let target = { let renderer = world.borrow::>>().unwrap(); @@ -258,7 +260,8 @@ pub fn kubi_main() { //Process control flow changes if let Some(flow) = world.borrow::>().unwrap().0 { - *control_flow = flow; + //TODO MIGRATION + //*control_flow = flow; } }, _ => (), diff --git a/kubi/src/loading_screen.rs b/kubi/src/loading_screen.rs index e214280..2cecc58 100644 --- a/kubi/src/loading_screen.rs +++ b/kubi/src/loading_screen.rs @@ -1,12 +1,12 @@ use shipyard::{UniqueView, UniqueViewMut, Workload, IntoWorkload, EntityId, Unique, AllStoragesViewMut, ViewMut, Get, SystemModificator, track}; -use winit::keyboard::Key; +use winit::keyboard::KeyCode; use glam::{Mat3, vec2}; use crate::{ world::ChunkStorage, state::{GameState, NextState, is_changing_state}, transform::Transform2d, legacy_gui::{ - GuiComponent, + GuiComponent, progressbar::ProgressbarComponent }, rendering::{WindowSize, if_resized}, @@ -76,7 +76,7 @@ fn override_loading( kbm_state: UniqueView, mut state: UniqueViewMut ) { - if kbm_state.keyboard_state.contains(Key::F as u32) { + if kbm_state.keyboard_state.contains(KeyCode::KeyF as u32) { state.0 = Some(GameState::InGame); } } diff --git a/kubi/src/networking.rs b/kubi/src/networking.rs index b422cb7..eac99f7 100644 --- a/kubi/src/networking.rs +++ b/kubi/src/networking.rs @@ -158,21 +158,17 @@ pub fn disconnect_on_exit( control_flow: UniqueView, mut client: UniqueViewMut, ) { - if let Some(ControlFlow::ExitWithCode(_)) = control_flow.0 { - if client.0.is_active() { - client.0.flush(); - client.0.disconnect(); - while client.0.is_active() { client.0.step().for_each(|_|()); } - log::info!("Client disconnected"); - } else { - log::info!("Client inactive") - } - // if let Err(error) = client.0. { - // log::error!("failed to disconnect: {}", error); - // } else { - // log::info!("Client disconnected"); - // } - } + //TODO MIGRATION + // if let Some(ControlFlow::ExitWithCode(_)) = control_flow.0 { + // if client.0.is_active() { + // client.0.flush(); + // client.0.disconnect(); + // while client.0.is_active() { client.0.step().for_each(|_|()); } + // log::info!("Client disconnected"); + // } else { + // log::info!("Client inactive") + // } + // } } // conditions diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index feeb297..b429dc0 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -1,7 +1,7 @@ use shipyard::{Unique, NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, AllStoragesView}; use winit::{ event_loop::EventLoop, - window::{WindowBuilder, Fullscreen}, + window::{WindowBuilder, Fullscreen, Window}, dpi::PhysicalSize }; use glium::{Display, Surface, Version, Api}; @@ -28,58 +28,61 @@ pub struct WindowSize(pub UVec2); #[derive(Unique)] pub struct Renderer { - pub display: Display + pub window: Window, + pub display: Display, } impl Renderer { pub fn init(event_loop: &EventLoop<()>, settings: &GameSettings) -> Self { log::info!("initializing display"); - let wb = WindowBuilder::new() - .with_title("kubi") - .with_maximized(true) - .with_min_inner_size(PhysicalSize::new(640, 480)) - .with_fullscreen({ - //this has no effect on android, so skip this pointless stuff - #[cfg(target_os = "android")] { - None - } - #[cfg(not(target_os = "android"))] - if let Some(fs_settings) = &settings.fullscreen { - let monitor = event_loop.primary_monitor().or_else(|| { - event_loop.available_monitors().next() - }); - if let Some(monitor) = monitor { - log::info!("monitor: {}", monitor.name().unwrap_or_else(|| "generic".into())); - match fs_settings.mode { - FullscreenMode::Borderless => { - log::info!("starting in borderless fullscreen mode"); - Some(Fullscreen::Borderless(Some(monitor))) - }, - FullscreenMode::Exclusive => { - log::warn!("exclusive fullscreen mode is experimental"); - log::info!("starting in exclusive fullscreen mode"); - //TODO: grabbing the first video mode is probably not the best idea... - monitor.video_modes().next() - .map(|vmode| { - log::info!("video mode: {}", vmode.to_string()); - Some(Fullscreen::Exclusive(vmode)) - }) - .unwrap_or_else(|| { - log::warn!("no valid video modes found, falling back to windowed mode instead"); - None - }) - } - } - } else { - log::warn!("no monitors found, falling back to windowed mode"); - None - } - } else { - log::info!("starting in windowed mode"); - None - } - }); + let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(&event_loop); + + // let wb = WindowBuilder::new() + // .with_title("kubi") + // .with_maximized(true) + // .with_min_inner_size(PhysicalSize::new(640, 480)) + // .with_fullscreen({ + // //this has no effect on android, so skip this pointless stuff + // #[cfg(target_os = "android")] { + // None + // } + // #[cfg(not(target_os = "android"))] + // if let Some(fs_settings) = &settings.fullscreen { + // let monitor = event_loop.primary_monitor().or_else(|| { + // event_loop.available_monitors().next() + // }); + // if let Some(monitor) = monitor { + // log::info!("monitor: {}", monitor.name().unwrap_or_else(|| "generic".into())); + // match fs_settings.mode { + // FullscreenMode::Borderless => { + // log::info!("starting in borderless fullscreen mode"); + // Some(Fullscreen::Borderless(Some(monitor))) + // }, + // FullscreenMode::Exclusive => { + // log::warn!("exclusive fullscreen mode is experimental"); + // log::info!("starting in exclusive fullscreen mode"); + // //TODO: grabbing the first video mode is probably not the best idea... + // monitor.video_modes().next() + // .map(|vmode| { + // log::info!("video mode: {}", vmode.to_string()); + // Some(Fullscreen::Exclusive(vmode)) + // }) + // .unwrap_or_else(|| { + // log::warn!("no valid video modes found, falling back to windowed mode instead"); + // None + // }) + // } + // } + // } else { + // log::warn!("no monitors found, falling back to windowed mode"); + // None + // } + // } else { + // log::info!("starting in windowed mode"); + // None + // } + // }); // let cb = ContextBuilder::new() // //.with_srgb(false) @@ -89,8 +92,8 @@ impl Renderer { // .with_gl_profile(GlProfile::Core) // .with_gl(GlRequest::Latest); - let display = Display::new(wb, cb) - .expect("Failed to create a glium Display"); + // let display = Display::new(wb, cb) + // .expect("Failed to create a glium Display"); log::info!("Vendor: {}", display.get_opengl_vendor_string()); log::info!("Renderer: {}", display.get_opengl_renderer_string()); @@ -103,7 +106,7 @@ impl Renderer { assert!(display.is_glsl_version_supported(&Version(Api::GlEs, 3, 0)), "GLSL ES 3.0 is not supported"); - Self { display } + Self { window, display } } }