get it to compile

This commit is contained in:
griffi-gh 2023-11-21 17:03:50 +01:00
parent 003f2fd460
commit 02009e6b59
7 changed files with 105 additions and 101 deletions

View file

@ -13,13 +13,14 @@ pub fn update_cursor_lock_state(
return return
} }
if lock.is_inserted_or_modified() { if lock.is_inserted_or_modified() {
let gl_window = display.display.gl_window(); //TODO MIGRATION
let window = gl_window.window(); // let gl_window = display.display.gl_window();
window.set_cursor_grab(match lock.0 { // let window = gl_window.window();
true => CursorGrabMode::Confined, // window.set_cursor_grab(match lock.0 {
false => CursorGrabMode::None, // true => CursorGrabMode::Confined,
}).expect("Failed to change cursor grab state"); // false => CursorGrabMode::None,
window.set_cursor_visible(!lock.0); // }).expect("Failed to change cursor grab state");
// window.set_cursor_visible(!lock.0);
} }
} }

View file

@ -67,12 +67,13 @@ pub fn process_glutin_events(world: &mut World, event: &Event<()>) {
)); ));
}, },
Event::LoopDestroyed => { //TODO MIGRATION
world.add_entity(( // Event::LoopDestroyed => {
EventComponent, // world.add_entity((
OnBeforeExitEvent // EventComponent,
)); // OnBeforeExitEvent
}, // ));
// },
_ => (), _ => (),
} }

View file

