Skip to content

Commit 190a1ff

Browse files
committed
cleanups
1 parent 6e3bf55 commit 190a1ff

File tree

13 files changed

+34
-172
lines changed

13 files changed

+34
-172
lines changed

src/blocks/block.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use bytemuck::{Pod, Zeroable};
2-
use std::collections::HashMap;
32

43
use super::block_type::BlockType;
54
use crate::chunk::BlockVec;
65
use crate::collision::CollisionBox;
76
use crate::effects::ao::{convert_ao_u8_to_f32, from_vertex_position};
87
use crate::world::CHUNK_SIZE;
98
use glam::Vec3;
10-
use std::sync::{Arc, MutexGuard, RwLock};
9+
use std::sync::{Arc, RwLock};
1110

1211
#[derive(Debug)]
1312
pub struct Block {

src/blocks/block_type.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
use rand::{random, rngs::StdRng, Rng, SeedableRng};
2-
use std::any::Any;
3-
4-
use crate::world::{RNG_SEED, WATER_HEIGHT_LEVEL};
5-
61
use super::block::{FaceDirections, TexturedBlock};
2+
use crate::world::{RNG_SEED, WATER_HEIGHT_LEVEL};
3+
use rand::{rngs::StdRng, Rng, SeedableRng};
74

85
#[derive(Clone, Copy, Debug)]
96
// This can be 1, 2 [because sometimes we want to reuse the same texture for the bottom as the top]

src/effects.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -62,52 +62,4 @@ pub mod ao {
6262
pub(crate) fn convert_ao_u8_to_f32(ao: u8) -> f32 {
6363
1.0 - (ao as f32 / 3.0)
6464
}
65-
66-
mod test {
67-
use super::*;
68-
use crate::blocks::block::Block;
69-
use crate::blocks::block_type::BlockType;
70-
use std::sync::{Arc, RwLock};
71-
72-
// #[test]
73-
// fn should_calculate_the_correct_ao() {
74-
// let vertex_position = vec3(0.5, 0.5, 0.5); // Belongs to voxel 0,0,0
75-
// let block_vec: BlockVec = Arc::new(RwLock::new(vec![
76-
// vec![];
77-
// (CHUNK_SIZE * CHUNK_SIZE) as usize
78-
// ]));
79-
// let neighbour_voxels = [vec3(1.0, 1.0, 0.0), vec3(1.0, 1.0, 1.0)];
80-
// for voxel in &neighbour_voxels {
81-
// let mut block_write = block_vec.write().unwrap();
82-
// let region = &mut block_write[((voxel.x * CHUNK_SIZE as f32) + voxel.z) as usize];
83-
84-
// for _ in region.len()..=voxel.y as usize {
85-
// region.push(None);
86-
// }
87-
88-
// region[voxel.y as usize] = Some(Arc::new(RwLock::new(Block::new(
89-
// voxel.clone(),
90-
// voxel.get_chunk_from_position_absolute(),
91-
// BlockType::dirt(),
92-
// ))));
93-
// }
94-
// let chunk_blocks = vec![((0, 0), block_vec)];
95-
96-
// let vao = from_vertex_position(&vertex_position, &chunk_blocks);
97-
98-
// assert_eq!(vao, 1);
99-
100-
// let vertex_position = vec3(0.5, 0.5, -0.5); // Belongs to voxel 0,0,0
101-
102-
// let vao = from_vertex_position(&vertex_position, &chunk_blocks);
103-
104-
// assert_eq!(vao, 2);
105-
106-
// let vertex_position = vec3(-5.5, 5.5, -0.5); // Belongs to voxel 0,0,0
107-
108-
// let vao = from_vertex_position(&vertex_position, &chunk_blocks);
109-
110-
// assert_eq!(vao, 3);
111-
// }
112-
}
11365
}

src/main.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use std::time::Instant;
88
use winit::dpi::LogicalSize;
99
use winit::window::CursorGrabMode;
1010
use winit::{
11-
dpi::PhysicalSize,
1211
event::*,
1312
event_loop::EventLoop,
1413
keyboard::{Key, NamedKey},
@@ -83,9 +82,7 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
8382
target.exit();
8483
}
8584

86-
WindowEvent::KeyboardInput { event, .. } => {
87-
state.handle_keypress(event, delta_time.as_secs_f32())
88-
}
85+
WindowEvent::KeyboardInput { event, .. } => state.handle_keypress(event),
8986
WindowEvent::MouseInput {
9087
state: ElementState::Pressed,
9188
button,
@@ -122,10 +119,10 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
122119

123120
if first_render {
124121
// Don't do calcs based on delta time on first render
125-
state.update(0.0, 0.0);
122+
state.update(0.0);
126123
first_render = false;
127124
} else {
128-
state.update(delta_time.as_secs_f32(), total_time.as_secs_f32());
125+
state.update(delta_time.as_secs_f32());
129126
}
130127
state.draw();
131128
window.lock().unwrap().request_redraw();

src/pipelines/highlight_selected.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
use std::sync::{Arc, RwLock};
2-
31
use crate::{blocks::block::FaceDirections, material::Texture, player::Player, state::State};
42

5-
use super::{pipeline_manager::PipelineManager, translucent::Water, Pipeline};
3+
use super::{pipeline_manager::PipelineManager, Pipeline};
64

75
pub struct HighlightSelectedPipeline {
86
pub pipeline: wgpu::RenderPipeline,
@@ -16,8 +14,8 @@ impl Pipeline for HighlightSelectedPipeline {
1614
state: &State,
1715
encoder: &mut wgpu::CommandEncoder,
1816
view: &wgpu::TextureView,
19-
player: &std::sync::RwLockReadGuard<'_, Player>,
20-
chunks: &Vec<std::sync::RwLockReadGuard<'_, crate::chunk::Chunk>>,
17+
_player: &std::sync::RwLockReadGuard<'_, Player>,
18+
_chunks: &Vec<std::sync::RwLockReadGuard<'_, crate::chunk::Chunk>>,
2119
) -> () {
2220
let main_pipeline_ref = state
2321
.pipeline_manager

src/pipelines/main.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use std::sync::{Arc, RwLock};
2-
31
use wgpu::Face;
42

53
use crate::{
@@ -21,7 +19,7 @@ pub struct MainPipeline {
2119
impl Pipeline for MainPipeline {
2220
fn render(
2321
&self,
24-
state: &State,
22+
_state: &State,
2523
encoder: &mut wgpu::CommandEncoder,
2624
view: &wgpu::TextureView,
2725
player: &std::sync::RwLockReadGuard<'_, Player>,
@@ -84,15 +82,12 @@ impl Pipeline for MainPipeline {
8482

8583
fn update(
8684
&mut self,
87-
pipeline_manager: &PipelineManager,
88-
// player: Arc<RwLock<Player>>,
89-
state: &State, // queue: Arc<wgpu::Queue>,
90-
// device: Arc<wgpu::Device>,
91-
// surface_configuration: &wgpu::SurfaceConfiguration,
85+
_pipeline_manager: &PipelineManager,
86+
_state: &State,
9287
) -> Result<(), Box<dyn std::error::Error>> {
9388
Ok(())
9489
}
95-
fn init(state: &State, pipeline_manager: &PipelineManager) -> Self {
90+
fn init(state: &State, _pipeline_manager: &PipelineManager) -> Self {
9691
let swapchain_capabilities = state.surface.get_capabilities(&state.adapter);
9792
let swapchain_format = swapchain_capabilities.formats[0];
9893

src/pipelines/mod.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use std::{
2-
error::Error,
3-
sync::{Arc, RwLock, RwLockReadGuard},
4-
};
1+
use std::{error::Error, sync::RwLockReadGuard};
52

63
use self::pipeline_manager::PipelineManager;
74
use crate::{chunk::Chunk, player::Player, state::State};

src/pipelines/pipeline_manager.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
1-
use std::{
2-
cell::RefCell,
3-
sync::{Arc, RwLock},
4-
};
1+
use std::cell::RefCell;
52

63
use wgpu::{CommandEncoder, TextureView};
74

8-
use crate::{player::Player, state::State};
5+
use crate::state::State;
96

107
use super::{
118
highlight_selected::HighlightSelectedPipeline, main::MainPipeline,
@@ -26,6 +23,7 @@ impl PipelineManager {
2623
view: &TextureView,
2724
main_pipeline: &MainPipeline,
2825
) {
26+
todo!();
2927
}
3028
pub fn init(state: &State) -> PipelineManager {
3129
let mut pipeline = PipelineManager {

src/pipelines/translucent.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,12 @@
1-
use std::sync::{Arc, RwLock, RwLockReadGuard};
1+
use std::sync::RwLockReadGuard;
22

3-
use crate::blocks::block::{Block, FaceDirections};
3+
use super::pipeline_manager::PipelineManager;
4+
use super::Pipeline;
5+
use crate::blocks::block::Block;
46
use crate::chunk::Chunk;
57
use crate::material::Texture;
6-
use crate::pipeline::Uniforms;
78
use crate::player::Player;
89
use crate::state::State;
9-
use wgpu::util::DeviceExt;
10-
use wgpu::{
11-
BindGroup, BindGroupEntry, BindGroupLayoutEntry, Buffer, BufferUsages, CommandEncoder,
12-
RenderPipeline,
13-
};
14-
15-
use super::main::MainPipeline;
16-
use super::pipeline_manager::PipelineManager;
17-
use super::Pipeline;
1810

1911
pub struct Water;
2012
impl Water {
@@ -29,11 +21,7 @@ impl Pipeline for TranslucentPipeline {
2921
fn update(
3022
&mut self,
3123
_pipeline_manager: &PipelineManager,
32-
state: &State,
33-
// player: Arc<RwLock<Player>>,
34-
// queue: Arc<wgpu::Queue>,
35-
// _device: Arc<wgpu::Device>,
36-
// _surface_config: &wgpu::SurfaceConfiguration,
24+
_state: &State,
3725
) -> Result<(), Box<dyn std::error::Error>> {
3826
Ok(())
3927
}

src/pipelines/ui.rs

Lines changed: 5 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
1-
use crate::blocks;
21
use crate::blocks::block::{FaceDirections, TexturedBlock};
32
use crate::material::Texture;
4-
use crate::pipeline::Uniforms;
53
use crate::player::Player;
64
use crate::state::State;
7-
use std::borrow::Borrow;
8-
use std::collections::HashMap;
9-
use std::sync::{Arc, Mutex, RwLock};
105
use wgpu::util::DeviceExt;
11-
use wgpu::{BindGroup, Buffer, BufferUsages, RenderPipeline};
6+
use wgpu::BufferUsages;
127

138
use super::pipeline_manager::PipelineManager;
149
use super::Pipeline;
@@ -24,8 +19,8 @@ impl Pipeline for UIPipeline {
2419
state: &State,
2520
encoder: &mut wgpu::CommandEncoder,
2621
view: &wgpu::TextureView,
27-
player: &std::sync::RwLockReadGuard<'_, Player>,
28-
chunks: &Vec<std::sync::RwLockReadGuard<'_, crate::chunk::Chunk>>,
22+
_player: &std::sync::RwLockReadGuard<'_, Player>,
23+
_chunks: &Vec<std::sync::RwLockReadGuard<'_, crate::chunk::Chunk>>,
2924
) -> () {
3025
let main_pipeline_ref = state
3126
.pipeline_manager
@@ -145,11 +140,8 @@ impl Pipeline for UIPipeline {
145140
}
146141
fn update(
147142
&mut self,
148-
pipeline_manager: &PipelineManager,
149-
state: &State, // player: Arc<RwLock<Player>>,
150-
// queue: Arc<wgpu::Queue>,
151-
// device: Arc<wgpu::Device>,
152-
// surface_config: &wgpu::SurfaceConfiguration,
143+
_pipeline_manager: &PipelineManager,
144+
state: &State,
153145
) -> Result<(), Box<dyn std::error::Error>> {
154146
let aspect_ratio = state.surface_config.height as f32 / state.surface_config.width as f32;
155147
let player = state.player.read().unwrap();
@@ -162,51 +154,6 @@ impl Pipeline for UIPipeline {
162154
bytemuck::cast_slice(&screen_quad),
163155
);
164156
Ok(())
165-
166-
// let aspect_ratio = state.surface_config.height as f32 / state.surface_config.width as f32;
167-
168-
// let player = state.player.read().unwrap();
169-
// let block_type = player.placing_block;
170-
// let tex_coords = block_type.get_texcoords(FaceDirections::Front);
171-
// let screen_quad = Self::create_screen_quad(aspect_ratio, tex_coords);
172-
// let player = state.player.read().unwrap();
173-
// if let Some(block_ptr) = player.facing_block.as_ref() {
174-
// let block = block_ptr.read().unwrap();
175-
176-
// let face_data = FaceDirections::all()
177-
// .iter()
178-
// .find(|f| **f == player.facing_face.unwrap())
179-
// .unwrap()
180-
// .create_face_data(block_ptr.clone(), &vec![]);
181-
182-
// let blocks_position = face_data
183-
// .0
184-
// .iter()
185-
// .map(|v| {
186-
// [
187-
// // TODO: This is kinda ugly
188-
// v.position[0] + (block.absolute_position.x - block.position.x),
189-
// v.position[1] + (block.absolute_position.y - block.position.y),
190-
// v.position[2] + (block.absolute_position.z - block.position.z),
191-
// ]
192-
// })
193-
// .collect::<Vec<_>>();
194-
195-
// self.indices = face_data.1.len();
196-
// state.queue.write_buffer(
197-
// &self.vertex_buffer,
198-
// 0,
199-
// bytemuck::cast_slice(&blocks_position),
200-
// );
201-
// state
202-
// .queue
203-
// .write_buffer(&self.index_buffer, 0, bytemuck::cast_slice(&face_data.1));
204-
// } else {
205-
// self.indices = 0;
206-
// state.queue.write_buffer(&self.vertex_buffer, 0, &[]);
207-
// state.queue.write_buffer(&self.index_buffer, 0, &[]);
208-
// }
209-
// }
210157
}
211158
}
212159
impl UIPipeline {

0 commit comments

Comments
 (0)