Skip to content

Commit

Permalink
allow warnings and repair some of the warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
BreakingLead committed May 30, 2024
1 parent 208affc commit 5d3ff4f
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 51 deletions.
12 changes: 6 additions & 6 deletions blockworld-client/game/chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
10 changes: 5 additions & 5 deletions blockworld-client/game/console_instr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ impl ConsoleInstr {
let args_clean = &args_str[1..args_str.len() - 1];
let args: Vec<String> = 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<u64> = 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;
Expand All @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions blockworld-client/game/player_state.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion blockworld-client/game/register.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;

use anyhow::Error;
use glam::{IVec2, Vec2};

use block::{BlockID, BlockMeta};

Expand Down
9 changes: 5 additions & 4 deletions blockworld-client/game/save.rs
Original file line number Diff line number Diff line change
@@ -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<IVec2, Chunk>,
}
Expand All @@ -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"))
Expand Down
4 changes: 2 additions & 2 deletions blockworld-client/io/atlas_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down
1 change: 0 additions & 1 deletion blockworld-client/io/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pub mod assets_reader;
pub mod atlas_helper;
pub mod input_helper;
6 changes: 4 additions & 2 deletions blockworld-client/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use anyhow::*;
use clap::Parser;

mod debug;
Expand All @@ -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(())
}
4 changes: 2 additions & 2 deletions blockworld-client/render/render_block.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use glam::{vec3, Vec2, Vec3};
use glam::*;

use crate::io::atlas_helper::AtlasCoordinate;

Expand Down Expand Up @@ -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);
Expand Down
16 changes: 6 additions & 10 deletions blockworld-client/render/render_chunk.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -19,9 +15,9 @@ pub struct RenderChunk {
impl RenderChunk {
pub fn new(device: &Device, chunk: &Chunk, register_table: &RegisterTable) -> Self {
let mut vertices: Vec<Vertex> = 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,
Expand Down
5 changes: 0 additions & 5 deletions blockworld-client/render/texture.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 0 additions & 2 deletions blockworld-client/render/vertex.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use glam::Vec3;

#[repr(C)]
#[derive(Copy, Clone, Debug, bytemuck::Zeroable, bytemuck::Pod)]
pub struct Vertex {
Expand Down
12 changes: 5 additions & 7 deletions blockworld-client/render/window_init.rs
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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:?}")
Expand Down

0 comments on commit 5d3ff4f

Please sign in to comment.