@ -1,7 +1,7 @@
use gilrs::{Gilrs, GamepadId, Button, Event, Axis}; use gilrs::{Gilrs, GamepadId, Button, Event, Axis};
use glam::{Vec2, DVec2, vec2, dvec2}; use glam::{Vec2, DVec2, vec2, dvec2};
use winit::{ use winit::{
keyboard::Key, keyboard::{KeyCode, PhysicalKey},
event::{DeviceEvent, DeviceId, ElementState, TouchPhase} event::{DeviceEvent, DeviceId, ElementState, TouchPhase}
}; };
use hashbrown::HashMap; use hashbrown::HashMap;
@ -97,21 +97,21 @@ fn process_events(
) { ) {
input_state.mouse_delta = DVec2::ZERO; input_state.mouse_delta = DVec2::ZERO;
for event in device_events.iter() { for event in device_events.iter() {
match event.event { match &event.event {
DeviceEvent::MouseMotion { delta } => { DeviceEvent::MouseMotion { delta } => {
input_state.mouse_delta = DVec2::from(delta); input_state.mouse_delta = DVec2::from(*delta);
}, },
DeviceEvent::Key(input) => { DeviceEvent::Key(input) => {
if let Some(keycode) = input.virtual_keycode { if let PhysicalKey::Code(code) = input.physical_key {
match input.state { match input.state {
ElementState::Pressed => input_state.keyboard_state.insert(keycode as u32), ElementState::Pressed => input_state.keyboard_state.insert(code as u32),
ElementState::Released => input_state.keyboard_state.remove(keycode as u32), ElementState::Released => input_state.keyboard_state.remove(code as u32),
}; };
} }
}, },
DeviceEvent::Button { button, state } => { DeviceEvent::Button { button, state } => {
if button < 32 { if *button < 32 {
input_state.button_state[button as usize] = matches!(state, ElementState::Pressed); input_state.button_state[*button as usize] = matches!(*state, ElementState::Pressed);
} }
}, },
_ => () _ => ()
@ -176,10 +176,10 @@ fn update_input_state (
mut inputs: UniqueViewMut<Inputs>, mut inputs: UniqueViewMut<Inputs>,
) { ) {
inputs.movement += Vec2::new( inputs.movement += Vec2::new(
raw_inputs.keyboard_state.contains(Key::D as u32) as u32 as f32 - raw_inputs.keyboard_state.contains(KeyCode::KeyD as u32) as u32 as f32 -
raw_inputs.keyboard_state.contains(Key::A as u32) as u32 as f32, raw_inputs.keyboard_state.contains(KeyCode::KeyA as u32) as u32 as f32,
raw_inputs.keyboard_state.contains(Key::W as u32) as u32 as f32 - raw_inputs.keyboard_state.contains(KeyCode::KeyW 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::KeyS as u32) as u32 as f32
); );
inputs.look += raw_inputs.mouse_delta.as_vec2(); inputs.look += raw_inputs.mouse_delta.as_vec2();
inputs.action_a |= raw_inputs.button_state[1]; inputs.action_a |= raw_inputs.button_state[1];

View file

@ -194,7 +194,7 @@ pub fn kubi_main() {
world.run_workload(pre_startup).unwrap(); world.run_workload(pre_startup).unwrap();
//Create event loop //Create event loop
let event_loop = EventLoop::new(); let event_loop = EventLoop::new().unwrap();
//Initialize renderer //Initialize renderer
{ {
@ -215,19 +215,21 @@ pub fn kubi_main() {
//Run the event loop //Run the event loop
let mut last_update = Instant::now(); let mut last_update = Instant::now();
event_loop.run(move |event, _, control_flow| { event_loop.run(move |event, _| {
*control_flow = ControlFlow::Poll; //TODO MIGRATION
//*control_flow = ControlFlow::Poll;
process_glutin_events(&mut world, &event); process_glutin_events(&mut world, &event);
#[allow(clippy::collapsible_match, clippy::single_match)] #[allow(clippy::collapsible_match, clippy::single_match)]
match event { match event {
Event::WindowEvent { event, .. } => match event { Event::WindowEvent { event, .. } => match event {
WindowEvent::CloseRequested => { WindowEvent::CloseRequested => {
log::info!("exit requested"); 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?) //Update delta time (maybe move this into a system?)
{ {
let mut dt_view = world.borrow::<UniqueViewMut<DeltaTime>>().unwrap(); let mut dt_view = world.borrow::<UniqueViewMut<DeltaTime>>().unwrap();
@ -258,7 +260,8 @@ pub fn kubi_main() {
//Process control flow changes //Process control flow changes
if let Some(flow) = world.borrow::<UniqueView<SetControlFlow>>().unwrap().0 { if let Some(flow) = world.borrow::<UniqueView<SetControlFlow>>().unwrap().0 {
*control_flow = flow; //TODO MIGRATION
//*control_flow = flow;
} }
}, },
_ => (), _ => (),

View file

@ -1,5 +1,5 @@
use shipyard::{UniqueView, UniqueViewMut, Workload, IntoWorkload, EntityId, Unique, AllStoragesViewMut, ViewMut, Get, SystemModificator, track}; 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 glam::{Mat3, vec2};
use crate::{ use crate::{
world::ChunkStorage, world::ChunkStorage,
@ -76,7 +76,7 @@ fn override_loading(
kbm_state: UniqueView<RawKbmInputState>, kbm_state: UniqueView<RawKbmInputState>,
mut state: UniqueViewMut<NextState> mut state: UniqueViewMut<NextState>
) { ) {
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); state.0 = Some(GameState::InGame);
} }
} }

View file

@ -158,21 +158,17 @@ pub fn disconnect_on_exit(
control_flow: UniqueView<SetControlFlow>, control_flow: UniqueView<SetControlFlow>,
mut client: UniqueViewMut<UdpClient>, mut client: UniqueViewMut<UdpClient>,
) { ) {
if let Some(ControlFlow::ExitWithCode(_)) = control_flow.0 { //TODO MIGRATION
if client.0.is_active() { // if let Some(ControlFlow::ExitWithCode(_)) = control_flow.0 {
client.0.flush(); // if client.0.is_active() {
client.0.disconnect(); // client.0.flush();
while client.0.is_active() { client.0.step().for_each(|_|()); } // client.0.disconnect();
log::info!("Client disconnected"); // while client.0.is_active() { client.0.step().for_each(|_|()); }
} else {
log::info!("Client inactive")
}
// if let Err(error) = client.0. {
// log::error!("failed to disconnect: {}", error);
// } else {
// log::info!("Client disconnected"); // log::info!("Client disconnected");
// } else {
// log::info!("Client inactive")
// }
// } // }
}
} }
// conditions // conditions

View file

@ -1,7 +1,7 @@
use shipyard::{Unique, NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, AllStoragesView}; use shipyard::{Unique, NonSendSync, UniqueView, UniqueViewMut, View, IntoIter, AllStoragesView};
use winit::{ use winit::{
event_loop::EventLoop, event_loop::EventLoop,
window::{WindowBuilder, Fullscreen}, window::{WindowBuilder, Fullscreen, Window},
dpi::PhysicalSize dpi::PhysicalSize
}; };
use glium::{Display, Surface, Version, Api}; use glium::{Display, Surface, Version, Api};
@ -28,58 +28,61 @@ pub struct WindowSize(pub UVec2);
#[derive(Unique)] #[derive(Unique)]
pub struct Renderer { pub struct Renderer {
pub display: Display<WindowSurface> pub window: Window,
pub display: Display<WindowSurface>,
} }
impl Renderer { impl Renderer {
pub fn init(event_loop: &EventLoop<()>, settings: &GameSettings) -> Self { pub fn init(event_loop: &EventLoop<()>, settings: &GameSettings) -> Self {
log::info!("initializing display"); log::info!("initializing display");
let wb = WindowBuilder::new() let (window, display) = glium::backend::glutin::SimpleWindowBuilder::new().build(&event_loop);
.with_title("kubi")
.with_maximized(true) // let wb = WindowBuilder::new()
.with_min_inner_size(PhysicalSize::new(640, 480)) // .with_title("kubi")
.with_fullscreen({ // .with_maximized(true)
//this has no effect on android, so skip this pointless stuff // .with_min_inner_size(PhysicalSize::new(640, 480))
#[cfg(target_os = "android")] { // .with_fullscreen({
None // //this has no effect on android, so skip this pointless stuff
} // #[cfg(target_os = "android")] {
#[cfg(not(target_os = "android"))] // None
if let Some(fs_settings) = &settings.fullscreen { // }
let monitor = event_loop.primary_monitor().or_else(|| { // #[cfg(not(target_os = "android"))]
event_loop.available_monitors().next() // if let Some(fs_settings) = &settings.fullscreen {
}); // let monitor = event_loop.primary_monitor().or_else(|| {
if let Some(monitor) = monitor { // event_loop.available_monitors().next()
log::info!("monitor: {}", monitor.name().unwrap_or_else(|| "generic".into())); // });
match fs_settings.mode { // if let Some(monitor) = monitor {
FullscreenMode::Borderless => { // log::info!("monitor: {}", monitor.name().unwrap_or_else(|| "generic".into()));
log::info!("starting in borderless fullscreen mode"); // match fs_settings.mode {
Some(Fullscreen::Borderless(Some(monitor))) // FullscreenMode::Borderless => {
}, // log::info!("starting in borderless fullscreen mode");
FullscreenMode::Exclusive => { // Some(Fullscreen::Borderless(Some(monitor)))
log::warn!("exclusive fullscreen mode is experimental"); // },
log::info!("starting in exclusive fullscreen mode"); // FullscreenMode::Exclusive => {
//TODO: grabbing the first video mode is probably not the best idea... // log::warn!("exclusive fullscreen mode is experimental");
monitor.video_modes().next() // log::info!("starting in exclusive fullscreen mode");
.map(|vmode| { // //TODO: grabbing the first video mode is probably not the best idea...
log::info!("video mode: {}", vmode.to_string()); // monitor.video_modes().next()
Some(Fullscreen::Exclusive(vmode)) // .map(|vmode| {
}) // log::info!("video mode: {}", vmode.to_string());
.unwrap_or_else(|| { // Some(Fullscreen::Exclusive(vmode))
log::warn!("no valid video modes found, falling back to windowed mode instead"); // })
None // .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::warn!("no monitors found, falling back to windowed mode");
} else { // None
log::info!("starting in windowed mode"); // }
None // } else {
} // log::info!("starting in windowed mode");
}); // None
// }
// });
// let cb = ContextBuilder::new() // let cb = ContextBuilder::new()
// //.with_srgb(false) // //.with_srgb(false)
@ -89,8 +92,8 @@ impl Renderer {
// .with_gl_profile(GlProfile::Core) // .with_gl_profile(GlProfile::Core)
// .with_gl(GlRequest::Latest); // .with_gl(GlRequest::Latest);
let display = Display::new(wb, cb) // let display = Display::new(wb, cb)
.expect("Failed to create a glium Display"); // .expect("Failed to create a glium Display");
log::info!("Vendor: {}", display.get_opengl_vendor_string()); log::info!("Vendor: {}", display.get_opengl_vendor_string());
log::info!("Renderer: {}", display.get_opengl_renderer_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"); assert!(display.is_glsl_version_supported(&Version(Api::GlEs, 3, 0)), "GLSL ES 3.0 is not supported");
Self { display } Self { window, display }
} }
} }