diff options
Diffstat (limited to 'src/proc_gen/mod.rs')
| -rw-r--r-- | src/proc_gen/mod.rs | 43 |
1 files changed, 21 insertions, 22 deletions
diff --git a/src/proc_gen/mod.rs b/src/proc_gen/mod.rs index f97df66..4e333d1 100644 --- a/src/proc_gen/mod.rs +++ b/src/proc_gen/mod.rs @@ -31,7 +31,7 @@ struct BiomeChunkContext { } pub struct InterpolatedPixel { - pub interpolated_pixel_index: u8, + pub interpolated_pixel_indices: [(u8, f32); 4], pub interpolated_solidity: f32, } @@ -49,8 +49,8 @@ impl BiomeChunkContext { }; let instantaneous_idx_at = |dx, dy| match instantaneous_pixel_at(dx, dy) { - TilePixelType::Void => 255, - TilePixelType::Terrain(_) => 0, + TilePixelType::Void => 0, + TilePixelType::Terrain(_) => 1, TilePixelType::Custom(i) => i, }; @@ -79,44 +79,43 @@ impl BiomeChunkContext { // same for the pixel // TODO don't allocate per-cell - let mut idxes: Vec<u8> = Vec::new(); + let mut pixel_indices: Vec<u8> = Vec::new(); let tl = instantaneous_idx_at(0, 0); - if tl != 255 && !idxes.contains(&tl) { - idxes.push(tl); + if tl != 0 && !pixel_indices.contains(&tl) { + pixel_indices.push(tl); } let tr = instantaneous_idx_at(1, 0); - if tr != 255 && !idxes.contains(&tr) { - idxes.push(tr); + if tr != 0 && !pixel_indices.contains(&tr) { + pixel_indices.push(tr); } let bl = instantaneous_idx_at(0, 1); - if bl != 255 && !idxes.contains(&bl) { - idxes.push(bl); + if bl != 0 && !pixel_indices.contains(&bl) { + pixel_indices.push(bl); } let br = instantaneous_idx_at(1, 1); - if br != 255 && !idxes.contains(&br) { - idxes.push(br); + if br != 0 && !pixel_indices.contains(&br) { + pixel_indices.push(br); } - let idx_strengths = idxes.iter().map(|&i| { + let mut interpolated_pixel_indices: [(u8, f32); 4] = [(0, 0.0); 4]; + for (i, &p) in pixel_indices.iter().enumerate() { let i_top = lerp( - if tl == i { 1.0 } else { 0.0 }, - if tr == i { 1.0 } else { 0.0 }, + if tl == p { 1.0 } else { 0.0 }, + if tr == p { 1.0 } else { 0.0 }, frac.x, ); let i_bottom = lerp( - if bl == i { 1.0 } else { 0.0 }, - if br == i { 1.0 } else { 0.0 }, + if bl == p { 1.0 } else { 0.0 }, + if br == p { 1.0 } else { 0.0 }, frac.x, ); let interpolated_strength = lerp(i_top, i_bottom, frac.y); - (i, interpolated_strength) - }); + interpolated_pixel_indices[i] = (p, interpolated_strength); + } InterpolatedPixel { - interpolated_pixel_index: idx_strengths - .max_by(|&(_, s1), &(_, s2)| s1.total_cmp(&s2)) - .map_or(255, |(i, _)| i), + interpolated_pixel_indices, interpolated_solidity, } } |
