Skip to content

Commit

Permalink
player/src/bin/play.rs: fix winit feature code
Browse files Browse the repository at this point in the history
  • Loading branch information
TornaxO7 committed Oct 25, 2023
1 parent ec16a2f commit 1a3388d
Showing 1 changed file with 26 additions and 29 deletions.
55 changes: 26 additions & 29 deletions player/src/bin/play.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
fn main() {
use player::{GlobalPlay as _, IdentityPassThroughFactory};
use wgc::{device::trace, gfx_select};
use winit::{event::KeyEvent, keyboard::{Key, NamedKey}};

use std::{
fs,
path::{Path, PathBuf},
};

#[cfg(feature = "winit")]
use raw_window_handle::{HasRawDisplayHandle, HasRawWindowHandle};
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
#[cfg(feature = "winit")]
use winit::{event_loop::EventLoop, window::WindowBuilder};

Expand All @@ -35,7 +36,7 @@ fn main() {
#[cfg(feature = "winit")]
let event_loop = {
log::info!("Creating a window");
EventLoop::new()
EventLoop::new().unwrap()
};
#[cfg(feature = "winit")]
let window = WindowBuilder::new()
Expand All @@ -53,8 +54,8 @@ fn main() {

#[cfg(feature = "winit")]
let surface = global.instance_create_surface(
window.raw_display_handle(),
window.raw_window_handle(),
window.display_handle().unwrap().into(),
window.window_handle().unwrap().into(),
wgc::id::TypedId::zip(0, 1, wgt::Backend::Empty),
);

Expand Down Expand Up @@ -110,32 +111,32 @@ fn main() {
#[cfg(feature = "winit")]
{
use winit::{
event::{ElementState, Event, KeyboardInput, VirtualKeyCode, WindowEvent},
event::{ElementState, Event, WindowEvent},
event_loop::ControlFlow,
};

let mut resize_config = None;
let mut frame_count = 0;
let mut done = false;
event_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
event_loop.run(move |event, target| {
target.set_control_flow(ControlFlow::Poll);

match event {
Event::MainEventsCleared => {
window.request_redraw();
}
Event::RedrawRequested(_) if resize_config.is_none() => loop {
Event::WindowEvent { event, .. } => match event {
WindowEvent::RedrawRequested if resize_config.is_none() => {

match actions.pop() {
Some(trace::Action::ConfigureSurface(_device_id, config)) => {
log::info!("Configuring the surface");
let current_size: (u32, u32) = window.inner_size().into();
let size = (config.width, config.height);
if current_size != size {
window.set_inner_size(winit::dpi::PhysicalSize::new(
let _ = window.request_inner_size(winit::dpi::PhysicalSize::new(
config.width,
config.height,
));
resize_config = Some(config);
break;
target.exit();
} else {
let error = gfx_select!(device => global.surface_configure(surface, device, &config));
if let Some(e) = error {
Expand All @@ -147,12 +148,12 @@ fn main() {
frame_count += 1;
log::debug!("Presenting frame {}", frame_count);
gfx_select!(device => global.surface_present(id)).unwrap();
break;
target.exit();
}
Some(trace::Action::DiscardSurfaceTexture(id)) => {
log::debug!("Discarding frame {}", frame_count);
gfx_select!(device => global.surface_texture_discard(id)).unwrap();
break;
target.exit();
}
Some(action) => {
gfx_select!(device => global.process(device, action, &dir, &mut command_buffer_id_manager));
Expand All @@ -162,11 +163,10 @@ fn main() {
println!("Finished the end at frame {}", frame_count);
done = true;
}
break;
target.exit();
}
}
},
Event::WindowEvent { event, .. } => match event {
},
WindowEvent::Resized(_) => {
if let Some(config) = resize_config.take() {
let error = gfx_select!(device => global.surface_configure(surface, device, &config));
Expand All @@ -176,26 +176,23 @@ fn main() {
}
}
WindowEvent::KeyboardInput {
input:
KeyboardInput {
virtual_keycode: Some(VirtualKeyCode::Escape),
state: ElementState::Pressed,
..
},
event: KeyEvent {
logical_key: Key::Named(NamedKey::Escape),
state: ElementState::Pressed,
..
},
..
}
| WindowEvent::CloseRequested => {
*control_flow = ControlFlow::Exit;
}
| WindowEvent::CloseRequested => target.exit(),
_ => {}
},
Event::LoopDestroyed => {
Event::LoopExiting => {
log::info!("Closing");
gfx_select!(device => global.device_poll(device, wgt::Maintain::Wait)).unwrap();
}
_ => {}
}
});
}).unwrap();
}
}

Expand Down

0 comments on commit 1a3388d

Please sign in to comment.