Skip to content

Commit 8559ddc

Browse files
committed
clippy and cargo fix
1 parent 3923015 commit 8559ddc

File tree

16 files changed

+93
-107
lines changed

16 files changed

+93
-107
lines changed

src/blocks/block.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,18 @@ impl FaceDirections {
7878

7979
unique_indices.iter().enumerate().for_each(|(i, index)| {
8080
let vertex_position = glam::vec3(
81-
CUBE_VERTEX[(*index as usize * 3 + 0) as usize] + block_read.absolute_position.x,
82-
CUBE_VERTEX[(*index as usize * 3 + 1) as usize] + block_read.absolute_position.y,
83-
CUBE_VERTEX[(*index as usize * 3 + 2) as usize] + block_read.absolute_position.z,
81+
CUBE_VERTEX[*index as usize * 3_usize] + block_read.absolute_position.x,
82+
CUBE_VERTEX[*index as usize * 3 + 1] + block_read.absolute_position.y,
83+
CUBE_VERTEX[*index as usize * 3 + 2] + block_read.absolute_position.z,
8484
);
8585

8686
vertex_data.push(BlockVertexData {
8787
position: [
88-
CUBE_VERTEX[(*index as usize * 3 + 0) as usize] + block_read.position.x,
89-
CUBE_VERTEX[(*index as usize * 3 + 1) as usize] + block_read.position.y,
90-
CUBE_VERTEX[(*index as usize * 3 + 2) as usize] + block_read.position.z,
88+
CUBE_VERTEX[*index as usize * 3_usize] + block_read.position.x,
89+
CUBE_VERTEX[*index as usize * 3 + 1] + block_read.position.y,
90+
CUBE_VERTEX[*index as usize * 3 + 2] + block_read.position.z,
9191
],
92-
ao: convert_ao_u8_to_f32(from_vertex_position(&vertex_position, &blocks)),
92+
ao: convert_ao_u8_to_f32(from_vertex_position(&vertex_position, blocks)),
9393
normal: normals.into(),
9494
tex_coords: face_texcoords[i],
9595
})
@@ -144,19 +144,19 @@ impl Block {
144144
if self.position.z == 0.0 {
145145
neighbour_chunks.push((chunk.0, chunk.1 - 1));
146146
}
147-
return neighbour_chunks;
147+
neighbour_chunks
148148
}
149149
pub fn is_on_chunk_border(&self) -> bool {
150-
return self.position.x == 0.0
150+
self.position.x == 0.0
151151
|| self.position.x == 15.0
152152
|| self.position.z == 0.0
153-
|| self.position.z == 15.0;
153+
|| self.position.z == 15.0
154154
}
155155
pub fn get_chunk_coords(&self) -> (i32, i32) {
156-
return (
156+
(
157157
(f32::floor(self.absolute_position.x / CHUNK_SIZE as f32)) as i32,
158158
(f32::floor(self.absolute_position.z / CHUNK_SIZE as f32)) as i32,
159-
);
159+
)
160160
}
161161
pub fn get_vertex_data_layout() -> wgpu::VertexBufferLayout<'static> {
162162
wgpu::VertexBufferLayout {

src/blocks/block_type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn get_base_coords(config: &BlockTypeConfigs, face_dir: FaceDirections) -> glam:
144144

145145
let low_bound = y_offset * BLOCK_OFFSET_NORMALIZED + BLOCK_OFFSET_NORMALIZED;
146146
let left_bound = x_offset * BLOCK_OFFSET_NORMALIZED;
147-
return glam::vec2(left_bound, low_bound);
147+
glam::vec2(left_bound, low_bound)
148148
}
149149
fn get_tex_coords(config: &BlockTypeConfigs, face_dir: FaceDirections) -> [[f32; 2]; 4] {
150150
let bc = get_base_coords(config, face_dir);

src/chunk.rs

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ impl Chunk {
7373
pub fn block_type_at(&self, position: &glam::Vec3) -> Option<BlockType> {
7474
let block = self.get_block_at_relative(position)?;
7575
let block_type = block.read().unwrap().block_type;
76-
Some(block_type.clone())
76+
Some(block_type)
7777
}
7878
pub fn exists_block_at(&self, position: &glam::Vec3) -> bool {
7979
if let Some(y_blocks) = self
@@ -83,12 +83,12 @@ impl Chunk {
8383
.get(((position.x as u32 * CHUNK_SIZE) + position.z as u32) as usize)
8484
{
8585
if let Some(block_opt) = y_blocks.get(position.y as usize) {
86-
if let Some(_) = block_opt {
86+
if block_opt.is_some() {
8787
return true;
8888
}
8989
}
9090
}
91-
return false;
91+
false
9292
}
9393
pub fn get_block_at_relative(&self, position: &glam::Vec3) -> Option<Arc<RwLock<Block>>> {
9494
if let Some(y_blocks) = self
@@ -101,25 +101,15 @@ impl Chunk {
101101
return Some(Arc::clone(block));
102102
}
103103
}
104-
return None;
104+
None
105105
}
106106
pub fn is_outside_chunk(position: &glam::Vec3) -> bool {
107-
if position.x < 0.0
107+
position.x < 0.0
108108
|| position.x >= CHUNK_SIZE as f32
109-
|| position.z < 0.0
110-
|| position.z >= CHUNK_SIZE as f32
111-
{
112-
true
113-
} else {
114-
false
115-
}
109+
|| position.z < 0.0 || position.z >= CHUNK_SIZE as f32
116110
}
117111
pub fn is_outside_bounds(position: &glam::Vec3) -> bool {
118-
if position.y < 0.0 {
119-
true
120-
} else {
121-
false
122-
}
112+
position.y < 0.0
123113
}
124114
/*
125115
Return tuple:
@@ -333,9 +323,9 @@ impl Chunk {
333323
}
334324
if let Some(v) = noise_data.get((z * (NOISE_SIZE as i32) + x) as usize) {
335325
let y_top = (v + 1.0) * 0.5;
336-
return (f32::powf(100.0, y_top) - 1.0) as u32;
326+
(f32::powf(100.0, y_top) - 1.0) as u32
337327
} else {
338-
return 0;
328+
0
339329
}
340330
}
341331

@@ -370,7 +360,7 @@ impl Chunk {
370360
}
371361
// Fill with water empty blocks
372362
for y in curr.len()..=(WATER_HEIGHT_LEVEL as usize) {
373-
if let None = curr.get(y) {
363+
if curr.get(y).is_none() {
374364
let block = Arc::new(RwLock::new(Block::new(
375365
glam::vec3(x as f32, y as f32, z as f32),
376366
(chunk_x, chunk_y),
@@ -416,7 +406,7 @@ impl Chunk {
416406
{
417407
continue;
418408
}
419-
let highest_block_position = highest_block.absolute_position.clone();
409+
let highest_block_position = highest_block.absolute_position;
420410

421411
tree_blocks.append(&mut crate::structures::Tree::get_blocks(
422412
highest_block_position,
@@ -549,13 +539,13 @@ impl Chunk {
549539
if !was_loaded {
550540
chunk.place_trees();
551541
}
552-
return chunk;
542+
chunk
553543
}
554544
}
555545

556546
impl Saveable<Chunk> for Chunk {
557547
fn save(&self) -> Result<(), Box<dyn Error>> {
558-
if let Ok(_) = std::fs::create_dir("data") {
548+
if std::fs::create_dir("data").is_ok() {
559549
println!("Created dir");
560550
}
561551
let mut data = String::new();
@@ -591,10 +581,10 @@ impl Loadable<BlockVec> for Chunk {
591581
let mut coords = filename_chunk
592582
.to_str()
593583
.unwrap()
594-
.split("k")
584+
.split('k')
595585
.last()
596586
.expect("Invalid filename")
597-
.split("_");
587+
.split('_');
598588
let x = coords.next().unwrap().parse::<i32>()?;
599589
let y = coords.next().unwrap().parse::<i32>()?;
600590

@@ -603,7 +593,7 @@ impl Loadable<BlockVec> for Chunk {
603593
if *chunk_position == (x, y) {
604594
let file_contents = std::fs::read_to_string(format!("data/chunk{}_{}", x, y))?;
605595
for line in file_contents.lines() {
606-
let mut i = line.split(",");
596+
let mut i = line.split(',');
607597
let bx = i.next().unwrap().parse::<u32>()?;
608598
let by = i.next().unwrap().parse::<u32>()?;
609599
let bz = i.next().unwrap().parse::<u32>()?;
@@ -630,6 +620,6 @@ impl Loadable<BlockVec> for Chunk {
630620
}
631621
}
632622
}
633-
return Err("Not valid args".into());
623+
Err("Not valid args".into())
634624
}
635625
}

src/collision.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ impl Ray {
7878
tmax = tzmax;
7979
}
8080

81-
return Some(vec![
81+
Some(vec![
8282
self.origin + self.direction * tmin,
8383
self.origin + self.direction * tmax,
84-
]);
84+
])
8585
}
8686
}
8787

@@ -116,7 +116,7 @@ impl CollisionBox {
116116
}
117117
}
118118
pub fn to_block_position(&self) -> glam::Vec3 {
119-
return glam::vec3(self.min_x, self.min_y, self.min_z);
119+
glam::vec3(self.min_x, self.min_y, self.min_z)
120120
}
121121
pub fn new(x: f32, y: f32, z: f32, width: f32, height: f32, depth: f32) -> CollisionBox {
122122
CollisionBox {
@@ -129,20 +129,20 @@ impl CollisionBox {
129129
}
130130
}
131131
pub fn intersects_point(&self, point: &CollisionPoint) -> bool {
132-
return point.x >= self.min_x
132+
point.x >= self.min_x
133133
&& point.x <= self.max_x
134134
&& point.y >= self.min_y
135135
&& point.y <= self.max_y
136136
&& point.z >= self.min_z
137-
&& point.z <= self.max_z;
137+
&& point.z <= self.max_z
138138
}
139139
pub fn intersects(&self, other: &CollisionBox) -> bool {
140-
return self.min_x <= other.max_x
140+
self.min_x <= other.max_x
141141
&& self.max_x >= other.min_x
142142
&& self.min_y <= other.max_y
143143
&& self.max_y >= other.min_y
144144
&& self.min_z <= other.max_z
145-
&& self.max_z >= other.min_z;
145+
&& self.max_z >= other.min_z
146146
}
147147
pub fn intersects_direction() {
148148
todo!()

src/effects.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ pub mod ao {
99
if side1 && side2 {
1010
return 0;
1111
}
12-
return 3 - (side1 as u8 + side2 as u8 + up as u8);
12+
3 - (side1 as u8 + side2 as u8 + up as u8)
1313
}
1414
pub(crate) fn from_vertex_position(
1515
vertex_position: &glam::Vec3,
@@ -55,7 +55,7 @@ pub mod ao {
5555
}
5656
}
5757
}
58-
return calc_vertex_ao(has_side1, has_side2, has_corner);
58+
calc_vertex_ao(has_side1, has_side2, has_corner)
5959
}
6060
// ao -> 1 (max)
6161
// ao -> 0 (min)

src/material.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ impl Texture {
7777

7878
let data: Vec<_> = perlin_noise_data
7979
.iter()
80-
.map(|v| {
80+
.flat_map(|v| {
8181
let u = f32::round((v + 1.0) * 0.5 * 255.0) as u8;
8282
[u, u, u, 255]
8383
})
84-
.flatten()
8584
.collect();
8685

8786
state.queue.write_texture(
@@ -91,7 +90,7 @@ impl Texture {
9190
mip_level: 0,
9291
origin: wgpu::Origin3d::ZERO,
9392
},
94-
&data.as_slice(),
93+
data.as_slice(),
9594
wgpu::ImageDataLayout {
9695
offset: 0,
9796
bytes_per_row: Some(4 * width),
@@ -148,7 +147,7 @@ impl Texture {
148147
mip_level: 0,
149148
origin: wgpu::Origin3d::ZERO,
150149
},
151-
&rgba,
150+
rgba,
152151
wgpu::ImageDataLayout {
153152
offset: 0,
154153
bytes_per_row: Some(4 * dimensions.0),
@@ -206,7 +205,7 @@ impl Texture {
206205
mip_level: 0,
207206
origin: wgpu::Origin3d::ZERO,
208207
},
209-
&rgba,
208+
rgba,
210209
wgpu::ImageDataLayout {
211210
offset: 0,
212211
bytes_per_row: Some(4 * dimensions.0),

src/pipelines/highlight_selected.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ impl Pipeline for HighlightSelectedPipeline {
1616
view: &wgpu::TextureView,
1717
_player: &std::sync::RwLockReadGuard<'_, Player>,
1818
_chunks: &Vec<std::sync::RwLockReadGuard<'_, crate::chunk::Chunk>>,
19-
) -> () {
19+
) {
2020
let main_pipeline_ref = state
2121
.pipeline_manager
2222
.main_pipeline

src/pipelines/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ impl Pipeline for MainPipeline {
2424
view: &wgpu::TextureView,
2525
player: &std::sync::RwLockReadGuard<'_, Player>,
2626
chunks: &Vec<std::sync::RwLockReadGuard<'_, crate::chunk::Chunk>>,
27-
) -> () {
27+
) {
2828
let mut main_rpass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
2929
label: None,
3030
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
31-
view: &view,
31+
view,
3232
resolve_target: None,
3333
ops: wgpu::Operations {
3434
load: wgpu::LoadOp::Clear(wgpu::Color {

src/pipelines/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub trait Pipeline {
2121
view: &wgpu::TextureView,
2222
player: &RwLockReadGuard<'_, Player>,
2323
chunks: &Vec<RwLockReadGuard<'_, Chunk>>,
24-
) -> ();
24+
);
2525
}
2626
mod highlight_selected;
2727
mod main;

src/pipelines/pipeline_manager.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ pub struct PipelineManager {
1919
impl PipelineManager {
2020
pub fn render(
2121
&self,
22-
encoder: &mut CommandEncoder,
23-
view: &TextureView,
24-
main_pipeline: &MainPipeline,
22+
_encoder: &mut CommandEncoder,
23+
_view: &TextureView,
24+
_main_pipeline: &MainPipeline,
2525
) {
2626
todo!();
2727
}
@@ -39,31 +39,31 @@ impl PipelineManager {
3939
state, &pipeline,
4040
)));
4141
pipeline.ui_pipeline = Some(RefCell::new(UIPipeline::init(state, &pipeline)));
42-
return pipeline;
42+
pipeline
4343
}
4444

4545
pub fn update(&self, state: &State) -> Result<(), Box<dyn std::error::Error>> {
4646
self.main_pipeline
4747
.as_ref()
4848
.unwrap()
4949
.borrow_mut()
50-
.update(&self, state)?;
50+
.update(self, state)?;
5151
self.translucent_pipeline
5252
.as_ref()
5353
.unwrap()
5454
.borrow_mut()
55-
.update(&self, state)?;
55+
.update(self, state)?;
5656
self.highlight_selected_pipeline
5757
.as_ref()
5858
.unwrap()
5959
.borrow_mut()
60-
.update(&self, state)?;
60+
.update(self, state)?;
6161
self.ui_pipeline
6262
.as_ref()
6363
.unwrap()
6464
.borrow_mut()
65-
.update(&self, state)?;
65+
.update(self, state)?;
6666

67-
return Ok(());
67+
Ok(())
6868
}
6969
}

0 commit comments

Comments
 (0)