From e535537106ef692d289c6087aa96f95ef7cd253a Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Fri, 16 Aug 2019 18:23:58 +0100 Subject: [PATCH] Added default block kind to structure loading --- common/src/terrain/structure.rs | 19 ++++++++++++++++--- world/src/block/mod.rs | 15 +++++++++++++-- world/src/column/mod.rs | 18 ++++++++++++------ 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/common/src/terrain/structure.rs b/common/src/terrain/structure.rs index 0f70b37fbe..338ab6e6d7 100644 --- a/common/src/terrain/structure.rs +++ b/common/src/terrain/structure.rs @@ -11,6 +11,7 @@ use vek::*; #[derive(Copy, Clone)] pub enum StructureBlock { + None, TemperateLeaves, PineLeaves, Acacia, @@ -19,12 +20,12 @@ pub enum StructureBlock { GreenSludge, Fruit, Hollow, - Block(Block), + Block(Rgb), } impl Vox for StructureBlock { fn empty() -> Self { - StructureBlock::Block(Block::empty()) + StructureBlock::None } fn is_empty(&self) -> bool { @@ -43,6 +44,7 @@ pub struct Structure { center: Vec3, vol: Dyna, empty: StructureBlock, + default_kind: BlockKind, } impl Structure { @@ -51,12 +53,21 @@ impl Structure { self } + pub fn with_default_kind(mut self, kind: BlockKind) -> Self { + self.default_kind = kind; + self + } + pub fn get_bounds(&self) -> Aabb { Aabb { min: -self.center, max: self.vol.get_size().map(|e| e as i32) - self.center, } } + + pub fn default_kind(&self) -> BlockKind { + self.default_kind + } } impl BaseVol for Structure { @@ -107,7 +118,7 @@ impl Asset for Structure { .get(index as usize) .copied() .unwrap_or_else(|| Rgb::broadcast(0)); - StructureBlock::Block(Block::new(BlockKind::Normal, color)) + StructureBlock::Block(color) } }; @@ -121,12 +132,14 @@ impl Asset for Structure { center: Vec3::zero(), vol, empty: StructureBlock::empty(), + default_kind: BlockKind::Normal, }) } else { Ok(Self { center: Vec3::zero(), vol: Dyna::filled(Vec3::zero(), StructureBlock::empty(), ()), empty: StructureBlock::empty(), + default_kind: BlockKind::Normal, }) } } diff --git a/world/src/block/mod.rs b/world/src/block/mod.rs index c927a5194f..a8251bfb93 100644 --- a/world/src/block/mod.rs +++ b/world/src/block/mod.rs @@ -440,7 +440,14 @@ impl StructureInfo { .get((block_pos * 128) / 128) // Scaling .ok() .and_then(|b| { - block_from_structure(*b, block_pos, self.pos.into(), self.seed, sample) + block_from_structure( + *b, + volume.default_kind(), + block_pos, + self.pos.into(), + self.seed, + sample, + ) }) } } @@ -449,6 +456,7 @@ impl StructureInfo { fn block_from_structure( sblock: StructureBlock, + default_kind: BlockKind, pos: Vec3, structure_pos: Vec2, structure_seed: u32, @@ -461,6 +469,7 @@ fn block_from_structure( + ((field.get(Vec3::from(pos)) % 256) as f32 / 256.0 - 0.5) * 0.15; match sblock { + StructureBlock::None => None, StructureBlock::TemperateLeaves => Some(Block::new( BlockKind::Normal, Lerp::lerp(Rgb::new(0.0, 132.0, 94.0), Rgb::new(142.0, 181.0, 0.0), lerp) @@ -489,6 +498,8 @@ fn block_from_structure( .map(|e| e as u8), )), StructureBlock::Hollow => Some(Block::empty()), - StructureBlock::Block(block) => Some(block).filter(|block| !block.is_empty()), + StructureBlock::Block(color) => { + Some(Block::new(default_kind, color)).filter(|block| !block.is_empty()) + } } } diff --git a/world/src/column/mod.rs b/world/src/column/mod.rs index bfe9500244..021a422d87 100644 --- a/world/src/column/mod.rs +++ b/world/src/column/mod.rs @@ -7,7 +7,7 @@ use crate::{ }; use common::{ assets, - terrain::{Structure, TerrainChunkSize}, + terrain::{BlockKind, Structure, TerrainChunkSize}, vol::VolSize, }; use lazy_static::lazy_static; @@ -29,21 +29,27 @@ static DUNGEON_RAND: RandomPerm = RandomPerm::new(0x42782335); lazy_static! { pub static ref DUNGEONS: Vec> = vec![ assets::load_map("world.structure.dungeon.ruins", |s: Structure| s - .with_center(Vec3::new(57, 58, 61))) + .with_center(Vec3::new(57, 58, 61)) + .with_default_kind(BlockKind::Dense)) .unwrap(), assets::load_map("world.structure.dungeon.ruins_2", |s: Structure| s - .with_center(Vec3::new(53, 57, 60))) + .with_center(Vec3::new(53, 57, 60)) + .with_default_kind(BlockKind::Dense)) .unwrap(), assets::load_map("world.structure.dungeon.ruins_3", |s: Structure| s - .with_center(Vec3::new(58, 45, 72))) + .with_center(Vec3::new(58, 45, 72)) + .with_default_kind(BlockKind::Dense)) .unwrap(), assets::load_map( "world.structure.dungeon.meso_sewer_temple", - |s: Structure| s.with_center(Vec3::new(66, 56, 60)) + |s: Structure| s + .with_center(Vec3::new(66, 56, 60)) + .with_default_kind(BlockKind::Dense) ) .unwrap(), assets::load_map("world.structure.dungeon.ruins_maze", |s: Structure| s - .with_center(Vec3::new(56, 62, 116))) + .with_center(Vec3::new(56, 62, 116)) + .with_default_kind(BlockKind::Dense)) .unwrap(), ]; }