Skip to content

Commit

Permalink
Render hidden blocks with a single material
Browse files Browse the repository at this point in the history
  • Loading branch information
plule committed Apr 24, 2023
1 parent 2a4100b commit d0fce6f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
6 changes: 1 addition & 5 deletions src/map.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{tile::Tile, rfr::DFTile};
use crate::{rfr::DFTile, tile::Tile};
use dfhack_remote::Coord;
use std::{collections::HashMap, ops::Add};

Expand Down Expand Up @@ -44,10 +44,6 @@ impl Map {
}
}
pub fn add_tile<'a>(&mut self, df_tile: &'a DFTile<'a>) {
if df_tile.hidden {
return;
}

if let Some(tile) = df_tile.into() {
let coord_mirrored = Coords::new(df_tile.coords.x, df_tile.coords.y, df_tile.coords.z);
self.tiles.insert(coord_mirrored, tile);
Expand Down
14 changes: 9 additions & 5 deletions src/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ use rand::seq::SliceRandom;
use std::collections::HashMap;
use vox_writer::VoxWriter;

const WATER: u8 = 0;
const MAGMA: u8 = 1;
const DARK_GRASS: u8 = 2;
const LIGHT_GRASS: u8 = 3;
const HIDDEN: u8 = 0;
const WATER: u8 = 1;
const MAGMA: u8 = 2;
const DARK_GRASS: u8 = 3;
const LIGHT_GRASS: u8 = 4;

#[derive(Default)]
pub struct Palette {
Expand All @@ -22,13 +23,14 @@ impl Palette {
let palette_size = self.colors.len() as u8;
self.colors
.entry(mat_pair.to_owned())
.or_insert_with(|| palette_size + 4);
.or_insert_with(|| palette_size + 5);
}
}
}

pub fn write_palette(&self, vox: &mut VoxWriter, materials: &[MaterialDefinition]) {
vox.clear_colors();
vox.add_color(0, 0, 0, 255, HIDDEN);
vox.add_color(0, 0, 255, 64, WATER);
vox.add_color(255, 0, 0, 64, MAGMA);
vox.add_color(0, 102, 0, 255, DARK_GRASS);
Expand Down Expand Up @@ -56,6 +58,7 @@ impl Palette {

#[derive(Debug)]
pub enum Material {
Hidden,
Water,
Magma,
DarkGrass,
Expand All @@ -73,6 +76,7 @@ impl Material {

pub fn pick_color(&self, palette: &HashMap<MatPairHash, u8>) -> u8 {
(match self {
Material::Hidden => HIDDEN,
Material::Water => WATER,
Material::Magma => MAGMA,
Material::DarkGrass => DARK_GRASS,
Expand Down
15 changes: 11 additions & 4 deletions src/tile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub enum Shape {
Stair,
Tree { origin: Coords, part: TreePart },
Fortification,
Wall,
Full,
Ramp,
}

Expand Down Expand Up @@ -52,7 +52,7 @@ impl RampContactKind {
fn get_ramp_contact_kind(map: &Map, coords: &Coords) -> RampContactKind {
if let Some(tile) = map.tiles.get(coords) {
return match tile.shape {
Shape::Wall | Shape::Fortification => RampContactKind::Wall,
Shape::Full | Shape::Fortification => RampContactKind::Wall,
Shape::Ramp => RampContactKind::Ramp,
_ => RampContactKind::Empty,
};
Expand Down Expand Up @@ -264,7 +264,7 @@ impl Tile {
[true, true, true]
],
],
Shape::Wall => [
Shape::Full => [
[[true, true, true], [true, true, true], [true, true, true]],
[[true, true, true], [true, true, true], [true, true, true]],
[[true, true, true], [true, true, true], [true, true, true]],
Expand Down Expand Up @@ -307,6 +307,13 @@ impl Tile {

impl<'a> From<&'a DFTile<'a>> for Option<Tile> {
fn from(tile: &DFTile) -> Self {
if tile.hidden {
return Some(Tile {
shape: Shape::Full,
material: Material::Hidden,
coords: tile.coords,
});
}
// Check if it's a fluid, in that case, ignore what's below
match tile.tile_type.material() {
TiletypeMaterial::MAGMA => {
Expand Down Expand Up @@ -400,7 +407,7 @@ impl<'a> From<&'a DFTile<'a>> for Option<Tile> {
| TiletypeShape::STAIR_DOWN
| TiletypeShape::STAIR_UPDOWN => Some(Shape::Stair),
TiletypeShape::FORTIFICATION => Some(Shape::Fortification),
TiletypeShape::WALL => Some(Shape::Wall),
TiletypeShape::WALL => Some(Shape::Full),
_ => None,
} {
let material: MatPairHash = material.mat_pair.clone().unwrap_or_default().into();
Expand Down

0 comments on commit d0fce6f

Please sign in to comment.