diff --git a/blockworld-client/game/chunk.rs b/blockworld-client/game/chunk.rs index 61f1468..16fd33b 100644 --- a/blockworld-client/game/chunk.rs +++ b/blockworld-client/game/chunk.rs @@ -93,18 +93,18 @@ impl Default for Chunk { // REMEMBER TO DELETE THOSE CODE fn default() -> Self { let mut blocks = Box::new([Block::default(); CHUNK_BLOCK_NUM]); - for x in (0..CHUNK_SIZE as i32) { - for y in (0..3) { - for z in (0..CHUNK_SIZE as i32) { + for x in 0..CHUNK_SIZE as i32 { + for y in 0..3 { + for z in 0..CHUNK_SIZE as i32 { blocks[Chunk::index(x, y, z)] = match y { _ => Block { id: 1 }, } } } } - for x in (0..CHUNK_SIZE as i32) { - for y in (5..40) { - for z in (0..CHUNK_SIZE as i32) { + for x in 0..CHUNK_SIZE as i32 { + for y in 5..40 { + for z in 0..CHUNK_SIZE as i32 { if (vec3(x as f32, y as f32, z as f32) - vec3(7.0, 15.0, 7.0)).length() <= 7.0 { blocks[Chunk::index(x, y, z)] = match y { _ => Block { id: 2 }, diff --git a/blockworld-client/game/console_instr.rs b/blockworld-client/game/console_instr.rs index 728175c..18ca127 100644 --- a/blockworld-client/game/console_instr.rs +++ b/blockworld-client/game/console_instr.rs @@ -35,15 +35,15 @@ impl ConsoleInstr { let args_clean = &args_str[1..args_str.len() - 1]; let args: Vec = args_clean.split(',').map(|s| s.to_string()).collect(); - /// dialogue_id is used to distinguish the corresponding relation of request & reponse - /// It can be None if you are sure that + // dialogue_id is used to distinguish the corresponding relation of request & reponse + // It can be None if you are sure that let dialogue_id: Option = if input.ends_with("]") { let rev_chs = input.chars().rev(); // 这是个左闭右开区间 let event_id_start_index = input.len() - 1; let event_id_end_index = rev_chs .enumerate() - .find(|(index, ch)| *ch == '[') + .find(|(_, ch)| *ch == '[') .with_context(|| format!("failed to parse event_id"))? .0 + 1; @@ -66,10 +66,10 @@ impl ConsoleInstr { macro_rules! match_command{ ($(command $command_name:ident with_args ($($arg_n:ident:$arg_n_type:ident),*) debug $is_debug:ident)+ in $command_args:ident with_context $ctx:ident) => { match $command_args{ - $(ConsoleInstr{command ,args ,dialogue_id} if &command == stringify!($command_name) =>{ + $(ConsoleInstr{command ,args ,dialogue_id:_} if &command == stringify!($command_name) =>{ let mut count = 0; match ($({count+=1;&args[count-1].parse::<$arg_n_type>()}),*){ - ($(std::result::Result::Ok($arg_n)),*) =>{ + $(std::result::Result::Ok($arg_n)),* =>{ $command_name($ctx, $($arg_n),*); if $is_debug { println!("successfullly run \x1B[32m {} \x1B[0m with args \x1B[32m{:?}\x1B[0m",command,args); diff --git a/blockworld-client/game/player_state.rs b/blockworld-client/game/player_state.rs index 33559f8..1a923d5 100644 --- a/blockworld-client/game/player_state.rs +++ b/blockworld-client/game/player_state.rs @@ -1,8 +1,6 @@ -use std::collections::HashSet; +use winit::keyboard::{Key, NamedKey}; -use winit::keyboard::{Key, KeyCode, NamedKey}; - -use crate::{io::input_helper::InputState, render::draw::State}; +use crate::io::input_helper::InputState; // Best not to pub here // I'd like to change it later diff --git a/blockworld-client/game/register.rs b/blockworld-client/game/register.rs index f0bca22..c4378d7 100644 --- a/blockworld-client/game/register.rs +++ b/blockworld-client/game/register.rs @@ -1,7 +1,6 @@ use std::collections::HashMap; use anyhow::Error; -use glam::{IVec2, Vec2}; use block::{BlockID, BlockMeta}; diff --git a/blockworld-client/game/save.rs b/blockworld-client/game/save.rs index 7859289..87fcfaa 100644 --- a/blockworld-client/game/save.rs +++ b/blockworld-client/game/save.rs @@ -1,13 +1,13 @@ //! Save file(Map) manager -use std::collections::{HashMap, HashSet}; +use std::collections::HashMap; use anyhow::*; use glam::{ivec2, IVec2, IVec3}; use crate::game::chunk::CHUNK_SIZE; -use super::{block::Block, chunk::Chunk}; +use super::chunk::Chunk; struct ChunkPool { chunks: HashMap, } @@ -20,9 +20,10 @@ impl ChunkPool { } pub fn load_chunk(x: i32, y: i32) -> Result<()> { - todo!() + let _ = x; + let _ = y; + todo!(); } - pub fn generate_chunk(&mut self, x: i32, z: i32) -> Result<()> { if self.chunks.contains_key(&ivec2(x, z)) { Err(anyhow::Error::msg("Chunk already generated")) diff --git a/blockworld-client/io/atlas_helper.rs b/blockworld-client/io/atlas_helper.rs index bd72d99..019cdda 100644 --- a/blockworld-client/io/atlas_helper.rs +++ b/blockworld-client/io/atlas_helper.rs @@ -9,8 +9,8 @@ pub struct AtlasCoordinate { impl AtlasCoordinate { pub fn new(aa: Vec2, bb: Vec2) -> Self { - aa.clamp(vec2(0., 0.), vec2(1., 1.)); - bb.clamp(vec2(0., 0.), vec2(1., 1.)); + let aa = aa.clamp(vec2(0., 0.), vec2(1., 1.)); + let bb = bb.clamp(vec2(0., 0.), vec2(1., 1.)); Self { aa, bb } } diff --git a/blockworld-client/io/mod.rs b/blockworld-client/io/mod.rs index 88dff76..77817cb 100644 --- a/blockworld-client/io/mod.rs +++ b/blockworld-client/io/mod.rs @@ -1,3 +1,2 @@ -pub mod assets_reader; pub mod atlas_helper; pub mod input_helper; diff --git a/blockworld-client/main.rs b/blockworld-client/main.rs index 1723022..87a28c8 100644 --- a/blockworld-client/main.rs +++ b/blockworld-client/main.rs @@ -1,3 +1,4 @@ +use anyhow::*; use clap::Parser; mod debug; @@ -16,6 +17,7 @@ pub struct BootArgs { full_screen: bool, } -fn main() { - pollster::block_on(render::window_init::run()); +fn main() -> Result<()> { + pollster::block_on(render::window_init::run())?; + Ok(()) } diff --git a/blockworld-client/render/render_block.rs b/blockworld-client/render/render_block.rs index 7d5145e..d5bf5a4 100644 --- a/blockworld-client/render/render_block.rs +++ b/blockworld-client/render/render_block.rs @@ -1,4 +1,4 @@ -use glam::{vec3, Vec2, Vec3}; +use glam::*; use crate::io::atlas_helper::AtlasCoordinate; @@ -114,7 +114,7 @@ pub fn push_face_mesh( ) { // Center coord - let mut c = coord; + let c = coord; let mut n = direction.get_four_vtx(); n.iter_mut().for_each(|x| *x = *x + c); diff --git a/blockworld-client/render/render_chunk.rs b/blockworld-client/render/render_chunk.rs index cfdfaec..76db949 100644 --- a/blockworld-client/render/render_chunk.rs +++ b/blockworld-client/render/render_chunk.rs @@ -1,14 +1,10 @@ use super::render_block::*; -use glam::{vec2, vec3, IVec2}; -use log::info; +use glam::*; use wgpu::{util::DeviceExt, Device}; -use crate::{ - game::{block, chunk::*, register::RegisterTable}, - io::atlas_helper::AtlasMeta, -}; +use crate::game::{chunk::*, register::RegisterTable}; -use super::{draw::State, render_block::*, vertex::Vertex}; +use super::vertex::Vertex; #[derive(Debug)] pub struct RenderChunk { @@ -19,9 +15,9 @@ pub struct RenderChunk { impl RenderChunk { pub fn new(device: &Device, chunk: &Chunk, register_table: &RegisterTable) -> Self { let mut vertices: Vec = Vec::new(); - for x in (0..CHUNK_SIZE as i32) { - for y in (0..CHUNK_HEIGHT as i32) { - for z in (0..CHUNK_SIZE as i32) { + for x in 0..CHUNK_SIZE as i32 { + for y in 0..CHUNK_HEIGHT as i32 { + for z in 0..CHUNK_SIZE as i32 { let (abs_x, abs_z) = ( (chunk.x_pos * CHUNK_SIZE as i32 + x as i32) as f32, (chunk.z_pos * CHUNK_SIZE as i32 + z as i32) as f32, diff --git a/blockworld-client/render/texture.rs b/blockworld-client/render/texture.rs index 24b186f..9227775 100644 --- a/blockworld-client/render/texture.rs +++ b/blockworld-client/render/texture.rs @@ -1,11 +1,6 @@ -use std::collections::HashMap; - use anyhow::*; -use glam::*; use image::GenericImageView; -use crate::game::block::BlockType; - pub struct Texture { pub texture: wgpu::Texture, pub view: wgpu::TextureView, diff --git a/blockworld-client/render/vertex.rs b/blockworld-client/render/vertex.rs index 2c498e3..c065a72 100644 --- a/blockworld-client/render/vertex.rs +++ b/blockworld-client/render/vertex.rs @@ -1,5 +1,3 @@ -use glam::Vec3; - #[repr(C)] #[derive(Copy, Clone, Debug, bytemuck::Zeroable, bytemuck::Pod)] pub struct Vertex { diff --git a/blockworld-client/render/window_init.rs b/blockworld-client/render/window_init.rs index 4be83c3..c804ef7 100644 --- a/blockworld-client/render/window_init.rs +++ b/blockworld-client/render/window_init.rs @@ -1,15 +1,13 @@ -use crate::render::draw::{self, State}; +use crate::render::draw::State; use crate::BootArgs; use anyhow::*; -use anyhow::*; use clap::Parser; -use log::{debug, info}; +use log::*; use winit::application::ApplicationHandler; -use winit::dpi::PhysicalSize; use winit::event::{DeviceEvent, WindowEvent}; use winit::event_loop::{ActiveEventLoop, ControlFlow, EventLoop}; -use winit::keyboard::{KeyCode, PhysicalKey}; -use winit::window::{Window, WindowButtons, WindowId}; +use winit::keyboard::KeyCode; +use winit::window::WindowId; impl<'a> ApplicationHandler for State<'a> { fn resumed(&mut self, event_loop: &ActiveEventLoop) { @@ -50,7 +48,7 @@ impl<'a> ApplicationHandler for State<'a> { } WindowEvent::RedrawRequested => { self.update(); - self.render(); + self.render().expect("Render Error!"); // self.try_exec_single_instr_from_console().inspect_err( // |e| { // error!("err when try_exec_single_instr_from_console {e:?}")