Merge branch 'imbris/winit-update-v2' into 'master'

Update winit to 0.28

See merge request veloren/veloren!4088
This commit is contained in:
Imbris 2023-08-27 15:10:00 +00:00
commit de34726fa7
7 changed files with 306 additions and 498 deletions

View File

@ -48,6 +48,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Tweaked dungeons mobs and chests loot tables to be more balanced and rewarding
- Changed iron ore to iron ingots in the instruments' recipes
- Changed gold ore to gold ingots in the Brinstone armor set recipes
- Updated windowing library, wayland may work better.
### Removed
- Medium and large potions from all loot tables

705
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -157,6 +157,8 @@ clap = { version = "4.2", features = ["derive"]}
[patch.crates-io]
vek = { git = "https://github.com/yoanlcq/vek.git", rev = "84d5cb65841d46599a986c5477341bea4456be26" }
# patch winit to support older raw-window-handle that works with old wgpu
winit = { git = "https://github.com/Imberflur/winit.git", tag = "raw-window-handle-0.4-retro-support-v1" }
# patch wgpu so we can use wgpu-profiler crate
# wgpu = { git = "https://github.com/gfx-rs/wgpu.git", rev = "a92b8549a8e2cb9dac781bafc5ed32828f3caf46" }
wgpu = { git = "https://github.com/pythonesque/wgpu.git", rev = "179ea209374a92837cde252f1d9ee01f628cae08" }
@ -174,6 +176,9 @@ ntapi = { git = "https://github.com/MSxDOS/ntapi.git", rev = "9f56b149c9e2579673
# gfx-backend-dx11 = { git = "https://github.com/gfx-rs/gfx.git", rev = "e305dcca3557923a6a8810162d8dd09cb45a43a6" }
# gfx-backend-metal = { git = "https://github.com/gfx-rs/gfx.git", rev = "e305dcca3557923a6a8810162d8dd09cb45a43a6" }
# # Uncomment this to use a local fork of winit (for testing purposes)
# winit = { path = "../winit" }
# # Uncomment this to use a local fork of wgpu (for testing purposes)
# [patch.'https://github.com/gfx-rs/wgpu']
# wgpu-core = { path = "../wgpu/wgpu-core" }

View File

@ -56,7 +56,7 @@ i18n-helpers = {package = "veloren-voxygen-i18n-helpers", path = "i18n-helpers"}
voxygen-egui = {package = "veloren-voxygen-egui", path = "egui", optional = true }
# Graphics
winit = {version = "0.25.0", features = ["serde"]}
winit = {version = "0.28.6", features = ["serde"]}
wgpu = { version = "=0.8.0", features = ["trace", "cross"] }
wgpu-profiler = { git = "https://github.com/Imberflur/wgpu-profiler", tag = "wgpu-0.8" }
bytemuck = { version="1.4", features=["derive"] }
@ -71,16 +71,16 @@ cmake = "=0.1.45"
conrod_core = {git = "https://gitlab.com/veloren/conrod.git", branch="copypasta_0.7"}
conrod_winit = {git = "https://gitlab.com/veloren/conrod.git", branch="copypasta_0.7"}
euc = "0.5.0"
iced = {package = "iced_native", git = "https://github.com/Imberflur/iced", tag = "winit-0.25"}
iced_winit = {git = "https://github.com/Imberflur/iced", tag = "winit-0.25"}
window_clipboard = "0.2"
iced = {package = "iced_native", git = "https://github.com/Imberflur/iced", tag = "veloren-winit-0.28"}
iced_winit = {git = "https://github.com/Imberflur/iced", tag = "veloren-winit-0.28"}
window_clipboard = "0.3"
glyph_brush = "0.7.0"
keyboard-keynames = "0.1.2"
# https://gitlab.com/Frinksy/keyboard-keynames/-/merge_requests/8
keyboard-keynames = { git = "https://gitlab.com/Imbris/keyboard-keynames.git", tag = "veloren-winit-0.28" }
# EGUI
egui = {version = "0.12", optional = true }
egui_wgpu_backend = {git = "https://github.com/hasenbanck/egui_wgpu_backend.git", rev = "63a002c6a9b6c016e45806dd065864431caab621", optional = true }
egui_winit_platform = {version = "0.8", optional = true }
egui_winit_platform = { git = "https://github.com/Imberflur/egui_winit_platform.git", tag = "veloren-winit-0.28", optional = true }
# ECS
specs = { workspace = true, features = ["serde", "storage-event-control"] }
@ -104,10 +104,8 @@ backtrace = "0.3.40"
bincode = { workspace = true }
chrono = { workspace = true }
chumsky = "0.9"
cpal = "0.14"
crossbeam-utils = { workspace = true }
crossbeam-channel = { workspace = true }
# TODO: remove
directories-next = "2.0"
dot_vox = "5.1"
enum-iterator = "1.1.0"

View File

@ -12,7 +12,7 @@ be-dyn-lib = []
client = {package = "veloren-client", path = "../../client"}
common = {package = "veloren-common", path = "../../common"}
egui = "0.12"
egui_winit_platform = "0.8"
egui_winit_platform = { git = "https://github.com/Imberflur/egui_winit_platform.git", tag = "veloren-winit-0.28" }
lazy_static = { workspace = true }
common-dynlib = {package = "veloren-common-dynlib", path = "../../common/dynlib", optional = true}

View File

@ -1548,11 +1548,12 @@ impl<'a> Widget for Video<'a> {
let bit_depths: Vec<u16> = correct_res
.iter()
.filter(
|mode| match self.global_state.settings.graphics.fullscreen.refresh_rate {
Some(refresh_rate) => mode.refresh_rate() == refresh_rate,
|mode| match self.global_state.settings.graphics.fullscreen.refresh_rate_millihertz {
Some(rate) => mode.refresh_rate_millihertz() == rate,
None => true,
},
)
// TODO: why do we sort by this and then map to it?
.sorted_by_key(|mode| mode.bit_depth())
.map(|mode| mode.bit_depth())
.rev()
@ -1601,7 +1602,7 @@ impl<'a> Widget for Video<'a> {
}
// Refresh Rate
let refresh_rates: Vec<u16> = correct_res
let refresh_rates: Vec<u32> = correct_res
.into_iter()
.filter(
|mode| match self.global_state.settings.graphics.fullscreen.bit_depth {
@ -1609,8 +1610,9 @@ impl<'a> Widget for Video<'a> {
None => true,
},
)
.sorted_by_key(|mode| mode.refresh_rate())
.map(|mode| mode.refresh_rate())
// TODO: why do we sort by this and then map to it?
.sorted_by_key(|mode| mode.refresh_rate_millihertz())
.map(|mode| mode.refresh_rate_millihertz())
.rev()
.dedup()
.collect();
@ -1627,10 +1629,20 @@ impl<'a> Widget for Video<'a> {
once(String::from(
self.localized_strings.get_msg("common-automatic"),
))
.chain(refresh_rates.iter().map(|rate| format!("{}", rate)))
.chain(
refresh_rates
.iter()
.map(|&rate| format!("{:.1}", rate as f32 / 1000.0)),
)
.collect::<Vec<String>>()
.as_slice(),
match self.global_state.settings.graphics.fullscreen.refresh_rate {
match self
.global_state
.settings
.graphics
.fullscreen
.refresh_rate_millihertz
{
Some(refresh_rate) => refresh_rates
.iter()
.position(|rate| rate == &refresh_rate)
@ -1647,7 +1659,7 @@ impl<'a> Widget for Video<'a> {
.set(state.ids.refresh_rate, ui)
{
events.push(GraphicsChange::ChangeFullscreenMode(FullScreenSettings {
refresh_rate: if clicked == 0 {
refresh_rate_millihertz: if clicked == 0 {
None
} else {
Some(refresh_rates[clicked - 1])

View File

@ -1028,9 +1028,21 @@ impl Window {
pub fn is_cursor_grabbed(&self) -> bool { self.cursor_grabbed }
pub fn grab_cursor(&mut self, grab: bool) {
use winit::window::CursorGrabMode;
self.cursor_grabbed = grab;
self.window.set_cursor_visible(!grab);
let _ = self.window.set_cursor_grab(grab);
let res = if grab {
self.window
.set_cursor_grab(CursorGrabMode::Confined)
.or_else(|_e| self.window.set_cursor_grab(CursorGrabMode::Locked))
} else {
self.window.set_cursor_grab(CursorGrabMode::None)
};
if let Err(e) = res {
error!(?e, ?grab, "Failed to toggle cursor grab");
}
}
/// Moves mouse cursor to center of screen
@ -1073,7 +1085,7 @@ impl Window {
&self,
resolution: [u16; 2],
bit_depth: Option<u16>,
refresh_rate: Option<u16>,
refresh_rate_millihertz: Option<u32>,
correct_res: Option<Vec<VideoMode>>,
correct_depth: Option<Option<VideoMode>>,
correct_rate: Option<Option<VideoMode>>,
@ -1103,14 +1115,14 @@ impl Window {
.cloned()
});
match refresh_rate {
match refresh_rate_millihertz {
// A bit depth and a refresh rate is given
Some(rate) => {
// analogous to correct_res
let correct_rate = correct_rate.unwrap_or_else(|| {
correct_res
.iter()
.find(|mode| mode.refresh_rate() == rate)
.find(|mode| mode.refresh_rate_millihertz() == rate)
.cloned()
});
@ -1121,7 +1133,7 @@ impl Window {
correct_res
.iter()
.filter(|mode| mode.bit_depth() == depth)
.find(|mode| mode.refresh_rate() == rate)
.find(|mode| mode.refresh_rate_millihertz() == rate)
.cloned()
.or_else(|| {
if correct_depth.is_none() && correct_rate.is_none() {
@ -1166,14 +1178,14 @@ impl Window {
}
},
// No bit depth is given
None => match refresh_rate {
None => match refresh_rate_millihertz {
// No bit depth and a refresh rate is given
Some(rate) => {
// analogous to correct_res
let correct_rate = correct_rate.unwrap_or_else(|| {
correct_res
.iter()
.find(|mode| mode.refresh_rate() == rate)
.find(|mode| mode.refresh_rate_millihertz() == rate)
.cloned()
});
@ -1205,7 +1217,7 @@ impl Window {
.into_iter()
// Prefer bit depth over refresh rate
.sorted_by_key(|mode| mode.bit_depth())
.max_by_key(|mode| mode.refresh_rate()),
.max_by_key(|mode| mode.refresh_rate_millihertz()),
},
}
}
@ -1214,7 +1226,7 @@ impl Window {
&self,
resolution: [u16; 2],
bit_depth: Option<u16>,
refresh_rate: Option<u16>,
refresh_rate_millihertz: Option<u32>,
) -> Option<VideoMode> {
// (resolution, bit depth, refresh rate) represents a video mode
// spec: as specified
@ -1225,7 +1237,14 @@ impl Window {
// (spec, spec, max), (spec, max, spec)
// (spec, max, max)
// (max, max, max)
match self.select_video_mode_rec(resolution, bit_depth, refresh_rate, None, None, None) {
match self.select_video_mode_rec(
resolution,
bit_depth,
refresh_rate_millihertz,
None,
None,
None,
) {
Some(mode) => Some(mode),
// if there is no video mode with the specified resolution,
// fall back to the video mode with max resolution, bit depth and refresh rate
@ -1238,7 +1257,7 @@ impl Window {
let mode = monitor
.video_modes()
// Prefer bit depth over refresh rate
.sorted_by_key(|mode| mode.refresh_rate())
.sorted_by_key(|mode| mode.refresh_rate_millihertz())
.sorted_by_key(|mode| mode.bit_depth())
.max_by_key(|mode| mode.size().width);
@ -1263,7 +1282,7 @@ impl Window {
if let Some(video_mode) = self.select_video_mode(
fullscreen.resolution,
fullscreen.bit_depth,
fullscreen.refresh_rate,
fullscreen.refresh_rate_millihertz,
) {
winit::window::Fullscreen::Exclusive(video_mode)
} else {
@ -1411,7 +1430,7 @@ pub struct FullScreenSettings {
pub mode: FullscreenMode,
pub resolution: [u16; 2],
pub bit_depth: Option<u16>,
pub refresh_rate: Option<u16>,
pub refresh_rate_millihertz: Option<u32>,
}
impl Default for FullScreenSettings {
@ -1421,7 +1440,7 @@ impl Default for FullScreenSettings {
mode: FullscreenMode::Borderless,
resolution: [1920, 1080],
bit_depth: None,
refresh_rate: None,
refresh_rate_millihertz: None,
}
}
}