Skip to content

Commit 1930fae

Browse files
committed
cleanup
1 parent 63ba5d0 commit 1930fae

File tree

8 files changed

+27
-83
lines changed

8 files changed

+27
-83
lines changed

src/chunk.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
use crate::blocks::block_type::BlockType::Water;
21
use crate::persistence::{Loadable, Saveable};
32
use crate::player::Player;
43
use crate::utils::math_utils::Plane;
5-
use crate::world::{ChunkMap, WorldChunk, RNG_SEED, WATER_HEIGHT_LEVEL};
4+
use crate::world::{ChunkMap, RNG_SEED, WATER_HEIGHT_LEVEL};
65
use crate::{
76
blocks::{
87
block::{Block, BlockVertexData, FaceDirections},
@@ -11,15 +10,12 @@ use crate::{
1110
structures::Structure,
1211
world::{NoiseData, CHUNK_SIZE, MAX_TREES_PER_CHUNK, NOISE_CHUNK_PER_ROW, NOISE_SIZE},
1312
};
13+
1414
use glam::Vec3;
1515
use rand::rngs::StdRng;
1616
use rand::{Rng, SeedableRng};
1717
use std::any::Any;
18-
use std::cell::RefCell;
19-
use std::collections::HashMap;
2018
use std::error::Error;
21-
use std::io::{self, BufReader, Read};
22-
use std::rc::Rc;
2319
use std::sync::{Arc, RwLock};
2420
use wgpu::util::DeviceExt;
2521

src/effects.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
pub mod ao {
22
use crate::blocks::block_type::BlockType;
33
use crate::chunk::BlockVec;
4-
use crate::perf;
54
use crate::utils::{ChunkFromPosition, RelativeFromAbsolute};
65
use crate::world::CHUNK_SIZE;
7-
use glam::vec3;
8-
use std::time::Instant;
96

107
// https://0fps.net/2013/07/03/ambient-occlusion-for-minecraft-like-worlds/
118
pub(crate) fn calc_vertex_ao(side1: bool, side2: bool, up: bool) -> u8 {

src/main.rs

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
1-
use std::sync::{Arc, Mutex};
2-
use std::{
3-
fs::File,
4-
io::BufReader,
5-
mem,
6-
ops::ControlFlow,
7-
process::exit,
8-
time::{Duration, Instant},
9-
};
10-
11-
use bytemuck::{Pod, Zeroable};
12-
use glam::vec2;
13-
use material::Texture;
14-
use player::CameraController;
151
use state::State;
16-
use tobj::{load_obj, load_obj_buf, LoadOptions};
17-
use winit::keyboard::KeyCode;
2+
use std::sync::{Arc, Mutex};
3+
use std::time::Instant;
184
use winit::window::CursorGrabMode;
195
use winit::{
20-
dpi::{PhysicalPosition, PhysicalSize},
6+
dpi::PhysicalSize,
217
event::*,
228
event_loop::EventLoop,
23-
keyboard::{Key, NamedKey, PhysicalKey},
9+
keyboard::{Key, NamedKey},
2410
window::Window,
2511
};
2612

src/material.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
use image::{error::DecodingError, GenericImageView, ImageError};
2-
31
use crate::{state::State, utils::noise::perlin_noise};
2+
use image::GenericImageView;
43

54
impl Texture {
65
pub const DEPTH_FORMAT: wgpu::TextureFormat = wgpu::TextureFormat::Depth32Float;

src/pipeline.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,5 @@
1-
use std::fs::File;
2-
use std::io::Read;
3-
use std::{cell::RefCell, rc::Rc};
4-
1+
use crate::player::Camera;
52
use bytemuck::{Pod, Zeroable};
6-
use obj::Vertex;
7-
use wgpu::{include_wgsl, util::DeviceExt, BindGroup, Buffer, Face, RenderPipeline};
8-
9-
use crate::{
10-
blocks::block::Block,
11-
material::{Material, Texture},
12-
player::Camera,
13-
state::State,
14-
};
153

164
#[repr(C)]
175
#[derive(Copy, Clone, Debug, PartialEq, Pod, Zeroable)]

src/state.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1+
use std::sync::Arc;
12
use std::sync::{Mutex, RwLock};
2-
use std::time::Instant;
3-
use std::{f32::consts, sync::Arc};
3+
use winit::event::MouseButton;
4+
use winit::window::CursorGrabMode;
5+
use winit::{
6+
dpi::PhysicalSize,
7+
event::KeyEvent,
8+
keyboard::{KeyCode, PhysicalKey},
9+
window::Window,
10+
};
411

512
use crate::blocks::block::Block;
613
use crate::blocks::block_type::BlockType;
7-
use crate::collision::CollisionBox;
8-
use crate::perf;
914
use crate::persistence::Saveable;
1015
use crate::pipelines::pipeline_manager::PipelineManager;
1116
use crate::pipelines::Pipeline;
1217
use crate::utils::{ChunkFromPosition, RelativeFromAbsolute};
1318
use crate::{
1419
material::Texture,
15-
pipeline::{self, Uniforms},
20+
pipeline::Uniforms,
1621
player::{Camera, CameraController, Player},
1722
world::World,
1823
};
19-
use winit::event::MouseButton;
20-
use winit::window::CursorGrabMode;
21-
use winit::{
22-
dpi::PhysicalSize,
23-
event::KeyEvent,
24-
keyboard::{KeyCode, PhysicalKey},
25-
window::Window,
26-
};
2724

2825
pub struct State {
2926
pub surface: wgpu::Surface,

src/utils.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
use crate::world::CHUNK_SIZE;
22
use glam::{vec3, Vec3};
3-
use num_traits::FromPrimitive;
43

5-
fn fade(t: f32) -> f32 {
6-
((6.0 * t - 15.) * t + 10.) * t * t * t
7-
}
8-
fn lerp(a: f32, b: f32, t: f32) -> f32 {
9-
a + ((b - a) * t)
10-
}
114
pub(crate) mod math_utils {
125
#[derive(Debug)]
136
pub struct Plane {
@@ -25,7 +18,6 @@ pub(crate) mod noise {
2518

2619
use crate::world::RNG_SEED;
2720

28-
use super::*;
2921
use glam::Vec2;
3022

3123
const WRAP: u32 = 256;

src/world.rs

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,15 @@
1+
use crate::blocks::block_type::BlockType;
2+
use crate::persistence::Saveable;
3+
use crate::utils::{ChunkFromPosition, RelativeFromAbsolute};
4+
use crate::{blocks::block::Block, chunk::Chunk, player::Player, utils::threadpool::ThreadPool};
15
use glam::Vec3;
26
use std::borrow::Borrow;
37
use std::collections::HashMap;
4-
use std::fs::File;
5-
use std::ops::{Deref, DerefMut};
6-
use std::sync::{Mutex, RwLock};
8+
use std::sync::RwLock;
79
use std::{
810
sync::{mpsc, Arc},
911
thread,
1012
};
11-
use wgpu::util::DeviceExt;
12-
use wgpu::BindGroupEntry;
13-
14-
use crate::blocks::block_type::BlockType;
15-
use crate::persistence::Saveable;
16-
use crate::utils::{ChunkFromPosition, RelativeFromAbsolute};
17-
use crate::{blocks::block::Block, chunk::Chunk, player::Player, utils::threadpool::ThreadPool};
1813

1914
pub const RNG_SEED: u64 = 0;
2015
pub const CHUNK_SIZE: u32 = 16;
@@ -23,14 +18,11 @@ pub const NOISE_SIZE: u32 = 1024;
2318
pub const FREQUENCY: f32 = 1. / 128.;
2419
pub const NOISE_CHUNK_PER_ROW: u32 = NOISE_SIZE / CHUNK_SIZE;
2520
pub const MAX_TREES_PER_CHUNK: u32 = 3;
26-
2721
pub const CHUNKS_PER_ROW: u32 = 20;
2822
pub const CHUNKS_REGION: u32 = CHUNKS_PER_ROW * CHUNKS_PER_ROW;
2923
pub const WATER_HEIGHT_LEVEL: u8 = 5;
30-
3124
// Lower bound of chunk
3225
pub const LB: i32 = -((CHUNKS_PER_ROW / 2) as i32);
33-
3426
// Upper bound of chunk
3527
pub const UB: i32 = if CHUNKS_PER_ROW % 2 == 0 {
3628
(CHUNKS_PER_ROW / 2 - 1) as i32
@@ -39,7 +31,6 @@ pub const UB: i32 = if CHUNKS_PER_ROW % 2 == 0 {
3931
};
4032

4133
pub type NoiseData = Vec<f32>;
42-
4334
pub type WorldChunk = Arc<RwLock<Chunk>>;
4435
pub type ChunkMap = Arc<RwLock<HashMap<(i32, i32), WorldChunk>>>;
4536

@@ -172,10 +163,8 @@ impl World {
172163
current_chunk.0 - player_write.current_chunk.0,
173164
current_chunk.1 - player_write.current_chunk.1,
174165
);
175-
176166
let o = if CHUNKS_PER_ROW % 2 == 0 { 1 } else { 0 };
177167
let p = CHUNKS_PER_ROW as i32 / 2;
178-
179168
let new_chunks_offset = if delta.1 > 0 || delta.0 > 0 {
180169
p - o
181170
} else {
@@ -188,9 +177,9 @@ impl World {
188177
};
189178

190179
let mut new_chunks_positions: Vec<(i32, i32)> = vec![];
191-
192180
let chunk_y_remove = player_write.current_chunk.1 + old_chunks_offset;
193181
let chunk_x_remove = player_write.current_chunk.0 + old_chunks_offset;
182+
194183
if delta.0 != 0 {
195184
for i in LB + current_chunk.1..=UB + current_chunk.1 {
196185
new_chunks_positions.push((current_chunk.0 + new_chunks_offset, i));
@@ -243,9 +232,9 @@ impl World {
243232
})
244233
}
245234

246-
// for _ in keys_to_remove.iter() {
247-
// receiver.recv().unwrap();
248-
// }
235+
for _ in keys_to_remove.iter() {
236+
receiver.recv().unwrap();
237+
}
249238

250239
let chunks_added = new_chunks_positions.len();
251240
let (sender, receiver) = mpsc::channel();

0 commit comments

Comments
 (0)