From 35ad1762d6d1dccd55da240996c26720489fd87b Mon Sep 17 00:00:00 2001 From: EndMove Date: Sat, 16 Sep 2023 14:54:36 +0200 Subject: [PATCH] use windowBuilder --- Cargo.toml | 4 +++- assets/icon.ico | Bin 0 -> 16958 bytes benches/voxel_map_benchmark.rs | 4 ++-- src/main.rs | 41 +++++++++++++++++++++++---------- 4 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 assets/icon.ico diff --git a/Cargo.toml b/Cargo.toml index 7f57af4..5244ba3 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,8 @@ name = "rust-game-engine" version = "0.1.0" edition = "2021" +authors = ["phito", "endmove"] +repository = "https://git.endmove.eu/phito/rust-game-engine.git" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html @@ -11,7 +13,7 @@ env_logger = "0.10.0" pollster = "0.3.0" wgpu = "0.17.0" winit = "0.28.6" -criterion = { version = "0.4", features = ["html_reports"] } +criterion = { version = "0.5.1", features = ["html_reports"] } [[bench]] diff --git a/assets/icon.ico b/assets/icon.ico new file mode 100644 index 0000000000000000000000000000000000000000..522202d40b0d67df412c98f45bfb95c319d539f8 GIT binary patch literal 16958 zcmdU12b5gZdA<@LkVG*@!NvuMjaIumeP(B;>};F&-pqSbw)Zl-v%UAe(n_mtK*E+l z2o*a%CQe-9B#tp5#Jxbkv3(o|2LjkQjzM4%Qw8!0-F*LjGuv3Pa1bfO`E+OAym{|_ z-(T;2dthu0{>#s2`1em)n#9-#8DnVx4zXE)j*C~mKKxJp8;(!1P<)1kn`oS1fx2N} zgyog>GP!z?6?e^CQQSGR-e1|za!Y%dQZvLP9M>Ag#QCAdaYp$6@Cr9iv*kGYy+;Js zNb{5#8hC4`KfT6Z-p7cqTs?GUuzuti@Mm((&=_Zk%tm=GL;<^g*V^ zMp>|aRA>@uo@9joOE0;040ao4O5GUCF70L6B|XfZSHtovz^S7DTG;dl{)+z7IYpgS z`K8?~HxgsMXnT8hQRlhr!jAL4Xls9V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{K`d-<(jvsc`98SPov zO7}B&-KUtZ=}wm0dXzzjcgg1BoURUj0lDEMa>U6oSM0>g&f2?ArWYQ%$q?C(9_qHK zwD7IqydRqE;mDi!Z&vo-of6o47P*v@zigIv&LMtIZjpD~Ye38xBRf&Uc5_p~p52z{ zEc%bVAIqq|{Vq?#k(aXKcWw7J90A`G7iaPp;VR@0u7;D$-EiVsXZ^{{?AFh%HIe%(}jJ2w^{gufhkU~_Q))hX&HueX&Q z{D!mU5O>wx@nUA}VK)Ff-@^P|pSwJ}`Iyt!d~B1i>2Bn&(9 zc;lZztbAsjyW!-gq0hbErjsd_vOAcg`Y7V%c$O=6{5gy-xMIir&e|i)R(=S%<@m?5 znvVaiuj%+v5-k!y(WO1OBle}Aq-I)DfBHXh&LX*_;acFS?*?>xc0ad2w=+*a4esxE{X}*hs&nWAEpS^Ye`D;COwPu}f&2#s4s1(fA_W{Tj|M zG}70Maem?P8vK-gz5{m>?{V%*BfB2QXK|emU3jN<#Jnf{thj4KY8uk>x=*jwg#q2oeMT?e`e>5&-Mya*BKb9^0+zm2YR{(|n} R0xQ^Qxjo6w!oIrQ{~MI|%m@Gg literal 0 HcmV?d00001 diff --git a/benches/voxel_map_benchmark.rs b/benches/voxel_map_benchmark.rs index bc448c3..78f19dd 100644 --- a/benches/voxel_map_benchmark.rs +++ b/benches/voxel_map_benchmark.rs @@ -14,7 +14,7 @@ fn voxel_vec_1d(data: Vec) -> Voxel { const Y: usize = 0; const Z: usize = 0; - return data[X + Y * MAP_WIDTH + Z * MAP_WIDTH * MAP_HEIGHT]; + data[X + Y * MAP_WIDTH + Z * MAP_WIDTH * MAP_HEIGHT] } fn voxel_vec_3d(data: Vec>>) -> Voxel { @@ -22,7 +22,7 @@ fn voxel_vec_3d(data: Vec>>) -> Voxel { const Y: usize = 0; const Z: usize = 0; - return data[X][Y][Z]; + data[X][Y][Z] } fn criterion_benchmark(c: &mut Criterion) { diff --git a/src/main.rs b/src/main.rs index 833b512..cdf0104 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,22 +4,24 @@ use std::borrow::Cow; use winit::{ event::{Event, WindowEvent}, event_loop::{ControlFlow, EventLoop}, - window::Window, + window::{WindowBuilder, Window}, }; async fn run(event_loop: EventLoop<()>, window: Window) { let size = window.inner_size(); let instance = wgpu::Instance::default(); + let surface = unsafe { instance.create_surface(&window) } + .expect("Failed to create surface"); + + let adapter_options = wgpu::RequestAdapterOptions { + power_preference: wgpu::PowerPreference::default(), + force_fallback_adapter: false, + compatible_surface: None, + }; - let surface = unsafe { instance.create_surface(&window) }.unwrap(); let adapter = instance - .request_adapter(&wgpu::RequestAdapterOptions { - power_preference: wgpu::PowerPreference::default(), - force_fallback_adapter: false, - // Request an adapter which can render to our surface - compatible_surface: Some(&surface), - }) + .request_adapter(&adapter_options) .await .expect("Failed to find an appropriate adapter"); @@ -40,12 +42,12 @@ async fn run(event_loop: EventLoop<()>, window: Window) { // Load the shaders from disk let shader = device.create_shader_module(wgpu::ShaderModuleDescriptor { - label: None, + label: Some("Shader"), source: wgpu::ShaderSource::Wgsl(Cow::Borrowed(include_str!("shader.wgsl"))), }); let pipeline_layout = device.create_pipeline_layout(&wgpu::PipelineLayoutDescriptor { - label: None, + label: Some("Pipeline Layout"), bind_group_layouts: &[], push_constant_ranges: &[], }); @@ -54,7 +56,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) { let swapchain_format = swapchain_capabilities.formats[0]; let render_pipeline = device.create_render_pipeline(&wgpu::RenderPipelineDescriptor { - label: None, + label: Some("Render Pipeline"), layout: Some(&pipeline_layout), vertex: wgpu::VertexState { module: &shader, @@ -142,8 +144,23 @@ async fn run(event_loop: EventLoop<()>, window: Window) { } fn main() { + // Instantiate event loop and win builder let event_loop = EventLoop::new(); - let window = winit::window::Window::new(&event_loop).unwrap(); + let win_builder = WindowBuilder::new(); + + // Create and configure window + let window_def_size = winit::dpi::LogicalSize::new(640, 360); + // let window_icon = Icon::from_path("../assets/icon.ico", None).expect("Failed to load icon"); + let window = win_builder.with_title("Rust Game Engine") + .with_inner_size(window_def_size) + .with_min_inner_size(window_def_size) + .with_resizable(true) + .with_enabled_buttons(winit::window::WindowButtons::from_bits(3).unwrap()) + .with_transparent(true) + // .with_window_icon(Some(window_icon)) + .build(&event_loop) + .unwrap(); + #[cfg(not(target_arch = "wasm32"))] { env_logger::init();