This commit is contained in:
Ben Wallis 2021-05-04 09:14:08 +01:00
parent f574015c39
commit 4d1da112c1
12 changed files with 625 additions and 53 deletions

407
Cargo.lock generated
View File

@ -254,6 +254,12 @@ version = "0.3.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c9ff149ed9780025acfdb36862d35b28856bb693ceb451259a7164442f22fdc3"
[[package]]
name = "atomic_refcell"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "681b971236e0f76b20fcafca0236b8718c9186ee778d67cd78bd5f28fd85427f"
[[package]]
name = "atomicwrites"
version = "0.3.0"
@ -1223,6 +1229,16 @@ dependencies = [
"sct",
]
[[package]]
name = "d3d12"
version = "0.3.2"
source = "git+https://github.com/gfx-rs/d3d12-rs?rev=be19a243b86e0bafb9937d661fc8eabb3e42b44e#be19a243b86e0bafb9937d661fc8eabb3e42b44e"
dependencies = [
"bitflags",
"libloading 0.7.0",
"winapi 0.3.9",
]
[[package]]
name = "d3d12"
version = "0.4.0"
@ -1434,12 +1450,56 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650"
[[package]]
name = "egui"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2d7d6535c3ecdc8627a72c1c52d052d66cd9f71c238428690cc46bef9d1f2bce"
dependencies = [
"epaint",
]
[[package]]
name = "egui_demo_lib"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7407327572f2c3b7a8c20c7b591d9e608683b24311c546eaf46951789847ded"
dependencies = [
"egui",
"epi",
]
[[package]]
name = "egui_wgpu_backend"
version = "0.7.0"
dependencies = [
"bytemuck",
"epi",
"wgpu 0.8.0 (git+https://github.com/gfx-rs/wgpu-rs?rev=69be1ff88a073b3a7f9470044834e75c22f7b4ad)",
]
[[package]]
name = "egui_winit_platform"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "abb2766d3864d7391e34b9aa78caaa01c162baf1481523a371914e3f42144d84"
dependencies = [
"egui",
"winit",
]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]]
name = "emath"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4ed72c14666517e5c0198490864adea871081abe4f5523af8c3f4f56595142e"
[[package]]
name = "encoding_rs"
version = "0.8.28"
@ -1496,6 +1556,28 @@ dependencies = [
"syn 1.0.72",
]
[[package]]
name = "epaint"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2a19eff631454edbe5abe4693be00be0c1ea9832d727dc385c16841caa2d0162"
dependencies = [
"ahash 0.7.2",
"atomic_refcell",
"emath",
"ordered-float 2.1.1",
"rusttype 0.9.2",
]
[[package]]
name = "epi"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c2242aee03bc64fd16d58866e18c0f210004b95963bef30820747d18b9f5d627"
dependencies = [
"egui",
]
[[package]]
name = "error-code"
version = "2.0.2"
@ -1876,16 +1958,47 @@ dependencies = [
"wasi 0.10.2+wasi-snapshot-preview1",
]
[[package]]
name = "gfx-auxil"
version = "0.8.0"
source = "git+https://github.com/gfx-rs/gfx?rev=32684a7da923cfd661fe4d3003f4275270e9c40d#32684a7da923cfd661fe4d3003f4275270e9c40d"
dependencies = [
"fxhash",
"gfx-hal 0.7.0",
"spirv_cross",
]
[[package]]
name = "gfx-auxil"
version = "0.9.0"
source = "git+https://github.com/gfx-rs/gfx?rev=27a1dae3796d33d23812f2bb8c7e3b5aea18b521#27a1dae3796d33d23812f2bb8c7e3b5aea18b521"
dependencies = [
"fxhash",
"gfx-hal",
"gfx-hal 0.8.0",
"spirv_cross",
]
[[package]]
name = "gfx-backend-dx11"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=32684a7da923cfd661fe4d3003f4275270e9c40d#32684a7da923cfd661fe4d3003f4275270e9c40d"
dependencies = [
"arrayvec",
"bitflags",
"gfx-auxil 0.8.0",
"gfx-hal 0.7.0",
"libloading 0.7.0",
"log",
"parking_lot 0.11.1",
"range-alloc 0.1.2 (git+https://github.com/gfx-rs/gfx?rev=32684a7da923cfd661fe4d3003f4275270e9c40d)",
"raw-window-handle",
"smallvec",
"spirv_cross",
"thunderdome 0.3.0",
"winapi 0.3.9",
"wio",
]
[[package]]
name = "gfx-backend-dx11"
version = "0.8.0"
@ -1893,20 +2006,41 @@ source = "git+https://github.com/gfx-rs/gfx?rev=27a1dae3796d33d23812f2bb8c7e3b5a
dependencies = [
"arrayvec",
"bitflags",
"gfx-auxil",
"gfx-hal",
"gfx-auxil 0.9.0",
"gfx-hal 0.8.0",
"libloading 0.7.0",
"log",
"parking_lot 0.11.1",
"range-alloc",
"range-alloc 0.1.2 (git+https://github.com/gfx-rs/gfx?rev=27a1dae3796d33d23812f2bb8c7e3b5aea18b521)",
"raw-window-handle",
"smallvec",
"spirv_cross",
"thunderdome",
"thunderdome 0.4.1",
"winapi 0.3.9",
"wio",
]
[[package]]
name = "gfx-backend-dx12"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=32684a7da923cfd661fe4d3003f4275270e9c40d#32684a7da923cfd661fe4d3003f4275270e9c40d"
dependencies = [
"arrayvec",
"bit-set",
"bitflags",
"d3d12 0.3.2",
"gfx-auxil 0.8.0",
"gfx-hal 0.7.0",
"log",
"parking_lot 0.11.1",
"range-alloc 0.1.2 (git+https://github.com/gfx-rs/gfx?rev=32684a7da923cfd661fe4d3003f4275270e9c40d)",
"raw-window-handle",
"smallvec",
"spirv_cross",
"thunderdome 0.3.0",
"winapi 0.3.9",
]
[[package]]
name = "gfx-backend-dx12"
version = "0.8.0"
@ -1915,29 +2049,60 @@ dependencies = [
"arrayvec",
"bit-set",
"bitflags",
"d3d12",
"gfx-auxil",
"gfx-hal",
"d3d12 0.4.0",
"gfx-auxil 0.9.0",
"gfx-hal 0.8.0",
"log",
"parking_lot 0.11.1",
"range-alloc",
"range-alloc 0.1.2 (git+https://github.com/gfx-rs/gfx?rev=27a1dae3796d33d23812f2bb8c7e3b5aea18b521)",
"raw-window-handle",
"smallvec",
"spirv_cross",
"thunderdome",
"thunderdome 0.4.1",
"winapi 0.3.9",
]
[[package]]
name = "gfx-backend-empty"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=32684a7da923cfd661fe4d3003f4275270e9c40d#32684a7da923cfd661fe4d3003f4275270e9c40d"
dependencies = [
"gfx-hal 0.7.0",
"log",
"raw-window-handle",
]
[[package]]
name = "gfx-backend-empty"
version = "0.8.0"
source = "git+https://github.com/gfx-rs/gfx?rev=27a1dae3796d33d23812f2bb8c7e3b5aea18b521#27a1dae3796d33d23812f2bb8c7e3b5aea18b521"
dependencies = [
"gfx-hal",
"gfx-hal 0.8.0",
"log",
"raw-window-handle",
]
[[package]]
name = "gfx-backend-gl"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=32684a7da923cfd661fe4d3003f4275270e9c40d#32684a7da923cfd661fe4d3003f4275270e9c40d"
dependencies = [
"arrayvec",
"bitflags",
"fxhash",
"gfx-hal 0.7.0",
"glow 0.7.2",
"js-sys",
"khronos-egl",
"libloading 0.7.0",
"log",
"naga 0.3.1",
"parking_lot 0.11.1",
"raw-window-handle",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "gfx-backend-gl"
version = "0.8.1"
@ -1946,14 +2111,14 @@ dependencies = [
"arrayvec",
"bitflags",
"fxhash",
"gfx-auxil",
"gfx-hal",
"glow",
"gfx-auxil 0.9.0",
"gfx-hal 0.8.0",
"glow 0.9.0",
"js-sys",
"khronos-egl",
"libloading 0.7.0",
"log",
"naga",
"naga 0.4.0",
"parking_lot 0.11.1",
"raw-window-handle",
"spirv_cross",
@ -1961,6 +2126,30 @@ dependencies = [
"web-sys",
]
[[package]]
name = "gfx-backend-metal"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=32684a7da923cfd661fe4d3003f4275270e9c40d#32684a7da923cfd661fe4d3003f4275270e9c40d"
dependencies = [
"arrayvec",
"bitflags",
"block",
"cocoa-foundation",
"copyless",
"foreign-types",
"fxhash",
"gfx-hal 0.7.0",
"log",
"metal 0.21.0",
"naga 0.3.1",
"objc",
"parking_lot 0.11.1",
"profiling",
"range-alloc 0.1.2 (git+https://github.com/gfx-rs/gfx?rev=32684a7da923cfd661fe4d3003f4275270e9c40d)",
"raw-window-handle",
"storage-map",
]
[[package]]
name = "gfx-backend-metal"
version = "0.8.1"
@ -1973,20 +2162,40 @@ dependencies = [
"copyless",
"foreign-types",
"fxhash",
"gfx-auxil",
"gfx-hal",
"gfx-auxil 0.9.0",
"gfx-hal 0.8.0",
"log",
"metal",
"naga",
"metal 0.22.0",
"naga 0.4.0",
"objc",
"parking_lot 0.11.1",
"profiling",
"range-alloc",
"range-alloc 0.1.2 (git+https://github.com/gfx-rs/gfx?rev=27a1dae3796d33d23812f2bb8c7e3b5aea18b521)",
"raw-window-handle",
"spirv_cross",
"storage-map",
]
[[package]]
name = "gfx-backend-vulkan"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=32684a7da923cfd661fe4d3003f4275270e9c40d#32684a7da923cfd661fe4d3003f4275270e9c40d"
dependencies = [
"arrayvec",
"ash",
"byteorder",
"core-graphics-types",
"gfx-hal 0.7.0",
"inplace_it",
"log",
"naga 0.3.1",
"objc",
"parking_lot 0.11.1",
"raw-window-handle",
"smallvec",
"winapi 0.3.9",
]
[[package]]
name = "gfx-backend-vulkan"
version = "0.8.0"
@ -1996,11 +2205,11 @@ dependencies = [
"ash",
"byteorder",
"core-graphics-types",
"gfx-hal",
"gfx-hal 0.8.0",
"inplace_it",
"libloading 0.7.0",
"log",
"naga",
"naga 0.4.0",
"objc",
"parking_lot 0.11.1",
"raw-window-handle",
@ -2009,13 +2218,24 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "gfx-hal"
version = "0.7.0"
source = "git+https://github.com/gfx-rs/gfx?rev=32684a7da923cfd661fe4d3003f4275270e9c40d#32684a7da923cfd661fe4d3003f4275270e9c40d"
dependencies = [
"bitflags",
"naga 0.3.1",
"raw-window-handle",
"thiserror",
]
[[package]]
name = "gfx-hal"
version = "0.8.0"
source = "git+https://github.com/gfx-rs/gfx?rev=27a1dae3796d33d23812f2bb8c7e3b5aea18b521#27a1dae3796d33d23812f2bb8c7e3b5aea18b521"
dependencies = [
"bitflags",
"naga",
"naga 0.4.0",
"raw-window-handle",
"thiserror",
]
@ -2099,6 +2319,18 @@ version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
[[package]]
name = "glow"
version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "072136d2c3783f3a92f131acb227bc806d3886278e2a4dc1e9990ec89ef9e70b"
dependencies = [
"js-sys",
"slotmap 0.4.0",
"wasm-bindgen",
"web-sys",
]
[[package]]
name = "glow"
version = "0.9.0"
@ -2928,6 +3160,19 @@ dependencies = [
"autocfg",
]
[[package]]
name = "metal"
version = "0.21.0"
source = "git+https://github.com/gfx-rs/metal-rs?rev=78f632d194c7c16d18b71d7373c4080847d110b0#78f632d194c7c16d18b71d7373c4080847d110b0"
dependencies = [
"bitflags",
"block",
"cocoa-foundation",
"foreign-types",
"log",
"objc",
]
[[package]]
name = "metal"
version = "0.22.0"
@ -3057,6 +3302,22 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0debeb9fcf88823ea64d64e4a815ab1643f33127d995978e099942ce38f25238"
[[package]]
name = "naga"
version = "0.3.1"
source = "git+https://github.com/gfx-rs/naga?tag=gfx-23#4a5ff9a0538510ff3c3efa171941bfb44fc1be9c"
dependencies = [
"bit-set",
"bitflags",
"codespan-reporting",
"fxhash",
"log",
"num-traits",
"petgraph 0.5.1",
"spirv_headers",
"thiserror",
]
[[package]]
name = "naga"
version = "0.4.0"
@ -4170,6 +4431,11 @@ name = "range-alloc"
version = "0.1.2"
source = "git+https://github.com/gfx-rs/gfx?rev=27a1dae3796d33d23812f2bb8c7e3b5aea18b521#27a1dae3796d33d23812f2bb8c7e3b5aea18b521"
[[package]]
name = "range-alloc"
version = "0.1.2"
source = "git+https://github.com/gfx-rs/gfx?rev=32684a7da923cfd661fe4d3003f4275270e9c40d#32684a7da923cfd661fe4d3003f4275270e9c40d"
[[package]]
name = "raw-window-handle"
version = "0.3.3"
@ -5268,6 +5534,12 @@ dependencies = [
"once_cell",
]
[[package]]
name = "thunderdome"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7572415bd688d401c52f6e36f4c8e805b9ae1622619303b9fa835d531db0acae"
[[package]]
name = "thunderdome"
version = "0.4.1"
@ -6028,7 +6300,12 @@ dependencies = [
"directories-next",
"dispatch 0.1.4",
"dot_vox",
"egui",
"egui_demo_lib",
"egui_wgpu_backend",
"egui_winit_platform",
"enum-iterator",
"epi",
"euc",
"futures-executor",
"gilrs",
@ -6072,7 +6349,7 @@ dependencies = [
"veloren-server",
"veloren-voxygen-anim",
"veloren-world",
"wgpu",
"wgpu 0.8.0 (git+https://github.com/gfx-rs/wgpu-rs.git?rev=7486bdad64bb5d17b709ecccb41e063469efff88)",
"wgpu-profiler",
"window_clipboard 0.2.0",
"winit",
@ -6646,6 +6923,25 @@ dependencies = [
"winapi 0.3.9",
]
[[package]]
name = "wgpu"
version = "0.8.0"
source = "git+https://github.com/gfx-rs/wgpu-rs?rev=69be1ff88a073b3a7f9470044834e75c22f7b4ad#69be1ff88a073b3a7f9470044834e75c22f7b4ad"
dependencies = [
"arrayvec",
"js-sys",
"log",
"naga 0.3.1",
"parking_lot 0.11.1",
"raw-window-handle",
"smallvec",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"wgpu-core 0.8.0 (git+https://github.com/gfx-rs/wgpu?rev=e5ddb94be0221b0f53a8f43adfb15458daebfd7c)",
"wgpu-types 0.8.0 (git+https://github.com/gfx-rs/wgpu?rev=e5ddb94be0221b0f53a8f43adfb15458daebfd7c)",
]
[[package]]
name = "wgpu"
version = "0.8.0"
@ -6654,7 +6950,7 @@ dependencies = [
"arrayvec",
"js-sys",
"log",
"naga",
"naga 0.4.0",
"parking_lot 0.11.1",
"raw-window-handle",
"serde",
@ -6662,8 +6958,8 @@ dependencies = [
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"wgpu-core",
"wgpu-types",
"wgpu-core 0.8.0 (git+https://github.com/gfx-rs/wgpu?rev=53eab747a32414232be45d47cae8a43a369395d0)",
"wgpu-types 0.8.0 (git+https://github.com/gfx-rs/wgpu?rev=53eab747a32414232be45d47cae8a43a369395d0)",
]
[[package]]
@ -6676,17 +6972,17 @@ dependencies = [
"cfg_aliases",
"copyless",
"fxhash",
"gfx-backend-dx11",
"gfx-backend-dx12",
"gfx-backend-empty",
"gfx-backend-gl",
"gfx-backend-metal",
"gfx-backend-vulkan",
"gfx-hal",
"gfx-backend-dx11 0.8.0",
"gfx-backend-dx12 0.8.0",
"gfx-backend-empty 0.8.0",
"gfx-backend-gl 0.8.1",
"gfx-backend-metal 0.8.1",
"gfx-backend-vulkan 0.8.0",
"gfx-hal 0.8.0",
"gpu-alloc",
"gpu-descriptor",
"log",
"naga",
"naga 0.4.0",
"parking_lot 0.11.1",
"profiling",
"raw-window-handle",
@ -6694,7 +6990,36 @@ dependencies = [
"serde",
"smallvec",
"thiserror",
"wgpu-types",
"wgpu-types 0.8.0 (git+https://github.com/gfx-rs/wgpu?rev=53eab747a32414232be45d47cae8a43a369395d0)",
]
[[package]]
name = "wgpu-core"
version = "0.8.0"
source = "git+https://github.com/gfx-rs/wgpu?rev=e5ddb94be0221b0f53a8f43adfb15458daebfd7c#e5ddb94be0221b0f53a8f43adfb15458daebfd7c"
dependencies = [
"arrayvec",
"bitflags",
"cfg_aliases",
"copyless",
"fxhash",
"gfx-backend-dx11 0.7.0",
"gfx-backend-dx12 0.7.0",
"gfx-backend-empty 0.7.0",
"gfx-backend-gl 0.7.0",
"gfx-backend-metal 0.7.0",
"gfx-backend-vulkan 0.7.0",
"gfx-hal 0.7.0",
"gpu-alloc",
"gpu-descriptor",
"log",
"naga 0.3.1",
"parking_lot 0.11.1",
"profiling",
"raw-window-handle",
"smallvec",
"thiserror",
"wgpu-types 0.8.0 (git+https://github.com/gfx-rs/wgpu?rev=e5ddb94be0221b0f53a8f43adfb15458daebfd7c)",
]
[[package]]
@ -6703,7 +7028,7 @@ version = "0.4.0"
source = "git+https://github.com/Imberflur/wgpu-profiler?tag=wgpu-0.8#b156eb145bc223386ef344860d9b33b3c181650c"
dependencies = [
"futures",
"wgpu",
"wgpu 0.8.0 (git+https://github.com/gfx-rs/wgpu-rs.git?rev=7486bdad64bb5d17b709ecccb41e063469efff88)",
]
[[package]]
@ -6715,6 +7040,14 @@ dependencies = [
"serde",
]
[[package]]
name = "wgpu-types"
version = "0.8.0"
source = "git+https://github.com/gfx-rs/wgpu?rev=e5ddb94be0221b0f53a8f43adfb15458daebfd7c#e5ddb94be0221b0f53a8f43adfb15458daebfd7c"
dependencies = [
"bitflags",
]
[[package]]
name = "which"
version = "4.1.0"

View File

@ -60,6 +60,14 @@ window_clipboard = "0.2"
glyph_brush = "0.7.0"
keyboard-keynames = { git = "https://gitlab.com/Frinksy/keyboard-keynames.git", rev = "a97ae509cdb9dc70cf1bf0af762d2d1d3a0d6e0c" }
# EGUI
egui = "0.11"
egui_demo_lib = "0.11"
# egui_wgpu_backend = "0.7"
egui_wgpu_backend = { path = "../../egui_wgpu_backend" }
egui_winit_platform = "0.6"
epi = "0.11"
# ECS
specs = {git = "https://github.com/amethyst/specs.git", rev = "5a9b71035007be0e3574f35184acac1cd4530496"}
specs-idvs = { git = "https://gitlab.com/veloren/specs-idvs.git", rev = "b65fb220e94f5d3c9bc30074a076149763795556" }

View File

@ -41,19 +41,22 @@ use crate::singleplayer::Singleplayer;
use crate::{
audio::AudioFrontend,
profile::Profile,
render::Renderer,
run::ExampleRepaintSignal,
settings::Settings,
window::{Event, Window},
};
use common::clock::Clock;
use common_base::span;
use egui_winit_platform::Platform;
use i18n::LocalizationHandle;
use std::sync::Arc;
/// A type used to store state that is shared between all play states.
pub struct GlobalState {
pub settings: Settings,
pub profile: Profile,
pub window: Window,
pub egui_platform: Platform,
pub lazy_init: scene::terrain::SpriteRenderContextLazy,
pub audio: AudioFrontend,
pub info_message: Option<String>,
@ -67,6 +70,8 @@ pub struct GlobalState {
// enter the game before confirmation of successful character load
/// An error returned by Client that needs to be displayed by the UI
pub client_error: Option<String>,
pub egui_demo_app: egui_demo_lib::WrapApp, // TODO: Remove
pub repaint_signal: Option<Arc<ExampleRepaintSignal>>,
}
impl GlobalState {
@ -133,5 +138,5 @@ pub trait PlayState {
fn name(&self) -> &'static str;
/// Draw the play state.
fn render(&mut self, renderer: &mut Renderer, settings: &Settings);
fn render(&mut self, global_state: &mut GlobalState);
}

View File

@ -18,6 +18,8 @@ use common::{
assets::{self},
clock::Clock,
};
use egui::FontDefinitions;
use egui_winit_platform::{Platform, PlatformDescriptor};
use std::panic;
use tracing::{error, info, warn};
@ -185,10 +187,19 @@ fn main() {
let lazy_init = SpriteRenderContext::new(window.renderer_mut());
let mut egui_platform = Platform::new(PlatformDescriptor {
physical_width: window.window().inner_size().width as u32,
physical_height: window.window().inner_size().height as u32,
scale_factor: window.scale_factor(),
font_definitions: FontDefinitions::default(),
style: Default::default(),
});
let global_state = GlobalState {
audio,
profile,
window,
egui_platform,
lazy_init,
clock: Clock::new(std::time::Duration::from_secs_f64(
1.0 / get_fps(settings.graphics.max_fps) as f64,
@ -200,6 +211,8 @@ fn main() {
i18n,
clipboard,
client_error: None,
egui_demo_app: egui_demo_lib::WrapApp::default(),
repaint_signal: None,
};
run::run(global_state, event_loop);

View File

@ -232,7 +232,9 @@ impl PlayState for CharSelectionState {
fn name(&self) -> &'static str { "Character Selection" }
fn render(&mut self, renderer: &mut Renderer, _: &Settings) {
fn render(&mut self, global_state: &mut GlobalState) {
let renderer = global_state.window.renderer_mut();
let mut drawer = match renderer
.start_recording_frame(self.scene.global_bind_group())
.expect("Unrecoverable render error when starting a new frame!")
@ -267,5 +269,11 @@ impl PlayState for CharSelectionState {
if let Some(mut ui_drawer) = third_pass.draw_ui() {
self.char_selection_ui.render(&mut ui_drawer);
};
// drawer.draw_egui(
// egui_platform,
// egui_paint_jobs,
// 1.0, /* TODO: pass in winit window scale factor */
// );
}
}

View File

@ -9,6 +9,9 @@ use crate::{
i18n::LocalizationHandle, render::Renderer, settings::Settings, window::Event, Direction,
GlobalState, PlayState, PlayStateResult,
};
use chrono::Timelike;
#[cfg(feature = "singleplayer")]
use client::addr::ConnectionArgs;
use client::{
addr::ConnectionArgs,
error::{InitProtocolError, NetworkConnectError, NetworkError},
@ -17,6 +20,7 @@ use client::{
use client_init::{ClientInit, Error as InitError, Msg as InitMsg};
use common::comp;
use common_base::span;
use egui_wgpu_backend::epi::App;
use scene::Scene;
use std::sync::Arc;
use tokio::runtime;
@ -317,7 +321,9 @@ impl PlayState for MainMenuState {
fn name(&self) -> &'static str { "Title" }
fn render(&mut self, renderer: &mut Renderer, _: &Settings) {
fn render(&mut self, global_state: &mut GlobalState) {
let mut renderer = global_state.window.renderer_mut();
let mut drawer = match renderer
.start_recording_frame(self.scene.global_bind_group())
.expect("Unrecoverable render error when starting a new frame!")
@ -328,12 +334,62 @@ impl PlayState for MainMenuState {
};
// Draw the UI to the screen.
if let Some(mut ui_drawer) = drawer.third_pass().draw_ui() {
let mut third_pass = drawer.third_pass();
if let Some(mut ui_drawer) = third_pass.draw_ui() {
self.main_menu_ui.render(&mut ui_drawer);
};
drop(third_pass);
global_state.egui_platform.begin_frame();
let mut app_output = epi::backend::AppOutput::default();
let mut frame = epi::backend::FrameBuilder {
info: epi::IntegrationInfo {
web_info: None,
cpu_usage: None, // TODO
seconds_since_midnight: Some(seconds_since_midnight()),
native_pixels_per_point: Some(1.25 /* TODO */),
},
tex_allocator: drawer.egui_renderpass(),
output: &mut app_output,
repaint_signal: global_state.repaint_signal.as_ref().unwrap().clone(),
}
.build();
// let ctx = &global_state.egui_platform.context();
// egui::Window::new("Test Window")
// .default_width(200.0)
// .default_height(200.0)
// .show(ctx, |ui| {
// ui.label("Hello World!");
// });
global_state
.egui_demo_app
.update(&global_state.egui_platform.context(), &mut frame);
let (_output, paint_commands) = global_state.egui_platform.end_frame();
let paint_jobs = global_state
.egui_platform
.context()
.tessellate(paint_commands);
// let frame_time = (Instant::now() - egui_start).as_secs_f64() as f32;
// previous_frame_time = Some(frame_time);
drawer.draw_egui(
// renderer.egui_renderpass(),
&global_state.egui_platform,
&paint_jobs,
1.25, /* TODO: pass in winit window scale factor */
);
}
}
/// Time of day as seconds since midnight. Used for clock in demo app.
pub fn seconds_since_midnight() -> f64 {
let time = chrono::Local::now().time();
time.num_seconds_from_midnight() as f64 + 1e-9 * (time.nanosecond() as f64)
}
fn get_client_msg_error(e: client_init::Error, localized_strings: &LocalizationHandle) -> String {
let localization = localized_strings.read();

View File

@ -30,6 +30,7 @@ use super::{
use common::assets::{self, AssetExt, AssetHandle};
use common_base::span;
use core::convert::TryFrom;
use egui_wgpu_backend::wgpu::TextureFormat;
use std::sync::Arc;
use tracing::{error, info, warn};
use vek::*;
@ -135,6 +136,8 @@ pub struct Renderer {
profiler: wgpu_profiler::GpuProfiler,
profile_times: Vec<wgpu_profiler::GpuTimerScopeResult>,
profiler_features_enabled: bool,
egui_renderpass: egui_wgpu_backend::RenderPass,
}
impl Renderer {
@ -360,6 +363,9 @@ impl Renderer {
profiler.enable_timer = mode.profiler_enabled;
profiler.enable_debug_marker = mode.profiler_enabled;
let egui_renderpass =
egui_wgpu_backend::RenderPass::new(&device, TextureFormat::Bgra8UnormSrgb);
Ok(Self {
device,
queue,
@ -391,6 +397,7 @@ impl Renderer {
profiler,
profile_times: Vec::new(),
profiler_features_enabled,
egui_renderpass,
})
}
@ -1131,6 +1138,10 @@ impl Renderer {
}
}
pub fn egui_renderpass_mut(&mut self) -> &mut egui_wgpu_backend::RenderPass {
&mut self.egui_renderpass
}
// Consider reenabling at some time
//
// /// Queue the rendering of the player silhouette in the upcoming frame.

View File

@ -11,8 +11,11 @@ use super::{
Renderer, ShadowMap, ShadowMapRenderer,
};
use core::{num::NonZeroU32, ops::Range};
use egui_wgpu_backend::ScreenDescriptor;
use egui_winit_platform::Platform;
use std::sync::Arc;
use vek::Aabr;
use wgpu::TextureFormat;
use wgpu_profiler::scope::{ManualOwningScope, OwningScope, Scope};
// Currently available pipelines
@ -53,6 +56,7 @@ impl<'frame> Pipelines<'frame> {
struct RendererBorrow<'frame> {
queue: &'frame wgpu::Queue,
device: &'frame wgpu::Device,
sc_desc: &'frame wgpu::SwapChainDescriptor,
shadow: Option<&'frame super::Shadow>,
pipelines: Pipelines<'frame>,
locals: &'frame super::locals::Locals,
@ -60,12 +64,13 @@ struct RendererBorrow<'frame> {
mode: &'frame super::super::RenderMode,
quad_index_buffer_u16: &'frame Buffer<u16>,
quad_index_buffer_u32: &'frame Buffer<u32>,
egui_render_pass: &'frame mut egui_wgpu_backend::RenderPass,
}
pub struct Drawer<'frame> {
encoder: Option<ManualOwningScope<'frame, wgpu::CommandEncoder>>,
borrow: RendererBorrow<'frame>,
swap_tex: wgpu::SwapChainTexture,
pub swap_tex: wgpu::SwapChainTexture,
globals: &'frame GlobalsBindGroup,
// Texture and other info for taking a screenshot
// Writes to this instead in the third pass if it is present
@ -100,6 +105,7 @@ impl<'frame> Drawer<'frame> {
let borrow = RendererBorrow {
queue: &renderer.queue,
device: &renderer.device,
sc_desc: &renderer.sc_desc,
shadow,
pipelines,
locals: &renderer.locals,
@ -107,6 +113,7 @@ impl<'frame> Drawer<'frame> {
mode: &renderer.mode,
quad_index_buffer_u16: &renderer.quad_index_buffer_u16,
quad_index_buffer_u32: &renderer.quad_index_buffer_u32,
egui_render_pass: &mut renderer.egui_renderpass,
};
let encoder =
@ -124,6 +131,10 @@ impl<'frame> Drawer<'frame> {
/// Get the render mode.
pub fn render_mode(&self) -> &super::super::RenderMode { self.borrow.mode }
// pub fn encoder(&mut self) -> &mut ManualOwningScope<wgpu::CommandEncoder> {
// self.encoder.as_mut().unwrap()
// }
/// Returns None if the shadow renderer is not enabled at some level or the
/// pipelines are not available yet
pub fn shadow_pass(&mut self) -> Option<ShadowPassDrawer> {
@ -260,6 +271,58 @@ impl<'frame> Drawer<'frame> {
}
}
pub fn egui_pass(&mut self) -> EguiPassDrawer {
let render_pass =
egui_wgpu_backend::RenderPass::new(self.borrow.device, TextureFormat::Bgra8UnormSrgb);
EguiPassDrawer {
render_pass,
borrow: &self.borrow,
}
}
pub fn draw_egui(
&mut self,
//egui_renderpass: &mut egui_wgpu_backend::RenderPass,
platform: &Platform,
paint_jobs: &[egui::paint::ClippedMesh],
scale_factor: f32,
) {
let screen_descriptor = ScreenDescriptor {
physical_width: self.borrow.sc_desc.width,
physical_height: self.borrow.sc_desc.height,
scale_factor,
};
self.borrow.egui_render_pass.update_texture(
self.borrow.device,
self.borrow.queue,
&platform.context().texture(),
);
self.borrow
.egui_render_pass
.update_user_textures(self.borrow.device, self.borrow.queue);
self.borrow.egui_render_pass.update_buffers(
self.borrow.device,
self.borrow.queue,
&paint_jobs,
&screen_descriptor,
);
self.borrow.egui_render_pass.execute(
self.encoder.as_mut().unwrap(),
self.borrow.device,
&self.swap_tex.view,
paint_jobs,
&screen_descriptor,
None,
);
}
pub fn egui_renderpass(&mut self) -> &mut egui_wgpu_backend::RenderPass {
self.borrow.egui_render_pass
}
/// Does nothing if the shadow pipelines are not available or shadow map
/// rendering is disabled
pub fn draw_point_shadows<'data: 'frame>(
@ -797,6 +860,11 @@ impl<'pass> ThirdPassDrawer<'pass> {
}
}
pub struct EguiPassDrawer<'pass> {
render_pass: egui_wgpu_backend::RenderPass,
borrow: &'pass RendererBorrow<'pass>,
}
pub struct UiDrawer<'pass_ref, 'pass: 'pass_ref> {
render_pass: Scope<'pass_ref, wgpu::RenderPass<'pass>>,
}

View File

@ -9,6 +9,23 @@ use common_base::{no_guard_span, span, GuardlessSpan};
use std::{mem, time::Duration};
use tracing::debug;
pub struct ExampleRepaintSignal(std::sync::Mutex<winit::event_loop::EventLoopProxy<CustomEvent>>);
/// A custom event type for the winit app.
pub enum CustomEvent {
RequestRedraw,
}
impl epi::RepaintSignal for ExampleRepaintSignal {
fn request_repaint(&self) {
self.0
.lock()
.unwrap()
.send_event(CustomEvent::RequestRedraw)
.ok();
}
}
pub fn run(mut global_state: GlobalState, event_loop: EventLoop) {
// Set up the initial play state.
let mut states: Vec<Box<dyn PlayState>> = vec![Box::new(MainMenuState::new(&mut global_state))];
@ -27,10 +44,15 @@ pub fn run(mut global_state: GlobalState, event_loop: EventLoop) {
let mut poll_span = None;
let mut event_span = None;
global_state.repaint_signal = Some(std::sync::Arc::new(ExampleRepaintSignal(
std::sync::Mutex::new(event_loop.create_proxy()),
)));
event_loop.run(move |event, _, control_flow| {
// Continuously run loop since we handle sleeping
*control_flow = winit::event_loop::ControlFlow::Poll;
global_state.egui_platform.handle_event(&event);
// Get events for the ui.
if let Some(event) = ui::Event::try_from(&event, global_state.window.window()) {
global_state.window.send_event(Event::Ui(event));
@ -167,10 +189,8 @@ fn handle_main_events_cleared(
drop(guard);
if let Some(last) = states.last_mut() {
span!(guard, "Render");
let renderer = global_state.window.renderer_mut();
// Render the screen using the global renderer
last.render(renderer, &global_state.settings);
last.render(global_state);
drop(guard);
}

View File

@ -37,13 +37,14 @@ use crate::{
audio::sfx::SfxEvent,
hud::{DebugInfo, Event as HudEvent, Hud, HudInfo, LootMessage, PromptDialogSettings},
key_state::KeyState,
menu::char_selection::CharSelectionState,
menu::{char_selection::CharSelectionState, main::seconds_since_midnight},
render::Renderer,
scene::{camera, terrain::Interaction, CameraMode, DebugShapeId, Scene, SceneData},
scene::{camera, terrain::Interaction, CameraMode, Scene, SceneData},
settings::Settings,
window::{AnalogGameInput, Event, GameInput},
Direction, Error, GlobalState, PlayState, PlayStateResult,
};
use egui_wgpu_backend::epi::App;
use hashbrown::HashMap;
use settings_change::Language::ChangeLanguage;
@ -1390,7 +1391,11 @@ impl PlayState for SessionState {
/// Render the session to the screen.
///
/// This method should be called once per frame.
fn render(&mut self, renderer: &mut Renderer, settings: &Settings) {
fn render(&mut self, global_state: &mut GlobalState) {
let renderer = global_state.window.renderer_mut();
let settings = &global_state.settings;
span!(_guard, "render", "<Session as PlayState>::render");
let mut drawer = match renderer
.start_recording_frame(self.scene.global_bind_group())
@ -1444,6 +1449,50 @@ impl PlayState for SessionState {
if let Some(mut ui_drawer) = third_pass.draw_ui() {
self.hud.render(&mut ui_drawer);
}; // Note: this semicolon is needed for the third_pass borrow to be dropped before it's lifetime ends
drop(third_pass);
global_state.egui_platform.begin_frame();
let mut app_output = epi::backend::AppOutput::default();
let mut frame = epi::backend::FrameBuilder {
info: epi::IntegrationInfo {
web_info: None,
cpu_usage: None, // TODO
seconds_since_midnight: Some(seconds_since_midnight()),
native_pixels_per_point: Some(1.25 /* TODO */),
},
tex_allocator: drawer.egui_renderpass(),
output: &mut app_output,
repaint_signal: global_state.repaint_signal.as_ref().unwrap().clone(),
}
.build();
// let ctx = &global_state.egui_platform.context();
// egui::Window::new("Test Window")
// .default_width(200.0)
// .default_height(200.0)
// .show(ctx, |ui| {
// ui.label("Hello World!");
// });
global_state
.egui_demo_app
.update(&global_state.egui_platform.context(), &mut frame);
let (_output, paint_commands) = global_state.egui_platform.end_frame();
let paint_jobs = global_state
.egui_platform
.context()
.tessellate(paint_commands);
// let frame_time = (Instant::now() - egui_start).as_secs_f64() as f32;
// previous_frame_time = Some(frame_time);
println!("drawing {} paint jobs from session", paint_jobs.len());
drawer.draw_egui(
// renderer.egui_renderpass(),
&global_state.egui_platform,
&paint_jobs,
1.25, /* TODO: pass in winit window scale factor */
);
}
}

View File

@ -1,3 +1,4 @@
use crate::run::CustomEvent;
use conrod_core::{event::Input, input::Button};
use vek::*;
@ -5,7 +6,7 @@ use vek::*;
pub struct Event(pub Input);
impl Event {
pub fn try_from(
event: &winit::event::Event<()>,
event: &winit::event::Event<CustomEvent>,
window: &winit::window::Window,
) -> Option<Self> {
use conrod_winit::*;

View File

@ -1,6 +1,7 @@
use crate::{
controller::*,
render::Renderer,
run::CustomEvent,
settings::{ControlSettings, Settings},
ui, Error,
};
@ -14,7 +15,6 @@ use serde::{Deserialize, Serialize};
use tracing::{error, warn};
use vek::*;
use winit::monitor::VideoMode;
/// Represents a key that the game recognises after input mapping.
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Deserialize, Serialize)]
pub enum GameInput {
@ -319,7 +319,7 @@ pub enum Event {
pub type MouseButton = winit::event::MouseButton;
pub type PressState = winit::event::ElementState;
pub type EventLoop = winit::event_loop::EventLoop<()>;
pub type EventLoop = winit::event_loop::EventLoop<CustomEvent>;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, Deserialize, Serialize)]
pub enum KeyMouse {
@ -547,7 +547,7 @@ pub struct Window {
impl Window {
pub fn new(settings: &Settings) -> Result<(Window, EventLoop), Error> {
let event_loop = EventLoop::new();
let event_loop = EventLoop::with_user_event();
let size = settings.graphics.window_size;