From d50f4323b1d76e07ce900c1c5e136dec35e062d8 Mon Sep 17 00:00:00 2001 From: griffi-gh Date: Tue, 21 Nov 2023 16:45:51 +0100 Subject: [PATCH] start fixing stuff --- kubi/src/block_placement.rs | 34 ++++++++++++++++++++-------------- kubi/src/control_flow.rs | 7 ++++--- kubi/src/cursor_lock.rs | 5 +++-- kubi/src/events.rs | 4 ++-- kubi/src/input.rs | 13 ++++++++----- kubi/src/lib.rs | 2 +- kubi/src/loading_screen.rs | 4 ++-- kubi/src/networking.rs | 2 +- kubi/src/rendering.rs | 35 +++++++++++++++++------------------ 9 files changed, 58 insertions(+), 48 deletions(-) diff --git a/kubi/src/block_placement.rs b/kubi/src/block_placement.rs index 93810b5..acad8ff 100644 --- a/kubi/src/block_placement.rs +++ b/kubi/src/block_placement.rs @@ -1,26 +1,32 @@ use shipyard::{UniqueViewMut, UniqueView, View, IntoIter, ViewMut, EntitiesViewMut, Workload, IntoWorkload}; -use glium::glutin::event::VirtualKeyCode; +use winit::keyboard::KeyCode; use kubi_shared::{ block::Block, - queue::QueuedBlock, + queue::QueuedBlock, player::PlayerHolding, }; use crate::{ player::MainPlayer, - world::{raycast::{LookingAtBlock, RAYCAST_STEP}, queue::BlockUpdateQueue}, - input::{Inputs, PrevInputs, RawKbmInputState}, - events::{EventComponent, player_actions::PlayerActionEvent}, + world::{ + raycast::{LookingAtBlock, RAYCAST_STEP}, + queue::BlockUpdateQueue + }, + input::{Inputs, PrevInputs, RawKbmInputState}, + events::{ + EventComponent, + player_actions::PlayerActionEvent + }, }; -const BLOCK_KEY_MAP: &[(VirtualKeyCode, Block)] = &[ - (VirtualKeyCode::Key1, Block::Cobblestone), - (VirtualKeyCode::Key2, Block::Planks), - (VirtualKeyCode::Key3, Block::Dirt), - (VirtualKeyCode::Key4, Block::Grass), - (VirtualKeyCode::Key5, Block::Sand), - (VirtualKeyCode::Key6, Block::Stone), - (VirtualKeyCode::Key7, Block::Torch), - (VirtualKeyCode::Key8, Block::Leaf), +const BLOCK_KEY_MAP: &[(KeyCode, Block)] = &[ + (KeyCode::Digit1, Block::Cobblestone), + (KeyCode::Digit2, Block::Planks), + (KeyCode::Digit3, Block::Dirt), + (KeyCode::Digit4, Block::Grass), + (KeyCode::Digit5, Block::Sand), + (KeyCode::Digit6, Block::Stone), + (KeyCode::Digit7, Block::Torch), + (KeyCode::Digit8, Block::Leaf), ]; fn pick_block_with_number_keys( diff --git a/kubi/src/control_flow.rs b/kubi/src/control_flow.rs index 4a4b0c3..10997de 100644 --- a/kubi/src/control_flow.rs +++ b/kubi/src/control_flow.rs @@ -1,5 +1,5 @@ use shipyard::{UniqueView, UniqueViewMut, Unique, AllStoragesView}; -use glium::glutin::{event::VirtualKeyCode, event_loop::ControlFlow}; +use winit::{keyboard::KeyCode, event_loop::ControlFlow}; use crate::input::RawKbmInputState; #[derive(Unique)] @@ -9,8 +9,9 @@ pub fn exit_on_esc( raw_inputs: UniqueView, mut control_flow: UniqueViewMut ) { - if raw_inputs.keyboard_state.contains(VirtualKeyCode::Escape as u32) { - control_flow.0 = Some(ControlFlow::Exit); + if raw_inputs.keyboard_state.contains(KeyCode::Escape as u32) { + //TODO MIGRATION: fix exit on esc + //control_flow.0 = Some(ControlFlow::Exit); } } diff --git a/kubi/src/cursor_lock.rs b/kubi/src/cursor_lock.rs index 428230a..090328f 100644 --- a/kubi/src/cursor_lock.rs +++ b/kubi/src/cursor_lock.rs @@ -1,6 +1,7 @@ +use glium::backend::Facade; use shipyard::{AllStoragesView, Unique, NonSendSync, UniqueView, UniqueViewMut}; use crate::rendering::Renderer; -use glium::glutin::window::CursorGrabMode; +use winit::window::CursorGrabMode; #[derive(Unique)] pub struct CursorLock(pub bool); @@ -13,7 +14,7 @@ pub fn update_cursor_lock_state( return } if lock.is_inserted_or_modified() { - let gl_window = display.display.gl_window(); + let gl_window = display.display.; let window = gl_window.window(); window.set_cursor_grab(match lock.0 { true => CursorGrabMode::Confined, diff --git a/kubi/src/events.rs b/kubi/src/events.rs index ba919f8..1e209b1 100644 --- a/kubi/src/events.rs +++ b/kubi/src/events.rs @@ -1,6 +1,6 @@ use glam::UVec2; use shipyard::{World, Component, AllStoragesViewMut, SparseSet, NonSendSync, UniqueView}; -use glium::glutin::event::{Event, DeviceEvent, DeviceId, WindowEvent, Touch}; +use winit::event::{Event, DeviceEvent, DeviceId, WindowEvent, Touch}; use crate::rendering::Renderer; pub mod player_actions; @@ -24,7 +24,7 @@ pub struct TouchEvent(pub Touch); #[derive(Component, Clone, Copy, Debug, Default)] pub struct WindowResizedEvent(pub UVec2); -pub fn process_glutin_events(world: &mut World, event: &Event<'_, ()>) { +pub fn process_glutin_events(world: &mut World, event: &Event<()>) { #[allow(clippy::collapsible_match, clippy::single_match)] match event { Event::WindowEvent { window_id: _, event } => match event { diff --git a/kubi/src/input.rs b/kubi/src/input.rs index d1e65b5..cf75422 100644 --- a/kubi/src/input.rs +++ b/kubi/src/input.rs @@ -1,6 +1,9 @@ use gilrs::{Gilrs, GamepadId, Button, Event, Axis}; use glam::{Vec2, DVec2, vec2, dvec2}; -use glium::glutin::event::{DeviceEvent, DeviceId, VirtualKeyCode, ElementState, TouchPhase}; +use winit::{ + keyboard::Key, + event::{DeviceEvent, DeviceId, ElementState, TouchPhase} +}; use hashbrown::HashMap; use tinyset::{SetU32, SetU64}; use nohash_hasher::BuildNoHashHasher; @@ -173,10 +176,10 @@ fn update_input_state ( mut inputs: UniqueViewMut, ) { inputs.movement += Vec2::new( - raw_inputs.keyboard_state.contains(VirtualKeyCode::D as u32) as u32 as f32 - - raw_inputs.keyboard_state.contains(VirtualKeyCode::A as u32) as u32 as f32, - raw_inputs.keyboard_state.contains(VirtualKeyCode::W as u32) as u32 as f32 - - raw_inputs.keyboard_state.contains(VirtualKeyCode::S as u32) as u32 as f32 + 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 ); 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 152f51d..d00999f 100644 --- a/kubi/src/lib.rs +++ b/kubi/src/lib.rs @@ -6,7 +6,7 @@ use shipyard::{ NonSendSync, WorkloadModificator, SystemModificator }; -use glium::glutin::{ +use winit::{ event_loop::{EventLoop, ControlFlow}, event::{Event, WindowEvent} }; diff --git a/kubi/src/loading_screen.rs b/kubi/src/loading_screen.rs index 91bbcdb..e214280 100644 --- a/kubi/src/loading_screen.rs +++ b/kubi/src/loading_screen.rs @@ -1,5 +1,5 @@ use shipyard::{UniqueView, UniqueViewMut, Workload, IntoWorkload, EntityId, Unique, AllStoragesViewMut, ViewMut, Get, SystemModificator, track}; -use glium::glutin::event::VirtualKeyCode; +use winit::keyboard::Key; use glam::{Mat3, vec2}; use crate::{ world::ChunkStorage, @@ -76,7 +76,7 @@ fn override_loading( kbm_state: UniqueView, mut state: UniqueViewMut ) { - if kbm_state.keyboard_state.contains(VirtualKeyCode::F as u32) { + if kbm_state.keyboard_state.contains(Key::F as u32) { state.0 = Some(GameState::InGame); } } diff --git a/kubi/src/networking.rs b/kubi/src/networking.rs index a0afa00..b422cb7 100644 --- a/kubi/src/networking.rs +++ b/kubi/src/networking.rs @@ -1,5 +1,5 @@ use shipyard::{Unique, AllStoragesView, UniqueView, UniqueViewMut, Workload, IntoWorkload, EntitiesViewMut, Component, ViewMut, SystemModificator, View, IntoIter, WorkloadModificator}; -use glium::glutin::event_loop::ControlFlow; +use winit::event_loop::ControlFlow; use std::net::SocketAddr; use uflow::{ client::{Client, Config as ClientConfig, Event as ClientEvent}, diff --git a/kubi/src/rendering.rs b/kubi/src/rendering.rs index a892d2b..feeb297 100644 --- a/kubi/src/rendering.rs +++ b/kubi/src/rendering.rs @@ -1,13 +1,11 @@ use shipyard::{Unique, NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, AllStoragesView}; -use glium::{ - Display, Surface, - Version, Api, - glutin::{ - event_loop::EventLoop, - window::{WindowBuilder, Fullscreen}, - ContextBuilder, GlProfile, GlRequest, dpi::PhysicalSize - }, +use winit::{ + event_loop::EventLoop, + window::{WindowBuilder, Fullscreen}, + dpi::PhysicalSize }; +use glium::{Display, Surface, Version, Api}; +use glutin::surface::WindowSurface; use glam::{Vec3, UVec2}; use crate::{events::WindowResizedEvent, settings::{GameSettings, FullscreenMode}}; @@ -30,12 +28,13 @@ pub struct WindowSize(pub UVec2); #[derive(Unique)] pub struct Renderer { - pub display: Display + 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) @@ -82,15 +81,15 @@ impl Renderer { } }); - let cb = ContextBuilder::new() - //.with_srgb(false) - .with_depth_buffer(24) - .with_multisampling(settings.msaa.unwrap_or_default()) - .with_vsync(settings.vsync) - .with_gl_profile(GlProfile::Core) - .with_gl(GlRequest::Latest); + // let cb = ContextBuilder::new() + // //.with_srgb(false) + // .with_depth_buffer(24) + // .with_multisampling(settings.msaa.unwrap_or_default()) + // .with_vsync(settings.vsync) + // .with_gl_profile(GlProfile::Core) + // .with_gl(GlRequest::Latest); - let display = Display::new(wb, cb, event_loop) + let display = Display::new(wb, cb) .expect("Failed to create a glium Display"); log::info!("Vendor: {}", display.get_opengl_vendor_string());