@@ -2,24 +2,8 @@ use terrain_resources::{Generator, NoiseFunctionParams, TerrainGeneratorParams};
2
2
3
3
use crate :: prelude:: * ;
4
4
5
- impl Generator {
6
- pub fn new ( seed : u32 ) -> Generator {
7
- Self :: new_with_params ( seed, TerrainGeneratorParams :: default ( ) )
8
- }
9
-
10
- pub fn new_with_params ( seed : u32 , params : TerrainGeneratorParams ) -> Generator {
11
- Generator {
12
- seed,
13
- perlin : Perlin :: new ( seed) ,
14
- params,
15
- }
16
- }
17
-
18
- pub fn generate_chunk ( & self , chunk : & mut Chunk ) {
19
- if chunk. position . y < 0.0 {
20
- return ;
21
- }
22
-
5
+ macro_rules! for_each_chunk_coordinate {
6
+ ( $chunk: expr, $body: expr) => {
23
7
for x in 0 ..CHUNK_SIZE + 2 {
24
8
for y in 0 ..CHUNK_SIZE + 2 {
25
9
for z in 0 ..CHUNK_SIZE + 2 {
@@ -34,14 +18,40 @@ impl Generator {
34
18
continue ;
35
19
}
36
20
37
- let chunk_origin = chunk. position * CHUNK_SIZE as f32 ;
21
+ let chunk_origin = $ chunk. position * CHUNK_SIZE as f32 ;
38
22
let local_position = Vec3 :: new( x as f32 , y as f32 , z as f32 ) ;
39
23
let block_position = chunk_origin + local_position;
40
- let block = self . generate_block ( block_position ) ;
41
- chunk . set_unpadded ( x, y, z, block ) ;
24
+
25
+ $body ( x, y, z, block_position ) ;
42
26
}
43
27
}
44
28
}
29
+ } ;
30
+ }
31
+
32
+
33
+ impl Generator {
34
+ pub fn new ( seed : u32 ) -> Generator {
35
+ Self :: new_with_params ( seed, TerrainGeneratorParams :: default ( ) )
36
+ }
37
+
38
+ pub fn new_with_params ( seed : u32 , params : TerrainGeneratorParams ) -> Generator {
39
+ Generator {
40
+ seed,
41
+ perlin : Perlin :: new ( seed) ,
42
+ params,
43
+ }
44
+ }
45
+
46
+ pub fn generate_chunk ( & self , chunk : & mut Chunk ) {
47
+ if chunk. position . y < 0.0 {
48
+ return ;
49
+ }
50
+
51
+ for_each_chunk_coordinate ! ( chunk, |x, y, z, block_position| {
52
+ let block = self . generate_block( block_position) ;
53
+ chunk. set_unpadded( x, y, z, block) ;
54
+ } ) ;
45
55
}
46
56
47
57
fn generate_block ( & self , position : Vec3 ) -> BlockId {
0 commit comments