mirror of
https://github.com/exoticorn/microw8.git
synced 2026-01-20 11:16:42 +01:00
revert to winit 0.28 and wgpu 0.17 to fix fps on windows
This commit is contained in:
754
Cargo.lock
generated
754
Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
911
uw8-window/Cargo.lock
generated
911
uw8-window/Cargo.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -6,11 +6,11 @@ edition = "2021"
|
|||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
winit = "0.29.15"
|
|
||||||
env_logger = "0.11.3"
|
env_logger = "0.11.3"
|
||||||
|
winit = "0.28.6"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
pico-args = "0.5"
|
pico-args = "0.5"
|
||||||
wgpu = "0.19.3"
|
wgpu = "0.17"
|
||||||
pollster = "0.3.0"
|
pollster = "0.3.0"
|
||||||
bytemuck = { version = "1.15", features = [ "derive" ] }
|
bytemuck = { version = "1.15", features = [ "derive" ] }
|
||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
|
|||||||
@@ -1,16 +1,16 @@
|
|||||||
use crate::{Input, WindowConfig, WindowImpl};
|
use crate::{Input, WindowConfig, WindowImpl};
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use std::{sync::Arc, time::Instant};
|
use std::time::Instant;
|
||||||
|
|
||||||
use winit::{
|
use winit::{
|
||||||
dpi::PhysicalSize,
|
dpi::PhysicalSize,
|
||||||
event::{Event, WindowEvent},
|
event::{Event, VirtualKeyCode, WindowEvent},
|
||||||
event_loop::{ControlFlow, EventLoop},
|
event_loop::{ControlFlow, EventLoop},
|
||||||
keyboard::{Key, KeyCode, NamedKey, PhysicalKey},
|
|
||||||
platform::pump_events::{EventLoopExtPumpEvents, PumpStatus},
|
|
||||||
window::{Fullscreen, WindowBuilder},
|
window::{Fullscreen, WindowBuilder},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use winit::platform::run_return::EventLoopExtRunReturn;
|
||||||
|
|
||||||
mod crt;
|
mod crt;
|
||||||
mod fast_crt;
|
mod fast_crt;
|
||||||
mod square;
|
mod square;
|
||||||
@@ -21,7 +21,7 @@ use square::SquareFilter;
|
|||||||
|
|
||||||
pub struct Window {
|
pub struct Window {
|
||||||
_instance: wgpu::Instance,
|
_instance: wgpu::Instance,
|
||||||
surface: wgpu::Surface<'static>,
|
surface: wgpu::Surface,
|
||||||
_adapter: wgpu::Adapter,
|
_adapter: wgpu::Adapter,
|
||||||
device: wgpu::Device,
|
device: wgpu::Device,
|
||||||
queue: wgpu::Queue,
|
queue: wgpu::Queue,
|
||||||
@@ -29,7 +29,7 @@ pub struct Window {
|
|||||||
surface_config: wgpu::SurfaceConfiguration,
|
surface_config: wgpu::SurfaceConfiguration,
|
||||||
filter: Box<dyn Filter>,
|
filter: Box<dyn Filter>,
|
||||||
event_loop: EventLoop<()>,
|
event_loop: EventLoop<()>,
|
||||||
window: Arc<winit::window::Window>,
|
window: winit::window::Window,
|
||||||
gamepads: [u8; 4],
|
gamepads: [u8; 4],
|
||||||
next_frame: Instant,
|
next_frame: Instant,
|
||||||
is_fullscreen: bool,
|
is_fullscreen: bool,
|
||||||
@@ -39,7 +39,7 @@ pub struct Window {
|
|||||||
impl Window {
|
impl Window {
|
||||||
pub fn new(window_config: WindowConfig) -> Result<Window> {
|
pub fn new(window_config: WindowConfig) -> Result<Window> {
|
||||||
async fn create(window_config: WindowConfig) -> Result<Window> {
|
async fn create(window_config: WindowConfig) -> Result<Window> {
|
||||||
let event_loop = EventLoop::new()?;
|
let event_loop = EventLoop::new();
|
||||||
let window = WindowBuilder::new()
|
let window = WindowBuilder::new()
|
||||||
.with_inner_size(PhysicalSize::new(
|
.with_inner_size(PhysicalSize::new(
|
||||||
(320. * window_config.scale).round() as u32,
|
(320. * window_config.scale).round() as u32,
|
||||||
@@ -56,10 +56,8 @@ impl Window {
|
|||||||
|
|
||||||
window.set_cursor_visible(false);
|
window.set_cursor_visible(false);
|
||||||
|
|
||||||
let window = Arc::new(window);
|
|
||||||
|
|
||||||
let instance = wgpu::Instance::new(Default::default());
|
let instance = wgpu::Instance::new(Default::default());
|
||||||
let surface = instance.create_surface(window.clone())?;
|
let surface = unsafe { instance.create_surface(&window) }?;
|
||||||
let adapter = instance
|
let adapter = instance
|
||||||
.request_adapter(&wgpu::RequestAdapterOptions {
|
.request_adapter(&wgpu::RequestAdapterOptions {
|
||||||
power_preference: wgpu::PowerPreference::LowPower,
|
power_preference: wgpu::PowerPreference::LowPower,
|
||||||
@@ -121,11 +119,8 @@ impl Window {
|
|||||||
impl WindowImpl for Window {
|
impl WindowImpl for Window {
|
||||||
fn begin_frame(&mut self) -> Input {
|
fn begin_frame(&mut self) -> Input {
|
||||||
let mut reset = false;
|
let mut reset = false;
|
||||||
self.event_loop
|
self.event_loop.run_return(|event, _, control_flow| {
|
||||||
.set_control_flow(ControlFlow::WaitUntil(self.next_frame));
|
*control_flow = ControlFlow::WaitUntil(self.next_frame);
|
||||||
while self.is_open {
|
|
||||||
let timeout = self.next_frame.saturating_duration_since(Instant::now());
|
|
||||||
let status = self.event_loop.pump_events(Some(timeout), |event, elwt| {
|
|
||||||
let mut new_filter = None;
|
let mut new_filter = None;
|
||||||
match event {
|
match event {
|
||||||
Event::WindowEvent { event, .. } => match event {
|
Event::WindowEvent { event, .. } => match event {
|
||||||
@@ -136,31 +131,32 @@ impl WindowImpl for Window {
|
|||||||
self.filter.resize(&self.queue, new_size);
|
self.filter.resize(&self.queue, new_size);
|
||||||
}
|
}
|
||||||
WindowEvent::CloseRequested => {
|
WindowEvent::CloseRequested => {
|
||||||
elwt.exit();
|
self.is_open = false;
|
||||||
|
*control_flow = ControlFlow::Exit;
|
||||||
}
|
}
|
||||||
WindowEvent::KeyboardInput { event, .. } => {
|
WindowEvent::KeyboardInput { input, .. } => {
|
||||||
fn gamepad_button(input: &winit::event::KeyEvent) -> u8 {
|
fn gamepad_button(input: &winit::event::KeyboardInput) -> u8 {
|
||||||
match input.physical_key {
|
match input.scancode {
|
||||||
PhysicalKey::Code(KeyCode::KeyZ) => 16,
|
44 => 16,
|
||||||
PhysicalKey::Code(KeyCode::KeyX) => 32,
|
45 => 32,
|
||||||
PhysicalKey::Code(KeyCode::KeyA) => 64,
|
30 => 64,
|
||||||
PhysicalKey::Code(KeyCode::KeyS) => 128,
|
31 => 128,
|
||||||
_ => match input.logical_key {
|
_ => match input.virtual_keycode {
|
||||||
Key::Named(NamedKey::ArrowUp) => 1,
|
Some(VirtualKeyCode::Up) => 1,
|
||||||
Key::Named(NamedKey::ArrowDown) => 2,
|
Some(VirtualKeyCode::Down) => 2,
|
||||||
Key::Named(NamedKey::ArrowLeft) => 4,
|
Some(VirtualKeyCode::Left) => 4,
|
||||||
Key::Named(NamedKey::ArrowRight) => 8,
|
Some(VirtualKeyCode::Right) => 8,
|
||||||
_ => 0,
|
_ => 0,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if event.state == winit::event::ElementState::Pressed {
|
if input.state == winit::event::ElementState::Pressed {
|
||||||
match event.logical_key {
|
match input.virtual_keycode {
|
||||||
Key::Named(NamedKey::Escape) => {
|
Some(VirtualKeyCode::Escape) => {
|
||||||
elwt.exit();
|
self.is_open = false;
|
||||||
|
*control_flow = ControlFlow::Exit;
|
||||||
}
|
}
|
||||||
Key::Character(ref c) => match c.as_str() {
|
Some(VirtualKeyCode::F) => {
|
||||||
"f" => {
|
|
||||||
let fullscreen = if self.window.fullscreen().is_some() {
|
let fullscreen = if self.window.fullscreen().is_some() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
@@ -169,24 +165,30 @@ impl WindowImpl for Window {
|
|||||||
self.is_fullscreen = fullscreen.is_some();
|
self.is_fullscreen = fullscreen.is_some();
|
||||||
self.window.set_fullscreen(fullscreen);
|
self.window.set_fullscreen(fullscreen);
|
||||||
}
|
}
|
||||||
"r" => reset = true,
|
Some(VirtualKeyCode::R) => reset = true,
|
||||||
"1" => new_filter = Some(1),
|
Some(VirtualKeyCode::Key1) => new_filter = Some(1),
|
||||||
"2" => new_filter = Some(2),
|
Some(VirtualKeyCode::Key2) => new_filter = Some(2),
|
||||||
"3" => new_filter = Some(3),
|
Some(VirtualKeyCode::Key3) => new_filter = Some(3),
|
||||||
"4" => new_filter = Some(4),
|
Some(VirtualKeyCode::Key4) => new_filter = Some(4),
|
||||||
"5" => new_filter = Some(5),
|
Some(VirtualKeyCode::Key5) => new_filter = Some(5),
|
||||||
_ => (),
|
|
||||||
},
|
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
|
|
||||||
self.gamepads[0] |= gamepad_button(&event);
|
self.gamepads[0] |= gamepad_button(&input);
|
||||||
} else {
|
} else {
|
||||||
self.gamepads[0] &= !gamepad_button(&event);
|
self.gamepads[0] &= !gamepad_button(&input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
},
|
},
|
||||||
|
Event::RedrawEventsCleared => {
|
||||||
|
if Instant::now() >= self.next_frame
|
||||||
|
// workaround needed on Wayland until the next winit release
|
||||||
|
&& self.window.fullscreen().is_some() == self.is_fullscreen
|
||||||
|
{
|
||||||
|
*control_flow = ControlFlow::Exit
|
||||||
|
}
|
||||||
|
}
|
||||||
_ => (),
|
_ => (),
|
||||||
}
|
}
|
||||||
if let Some(new_filter) = new_filter {
|
if let Some(new_filter) = new_filter {
|
||||||
@@ -199,15 +201,6 @@ impl WindowImpl for Window {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
match status {
|
|
||||||
PumpStatus::Exit(_) => self.is_open = false,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
if Instant::now() >= self.next_frame {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Input {
|
Input {
|
||||||
gamepads: self.gamepads,
|
gamepads: self.gamepads,
|
||||||
reset,
|
reset,
|
||||||
@@ -243,12 +236,10 @@ impl WindowImpl for Window {
|
|||||||
b: 0.0,
|
b: 0.0,
|
||||||
a: 1.0,
|
a: 1.0,
|
||||||
}),
|
}),
|
||||||
store: wgpu::StoreOp::Store,
|
store: true,
|
||||||
},
|
},
|
||||||
})],
|
})],
|
||||||
depth_stencil_attachment: None,
|
depth_stencil_attachment: None,
|
||||||
timestamp_writes: None,
|
|
||||||
occlusion_query_set: None,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
self.filter.render(&mut render_pass);
|
self.filter.render(&mut render_pass);
|
||||||
@@ -550,12 +541,10 @@ impl PaletteScreenMode {
|
|||||||
resolve_target: None,
|
resolve_target: None,
|
||||||
ops: wgpu::Operations {
|
ops: wgpu::Operations {
|
||||||
load: wgpu::LoadOp::Load,
|
load: wgpu::LoadOp::Load,
|
||||||
store: wgpu::StoreOp::Store,
|
store: true,
|
||||||
},
|
},
|
||||||
})],
|
})],
|
||||||
depth_stencil_attachment: None,
|
depth_stencil_attachment: None,
|
||||||
timestamp_writes: None,
|
|
||||||
occlusion_query_set: None,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
render_pass.set_pipeline(&self.pipeline);
|
render_pass.set_pipeline(&self.pipeline);
|
||||||
|
|||||||
Reference in New Issue
Block a user