]> git.lizzy.rs Git - mt_client.git/commitdiff
Merge branch 'master' of github.com:minetest-rust/mt_client
authorLizzy Fleckenstein <eliasfleckenstein@web.de>
Mon, 10 Apr 2023 17:08:58 +0000 (19:08 +0200)
committerLizzy Fleckenstein <eliasfleckenstein@web.de>
Mon, 10 Apr 2023 17:09:11 +0000 (19:09 +0200)
Cargo.toml
assets/shaders/map.wgsl
src/gfx.rs
src/gfx/map.rs

index 6b389824bc08a92c71eac4e307892ca5ba2c3c2d..309b64d91d09073b5d3cb083e8da753eac814ff5 100644 (file)
@@ -3,6 +3,12 @@ name = "mt_client"
 version = "0.1.0"
 edition = "2021"
 
+[profile.dev]
+opt-level = 1
+
+[profile.dev.package."*"]
+opt-level = 3
+
 [dependencies]
 bytemuck = { version = "1.13.0", features = ["derive"] }
 cgmath = "0.17.0"
index f6919a97f7af6d2fa6e4f767642a777798f35a51..bb88a3fc02a78672b312f16efd45b68cd84c57d6 100644 (file)
@@ -3,11 +3,13 @@
 struct VertexInput {
        @location(0) pos: vec3<f32>,
        @location(1) tex_coords: vec2<f32>,
+       @location(2) light: f32,
 }
 
 struct VertexOutput {
        @builtin(position) pos: vec4<f32>,
        @location(0) tex_coords: vec2<f32>,
+       @location(1) light: f32,
 }
 
 @group(1) @binding(0) var<uniform> view_proj: mat4x4<f32>;
@@ -20,6 +22,7 @@ fn vs_main(
        var out: VertexOutput;
        out.pos = view_proj * model * vec4<f32>(in.pos, 1.0);
        out.tex_coords = in.tex_coords;
+       out.light = in.light;
        return out;
 }
 
@@ -30,5 +33,12 @@ fn vs_main(
 
 @fragment
 fn fs_main(in: VertexOutput) -> @location(0) vec4<f32> {
-       return textureSample(atlas_texture, atlas_sampler, in.tex_coords);
+       var color = textureSample(atlas_texture, atlas_sampler, in.tex_coords);
+
+       if color.a < 0.1 {
+               discard;
+       }
+
+       color = vec4<f32>(color.rgb * in.light, color.a);
+       return color;
 }
index e3fb07316225c35a5bf439a1802bf15664a95797..c86b351717df36ad4fe624a0306313e958c4a0c1 100644 (file)
@@ -22,11 +22,6 @@ pub async fn run(
         .build(&event_loop)
         .unwrap();
 
-    window
-        .set_cursor_grab(CursorGrabMode::Locked)
-        .or_else(|_e| window.set_cursor_grab(CursorGrabMode::Confined))
-        .unwrap();
-
     window.set_cursor_visible(false);
 
     let mut state = state::State::new(&window).await;
@@ -37,6 +32,8 @@ pub async fn run(
 
     let mut last_frame = Instant::now();
 
+    let mut game_paused = false;
+
     event_loop.run_return(move |event, _, flow| match event {
         MainEventsCleared => window.request_redraw(),
         RedrawRequested(id) if id == window.id() => {
@@ -78,21 +75,28 @@ pub async fn run(
                 ..
             } => {
                 use fps_camera::Actions;
-                use winit::event::{ElementState::*, VirtualKeyCode as Key};
+                use winit::event::{ElementState, VirtualKeyCode as Key};
+
+                if key == &Key::Escape && key_state == &ElementState::Pressed {
+                    game_paused = !game_paused;
+                    window.set_cursor_visible(game_paused);
+                }
 
-                let actions = match key {
-                    Key::W => Actions::MOVE_FORWARD,
-                    Key::A => Actions::STRAFE_LEFT,
-                    Key::S => Actions::MOVE_BACKWARD,
-                    Key::D => Actions::STRAFE_RIGHT,
-                    Key::Space => Actions::FLY_UP,
-                    Key::LShift => Actions::FLY_DOWN,
-                    _ => Actions::empty(),
-                };
+                if !game_paused {
+                    let actions = match key {
+                        Key::W => Actions::MOVE_FORWARD,
+                        Key::A => Actions::STRAFE_LEFT,
+                        Key::S => Actions::MOVE_BACKWARD,
+                        Key::D => Actions::STRAFE_RIGHT,
+                        Key::Space => Actions::FLY_UP,
+                        Key::LShift => Actions::FLY_DOWN,
+                        _ => Actions::empty(),
+                    };
 
-                match key_state {
-                    Pressed => state.camera.enable_actions(actions),
-                    Released => state.camera.disable_action(actions),
+                    match key_state {
+                        ElementState::Pressed => state.camera.enable_actions(actions),
+                        ElementState::Released => state.camera.disable_action(actions),
+                    }
                 }
             }
             _ => {}
@@ -101,13 +105,15 @@ pub async fn run(
             event: MouseMotion { delta },
             ..
         } => {
-            state.camera.update_mouse(delta.0 as f32, delta.1 as f32);
-            window
-                .set_cursor_position(winit::dpi::PhysicalPosition::new(
-                    state.config.width / 2,
-                    state.config.height / 2,
-                ))
-                .ok();
+            if !game_paused {
+                state.camera.update_mouse(delta.0 as f32, delta.1 as f32);
+                window
+                    .set_cursor_position(winit::dpi::PhysicalPosition::new(
+                        state.config.width / 2,
+                        state.config.height / 2,
+                    ))
+                    .ok();
+            }
         }
         UserEvent(event) => match event {
             Close => *flow = ExitWithCode(0),
index d95a4d27737aa9e3a6ea3b386703b192590d2d8b..dbedb77b60a248caa5380b512973c2c48c078f3f 100644 (file)
@@ -19,11 +19,12 @@ pub struct MapRender {
 struct Vertex {
     pos: [f32; 3],
     tex_coords: [f32; 2],
+    light: f32,
 }
 
 impl Vertex {
-    const ATTRIBS: [wgpu::VertexAttribute; 2] =
-        wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2];
+    const ATTRIBS: [wgpu::VertexAttribute; 3] =
+        wgpu::vertex_attr_array![0 => Float32x3, 1 => Float32x2, 2 => Float32];
 
     fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
         wgpu::VertexBufferLayout {
@@ -62,11 +63,20 @@ impl MapRender {
             };
 
             use lerp::Lerp;
-            use mt_net::DrawType;
+            use mt_net::{DrawType, Param1Type};
             use std::array::from_fn as array;
 
             match def.draw_type {
-                DrawType::Cube => {
+                DrawType::Cube | DrawType::AllFaces | DrawType::AllFacesOpt => {
+                    let light = match def.param1_type {
+                        Param1Type::Light => {
+                            println!("{}", block.param_1[index]);
+
+                            block.param_1[index] as f32 / 15.0
+                        }
+                        _ => 1.0,
+                    };
+
                     let pos: [i16; 3] = array(|i| ((index >> (4 * i)) & 0xf) as i16);
                     for (f, face) in CUBE.iter().enumerate() {
                         let dir = FACE_DIR[f];
@@ -98,6 +108,7 @@ impl MapRender {
                             vertices.push(Vertex {
                                 pos: array(|i| pos[i] as f32 - 8.5 + vertex.0[i]),
                                 tex_coords: array(|i| rect[i].start.lerp(rect[i].end, vertex.1[i])),
+                                light,
                             })
                         }
                     }