diff options
author | metamuffin <metamuffin@disroot.org> | 2022-10-17 16:57:07 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2022-10-17 16:57:07 +0200 |
commit | b58c29c734978766db2c86acb436ca9425491b99 (patch) | |
tree | 51a6a95e3317cc124a7c44d8dddd567bd76a6c9b | |
parent | d1a020b9592bdca09800d4b3c0f34da45e968402 (diff) | |
download | trash-map-b58c29c734978766db2c86acb436ca9425491b99.tar trash-map-b58c29c734978766db2c86acb436ca9425491b99.tar.bz2 trash-map-b58c29c734978766db2c86acb436ca9425491b99.tar.zst |
naive renderer
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs index 609041b..5f4e621 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,7 +11,7 @@ use image::ImageBuffer; use log::debug; use std::{collections::HashMap, fs::File, path::Path}; -const SEG_SIZE: isize = 64; +const SEG_SIZE: isize = 128; fn main() { env_logger::builder() @@ -27,21 +27,25 @@ fn main() { for y in -64..256 { for z in 0..SEG_SIZE { let solid = |x: isize, y: isize, z: isize| { - if x >= 0 && z >= 0 && x < SEG_SIZE && z < SEG_SIZE && y >= -64 && y < 256 { - dim.block(x, y, z) - .map(|b| { - !matches!( - b.name(), - "minecraft:air" | "minecraft:water" | "minecraft:cave_air" - ) - }) - .unwrap_or(false) - } else { - false - } + dim.block(x, y, z) + .map(|b| { + !matches!( + b.name(), + "minecraft:air" | "minecraft:water" | "minecraft:cave_air" + ) + }) + .unwrap_or(false) }; let visible = |b: &Block| !matches!(b.name(), "minecraft:air" | "minecraft:cave_air"); + let ray_visible = || { + for i in 1..100 { + if solid(x - i, y + i, z - i) { + return false; + } + } + true + }; if visible(&dim.block(x, y, z).unwrap()) && !(solid(x + 1, y, z) @@ -50,6 +54,7 @@ fn main() { && solid(x, y - 1, z) && solid(x, y, z + 1) && solid(x, y, z - 1)) + && ray_visible() { visible_blocks.push((x, y, z)) } |