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
}
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);
}
}

View file

@ -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
// ));
// },
_ => (),
}

View file

@ -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>,
) {
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];

View file

@ -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::<UniqueViewMut<DeltaTime>>().unwrap();
@ -258,7 +260,8 @@ pub fn kubi_main() {
//Process control flow changes
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 winit::keyboard::Key;
use winit::keyboard::KeyCode;
use glam::{Mat3, vec2};
use crate::{
world::ChunkStorage,
@ -76,7 +76,7 @@ fn override_loading(
kbm_state: UniqueView<RawKbmInputState>,
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);
}
}

View file

@ -158,21 +158,17 @@ pub fn disconnect_on_exit(
control_flow: UniqueView<SetControlFlow>,
mut client: UniqueViewMut<UdpClient>,
) {
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 {
//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

View file

@ -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<WindowSurface>
pub window: Window,
pub display: Display<WindowSurface>,
}
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 }
}
}