Added default block kind to structure loading

This commit is contained in:
Joshua Barretto 2019-08-16 18:23:58 +01:00
parent 6cf5b99857
commit e535537106
3 changed files with 41 additions and 11 deletions

View File

@ -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<u8>),
}
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<i32>,
vol: Dyna<StructureBlock, ()>,
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<i32> {
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,
})
}
}

View File

@ -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<i32>,
structure_pos: Vec2<i32>,
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())
}
}
}

View File

@ -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<Arc<Structure>> = 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(),
];
}