forked from StrafesNET/strafe-client
update code for winit 0.29.2
This commit is contained in:
parent
5493350023
commit
dd0b8fd1f0
@ -5,7 +5,7 @@ use std::str::FromStr;
|
|||||||
use web_sys::{ImageBitmapRenderingContext, OffscreenCanvas};
|
use web_sys::{ImageBitmapRenderingContext, OffscreenCanvas};
|
||||||
use winit::{
|
use winit::{
|
||||||
event::{self, WindowEvent, DeviceEvent},
|
event::{self, WindowEvent, DeviceEvent},
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::EventLoop,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[allow(dead_code)]
|
#[allow(dead_code)]
|
||||||
@ -88,7 +88,7 @@ async fn setup<E: Example>(title: &str) -> Setup {
|
|||||||
env_logger::init();
|
env_logger::init();
|
||||||
};
|
};
|
||||||
|
|
||||||
let event_loop = EventLoop::new();
|
let event_loop = EventLoop::new().unwrap();
|
||||||
let mut builder = winit::window::WindowBuilder::new();
|
let mut builder = winit::window::WindowBuilder::new();
|
||||||
builder = builder.with_title(title);
|
builder = builder.with_title(title);
|
||||||
#[cfg(windows_OFF)] // TODO
|
#[cfg(windows_OFF)] // TODO
|
||||||
@ -302,15 +302,15 @@ fn start<E: Example>(
|
|||||||
let mut example = E::init(&config, &adapter, &device, &queue);
|
let mut example = E::init(&config, &adapter, &device, &queue);
|
||||||
|
|
||||||
log::info!("Entering render loop...");
|
log::info!("Entering render loop...");
|
||||||
event_loop.run(move |event, _, control_flow| {
|
event_loop.run(move |event, elwt| {
|
||||||
let _ = (&instance, &adapter); // force ownership by the closure
|
let _ = (&instance, &adapter); // force ownership by the closure
|
||||||
*control_flow = if cfg!(feature = "metal-auto-capture") {
|
// *control_flow = if cfg!(feature = "metal-auto-capture") {
|
||||||
ControlFlow::Exit
|
// ControlFlow::Exit
|
||||||
} else {
|
// } else {
|
||||||
ControlFlow::Poll
|
// ControlFlow::Poll
|
||||||
};
|
// };
|
||||||
match event {
|
match event {
|
||||||
event::Event::RedrawEventsCleared => {
|
event::Event::AboutToWait => {
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
spawner.run_until_stalled();
|
spawner.run_until_stalled();
|
||||||
|
|
||||||
@ -318,48 +318,44 @@ fn start<E: Example>(
|
|||||||
}
|
}
|
||||||
event::Event::WindowEvent {
|
event::Event::WindowEvent {
|
||||||
event:
|
event:
|
||||||
WindowEvent::Resized(size)
|
// WindowEvent::Resized(size)
|
||||||
| WindowEvent::ScaleFactorChanged {
|
// | WindowEvent::ScaleFactorChanged {
|
||||||
new_inner_size: &mut size,
|
// new_inner_size: &mut size,
|
||||||
..
|
// ..
|
||||||
},
|
// },
|
||||||
|
WindowEvent::Resized(size),//ignoring scale factor changed for now because mutex bruh
|
||||||
..
|
..
|
||||||
} => {
|
} => {
|
||||||
// Once winit is fixed, the detection conditions here can be removed.
|
|
||||||
// https://github.com/rust-windowing/winit/issues/2876
|
|
||||||
let max_dimension = adapter.limits().max_texture_dimension_2d;
|
|
||||||
if size.width > max_dimension || size.height > max_dimension {
|
|
||||||
log::warn!(
|
|
||||||
"The resizing size {:?} exceeds the limit of {}.",
|
|
||||||
size,
|
|
||||||
max_dimension
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
log::info!("Resizing to {:?}", size);
|
log::info!("Resizing to {:?}", size);
|
||||||
config.width = size.width.max(1);
|
config.width = size.width.max(1);
|
||||||
config.height = size.height.max(1);
|
config.height = size.height.max(1);
|
||||||
example.resize(&config, &device, &queue);
|
example.resize(&config, &device, &queue);
|
||||||
surface.configure(&device, &config);
|
surface.configure(&device, &config);
|
||||||
}
|
}
|
||||||
}
|
event::Event::DeviceEvent {
|
||||||
|
event,
|
||||||
|
..
|
||||||
|
} => {
|
||||||
|
example.device_event(&window,event);
|
||||||
|
},
|
||||||
event::Event::WindowEvent { event, .. } => match event {
|
event::Event::WindowEvent { event, .. } => match event {
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
event:
|
||||||
event::KeyboardInput {
|
event::KeyEvent {
|
||||||
virtual_keycode: Some(event::VirtualKeyCode::Escape),
|
logical_key: winit::keyboard::Key::Named(winit::keyboard::NamedKey::Escape),
|
||||||
state: event::ElementState::Pressed,
|
state: event::ElementState::Pressed,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
..
|
..
|
||||||
}
|
}
|
||||||
| WindowEvent::CloseRequested => {
|
| WindowEvent::CloseRequested => {
|
||||||
*control_flow = ControlFlow::Exit;
|
elwt.exit();
|
||||||
}
|
}
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
WindowEvent::KeyboardInput {
|
WindowEvent::KeyboardInput {
|
||||||
input:
|
event:
|
||||||
event::KeyboardInput {
|
event::KeyEvent {
|
||||||
virtual_keycode: Some(event::VirtualKeyCode::Scroll),
|
logical_key: winit::keyboard::Key::Named(winit::keyboard::NamedKey::ScrollLock),
|
||||||
state: event::ElementState::Pressed,
|
state: event::ElementState::Pressed,
|
||||||
..
|
..
|
||||||
},
|
},
|
||||||
@ -367,18 +363,7 @@ fn start<E: Example>(
|
|||||||
} => {
|
} => {
|
||||||
println!("{:#?}", instance.generate_report());
|
println!("{:#?}", instance.generate_report());
|
||||||
}
|
}
|
||||||
_ => {
|
WindowEvent::RedrawRequested => {
|
||||||
example.update(&window,&device,&queue,event);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
event::Event::DeviceEvent {
|
|
||||||
event,
|
|
||||||
..
|
|
||||||
} => {
|
|
||||||
example.device_event(&window,event);
|
|
||||||
},
|
|
||||||
event::Event::RedrawRequested(_) => {
|
|
||||||
|
|
||||||
let frame = match surface.get_current_texture() {
|
let frame = match surface.get_current_texture() {
|
||||||
Ok(frame) => frame,
|
Ok(frame) => frame,
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
@ -412,9 +397,13 @@ fn start<E: Example>(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
_ => {
|
||||||
|
example.update(&window,&device,&queue,event);
|
||||||
|
}
|
||||||
|
},
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
});
|
}).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(not(target_arch = "wasm32"))]
|
#[cfg(not(target_arch = "wasm32"))]
|
||||||
|
36
src/main.rs
36
src/main.rs
@ -1098,15 +1098,15 @@ impl framework::Example for GlobalState {
|
|||||||
//recalculate pressed keys on focus
|
//recalculate pressed keys on focus
|
||||||
},
|
},
|
||||||
winit::event::WindowEvent::KeyboardInput {
|
winit::event::WindowEvent::KeyboardInput {
|
||||||
input:winit::event::KeyboardInput{state, virtual_keycode,..},
|
event:winit::event::KeyEvent{state, logical_key,..},
|
||||||
..
|
..
|
||||||
}=>{
|
}=>{
|
||||||
let s=match state {
|
let s=match state {
|
||||||
winit::event::ElementState::Pressed => true,
|
winit::event::ElementState::Pressed => true,
|
||||||
winit::event::ElementState::Released => false,
|
winit::event::ElementState::Released => false,
|
||||||
};
|
};
|
||||||
match virtual_keycode{
|
match logical_key{
|
||||||
Some(winit::event::VirtualKeyCode::Tab)=>{
|
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Tab)=>{
|
||||||
if s{
|
if s{
|
||||||
self.manual_mouse_lock=false;
|
self.manual_mouse_lock=false;
|
||||||
match window.set_cursor_position(winit::dpi::PhysicalPosition::new(self.graphics.camera.screen_size.x as f32/2.0, self.graphics.camera.screen_size.y as f32/2.0)){
|
match window.set_cursor_position(winit::dpi::PhysicalPosition::new(self.graphics.camera.screen_size.x as f32/2.0, self.graphics.camera.screen_size.y as f32/2.0)){
|
||||||
@ -1135,7 +1135,7 @@ impl framework::Example for GlobalState {
|
|||||||
}
|
}
|
||||||
window.set_cursor_visible(s);
|
window.set_cursor_visible(s);
|
||||||
},
|
},
|
||||||
Some(winit::event::VirtualKeyCode::F11)=>{
|
winit::keyboard::Key::Named(winit::keyboard::NamedKey::F11)=>{
|
||||||
if s{
|
if s{
|
||||||
if window.fullscreen().is_some(){
|
if window.fullscreen().is_some(){
|
||||||
window.set_fullscreen(None);
|
window.set_fullscreen(None);
|
||||||
@ -1144,7 +1144,7 @@ impl framework::Example for GlobalState {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(winit::event::VirtualKeyCode::Escape)=>{
|
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Escape)=>{
|
||||||
if s{
|
if s{
|
||||||
self.manual_mouse_lock=false;
|
self.manual_mouse_lock=false;
|
||||||
match window.set_cursor_grab(winit::window::CursorGrabMode::None){
|
match window.set_cursor_grab(winit::window::CursorGrabMode::None){
|
||||||
@ -1154,18 +1154,21 @@ impl framework::Example for GlobalState {
|
|||||||
window.set_cursor_visible(true);
|
window.set_cursor_visible(true);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Some(keycode)=>{
|
keycode=>{
|
||||||
if let Some(input_instruction)=match keycode {
|
if let Some(input_instruction)=match keycode {
|
||||||
winit::event::VirtualKeyCode::W => Some(InputInstruction::MoveForward(s)),
|
winit::keyboard::Key::Named(winit::keyboard::NamedKey::Space)=>Some(InputInstruction::Jump(s)),
|
||||||
winit::event::VirtualKeyCode::A => Some(InputInstruction::MoveLeft(s)),
|
winit::keyboard::Key::Character(c)=>match c.as_str(){
|
||||||
winit::event::VirtualKeyCode::S => Some(InputInstruction::MoveBack(s)),
|
"w"=>Some(InputInstruction::MoveForward(s)),
|
||||||
winit::event::VirtualKeyCode::D => Some(InputInstruction::MoveRight(s)),
|
"a"=>Some(InputInstruction::MoveLeft(s)),
|
||||||
winit::event::VirtualKeyCode::E => Some(InputInstruction::MoveUp(s)),
|
"s"=>Some(InputInstruction::MoveBack(s)),
|
||||||
winit::event::VirtualKeyCode::Q => Some(InputInstruction::MoveDown(s)),
|
"d"=>Some(InputInstruction::MoveRight(s)),
|
||||||
winit::event::VirtualKeyCode::Space => Some(InputInstruction::Jump(s)),
|
"e"=>Some(InputInstruction::MoveUp(s)),
|
||||||
winit::event::VirtualKeyCode::Z => Some(InputInstruction::Zoom(s)),
|
"q"=>Some(InputInstruction::MoveDown(s)),
|
||||||
winit::event::VirtualKeyCode::R => if s{Some(InputInstruction::Reset)}else{None},
|
"z"=>Some(InputInstruction::Zoom(s)),
|
||||||
_ => None,
|
"r"=>if s{Some(InputInstruction::Reset)}else{None},
|
||||||
|
_=>None,
|
||||||
|
}
|
||||||
|
_=>None,
|
||||||
}{
|
}{
|
||||||
self.physics_thread.send(TimedInstruction{
|
self.physics_thread.send(TimedInstruction{
|
||||||
time,
|
time,
|
||||||
@ -1173,7 +1176,6 @@ impl framework::Example for GlobalState {
|
|||||||
}).unwrap();
|
}).unwrap();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_=>(),
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
_=>(),
|
_=>(),
|
||||||
|
Loading…
Reference in New Issue
Block a user