@@ -24,7 +24,7 @@ pub const FREQUENCY: f32 = 1. / 128.;
24
24
pub const NOISE_CHUNK_PER_ROW : u32 = NOISE_SIZE / CHUNK_SIZE ;
25
25
pub const MAX_TREES_PER_CHUNK : u32 = 3 ;
26
26
27
- pub const CHUNKS_PER_ROW : u32 = 60 ;
27
+ pub const CHUNKS_PER_ROW : u32 = 9 ;
28
28
pub const CHUNKS_REGION : u32 = CHUNKS_PER_ROW * CHUNKS_PER_ROW ;
29
29
pub const WATER_HEIGHT_LEVEL : u8 = 5 ;
30
30
@@ -56,61 +56,39 @@ pub struct World {
56
56
}
57
57
58
58
impl World {
59
- // pub fn get_other_chunks(&self, chunk_ptr: WorldChunk) -> Vec<WorldChunk> {
60
- // self.chunks
61
- // .values()
62
- // .filter_map(|c| {
63
- // return if !Arc::ptr_eq(&chunk_ptr, c) {
64
- // Some(c.clone())
65
- // } else {
66
- // None
67
- // };
68
- // })
69
- // .collect()
70
- // }
71
59
pub fn place_block ( & mut self , block : Arc < RwLock < Block > > ) {
72
60
let block_borrow = block. read ( ) . unwrap ( ) ;
73
61
let mut chunks_to_rerender = vec ! [ block_borrow. get_chunk_coords( ) ] ;
62
+ chunks_to_rerender. append ( & mut block_borrow. get_neighbour_chunks_coords ( ) ) ;
63
+
74
64
let chunk_map = self . chunks . read ( ) . unwrap ( ) ;
75
65
let chunk = chunk_map
76
66
. get ( & chunks_to_rerender[ 0 ] )
77
67
. expect ( "Cannot delete a block from unloaded chunk" ) ;
78
68
79
- let mut chunk_lock = chunk. write ( ) . unwrap ( ) ;
80
- chunk_lock. add_block ( block. clone ( ) , true ) ;
81
-
82
- let block_borrow = block. read ( ) . unwrap ( ) ;
83
- chunks_to_rerender. append ( & mut block_borrow. get_neighbour_chunks_coords ( ) ) ;
84
- std:: mem:: drop ( chunk_lock) ;
85
-
86
- // if block_neighbour_chunks.len() > 0 {
87
- // for neighbour_chunk in block_neighbour_chunks {
88
- // let neighbour_chunk = self
89
- // .chunks
90
- // .get(&neighbour_chunk)
91
- // .expect("Cannot destroy a block without neighbour being loaded");
92
-
93
- // chunks_to_rerender.push(neighbour_chunk.clone());
94
- // }
95
- // }
69
+ {
70
+ let mut chunk_lock = chunk. write ( ) . unwrap ( ) ;
71
+ chunk_lock. add_block ( block. clone ( ) , true ) ;
72
+ // Drop chunk lock write
73
+ }
96
74
97
75
self . render_chunks ( chunks_to_rerender)
98
- // self.render_chunks(block_neighbour_chunks.append(&mut vec![chunk_coords]));
99
76
}
100
77
pub fn remove_block ( & mut self , block : Arc < RwLock < Block > > ) {
101
78
let block_borrow = block. read ( ) . unwrap ( ) ;
102
79
let mut chunks_to_rerender = vec ! [ block_borrow. get_chunk_coords( ) ] ;
80
+ chunks_to_rerender. append ( & mut block_borrow. get_neighbour_chunks_coords ( ) ) ;
81
+
103
82
let chunk_map = self . chunks . read ( ) . unwrap ( ) ;
104
83
let chunk = chunk_map
105
84
. get ( & chunks_to_rerender[ 0 ] )
106
85
. expect ( "Cannot delete a block from unloaded chunk" ) ;
107
86
108
- let mut chunk_lock = chunk. write ( ) . unwrap ( ) ;
109
- chunk_lock. remove_block ( & ( block_borrow. position ) ) ;
110
- // chunk_lock.build_mesh(self.get_other_chunks(chunk.clone()));
111
- chunks_to_rerender. append ( & mut block_borrow. get_neighbour_chunks_coords ( ) ) ;
112
- // I hate this so much
113
- std:: mem:: drop ( chunk_lock) ;
87
+ {
88
+ let mut chunk_lock = chunk. write ( ) . unwrap ( ) ;
89
+ chunk_lock. remove_block ( & ( block_borrow. position ) ) ;
90
+ // Drop chunk lock write
91
+ }
114
92
115
93
self . render_chunks ( chunks_to_rerender) ;
116
94
}
@@ -144,9 +122,6 @@ impl World {
144
122
145
123
for position in positions. iter ( ) {
146
124
if let Some ( block) = self . get_blocks_absolute ( position) {
147
- if block. read ( ) . unwrap ( ) . block_type == BlockType :: Water {
148
- continue ;
149
- }
150
125
nearby_blocks. push ( block)
151
126
} ;
152
127
}
0 commit comments