mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Fixed window mask layering, fmt
This commit is contained in:
parent
781a3e1377
commit
431b2ae07b
@ -39,9 +39,7 @@ impl<T> Path<T> {
|
||||
|
||||
pub fn end(&self) -> Option<&T> { self.nodes.last() }
|
||||
|
||||
pub fn nodes(&self) -> &[T] {
|
||||
&self.nodes
|
||||
}
|
||||
pub fn nodes(&self) -> &[T] { &self.nodes }
|
||||
}
|
||||
|
||||
// Route: A path that can be progressed along
|
||||
|
@ -287,10 +287,9 @@ impl Block {
|
||||
|
||||
pub fn get_ori(&self) -> Option<u8> {
|
||||
match self.kind {
|
||||
BlockKind::Window1
|
||||
| BlockKind::Window2
|
||||
| BlockKind::Window3
|
||||
| BlockKind::Window4 => Some(self.color[0] & 0b111),
|
||||
BlockKind::Window1 | BlockKind::Window2 | BlockKind::Window3 | BlockKind::Window4 => {
|
||||
Some(self.color[0] & 0b111)
|
||||
},
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
@ -298,9 +298,10 @@ impl<V: RectRasterableVol<Vox = Block> + ReadVol + Debug> Meshable<TerrainPipeli
|
||||
}
|
||||
.min(range.size().d - 1);
|
||||
|
||||
// // We use multiple meshes and then combine them later such that we can group similar z
|
||||
// // levels together (better rendering performance)
|
||||
// let mut opaque_meshes = vec![Mesh::new(); ((z_end + 1 - z_start).clamped(1, 60) as usize / 10).max(1)];
|
||||
// // We use multiple meshes and then combine them later such that we can group
|
||||
// similar z // levels together (better rendering performance)
|
||||
// let mut opaque_meshes = vec![Mesh::new(); ((z_end + 1 - z_start).clamped(1,
|
||||
// 60) as usize / 10).max(1)];
|
||||
let mut opaque_mesh = Mesh::new();
|
||||
let mut fluid_mesh = Mesh::new();
|
||||
|
||||
@ -380,12 +381,13 @@ impl<V: RectRasterableVol<Vox = Block> + ReadVol + Debug> Meshable<TerrainPipeli
|
||||
[[[get_color(blocks[1][1][1].as_ref(), false); 3]; 3]; 3]
|
||||
};
|
||||
|
||||
// let opaque_mesh_index = ((z - z_start) * opaque_meshes.len() as i32 / (z_end + 1 - z_start).max(1)) as usize;
|
||||
// let selected_opaque_mesh = &mut opaque_meshes[opaque_mesh_index];
|
||||
// Create mesh polygons
|
||||
// let opaque_mesh_index = ((z - z_start) * opaque_meshes.len() as i32 / (z_end
|
||||
// + 1 - z_start).max(1)) as usize; let selected_opaque_mesh
|
||||
// = &mut opaque_meshes[opaque_mesh_index]; Create mesh
|
||||
// polygons
|
||||
if block.map_or(false, |vox| vox.is_opaque()) {
|
||||
vol::push_vox_verts(
|
||||
&mut opaque_mesh,//selected_opaque_mesh,
|
||||
&mut opaque_mesh, //selected_opaque_mesh,
|
||||
faces_to_make(&blocks, false, |vox| !vox.is_opaque()),
|
||||
offs,
|
||||
&colors,
|
||||
|
@ -5,9 +5,14 @@ pub struct Mesh<P: Pipeline> {
|
||||
verts: Vec<P::Vertex>,
|
||||
}
|
||||
|
||||
impl<P: Pipeline> Clone for Mesh<P> where P::Vertex: Clone {
|
||||
impl<P: Pipeline> Clone for Mesh<P>
|
||||
where
|
||||
P::Vertex: Clone,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self { verts: self.verts.clone() }
|
||||
Self {
|
||||
verts: self.verts.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,22 +66,16 @@ impl<P: Pipeline> Mesh<P> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn verts(&self) -> &[P::Vertex] {
|
||||
&self.verts
|
||||
}
|
||||
pub fn verts(&self) -> &[P::Vertex] { &self.verts }
|
||||
|
||||
pub fn iter(&self) -> std::slice::Iter<P::Vertex> {
|
||||
self.verts.iter()
|
||||
}
|
||||
pub fn iter(&self) -> std::slice::Iter<P::Vertex> { self.verts.iter() }
|
||||
}
|
||||
|
||||
impl<P: Pipeline> IntoIterator for Mesh<P> {
|
||||
type Item = P::Vertex;
|
||||
type IntoIter = std::vec::IntoIter<P::Vertex>;
|
||||
type Item = P::Vertex;
|
||||
|
||||
fn into_iter(self) -> Self::IntoIter {
|
||||
self.verts.into_iter()
|
||||
}
|
||||
fn into_iter(self) -> Self::IntoIter { self.verts.into_iter() }
|
||||
}
|
||||
|
||||
/// Represents a triangle stored on the CPU.
|
||||
|
@ -268,9 +268,7 @@ fn mesh_worker<V: BaseVol<Vox = Block> + RectRasterableVol + ReadVol + Debug>(
|
||||
let seed = wpos.x as u64 * 3
|
||||
+ wpos.y as u64 * 7
|
||||
+ wpos.x as u64 * wpos.y as u64; // Awful PRNG
|
||||
let ori = block
|
||||
.get_ori()
|
||||
.unwrap_or((seed % 8) as u8);
|
||||
let ori = block.get_ori().unwrap_or((seed % 8) as u8);
|
||||
|
||||
let instance = SpriteInstance::new(
|
||||
Mat4::identity()
|
||||
|
@ -3,7 +3,7 @@ mod econ;
|
||||
use crate::{
|
||||
sim::{SimChunk, WorldSim},
|
||||
site::{Dungeon, Settlement, Site as WorldSite},
|
||||
util::{attempt, seed_expan, NEIGHBORS, CARDINALS},
|
||||
util::{attempt, seed_expan, CARDINALS, NEIGHBORS},
|
||||
};
|
||||
use common::{
|
||||
astar::Astar,
|
||||
@ -108,9 +108,7 @@ impl Civs {
|
||||
.0;
|
||||
|
||||
let mut chunk = ctx.sim.get_mut(locs[1]).unwrap();
|
||||
chunk.path.neighbors |=
|
||||
(1 << (to_prev_idx as u8)) |
|
||||
(1 << (to_next_idx as u8));
|
||||
chunk.path.neighbors |= (1 << (to_prev_idx as u8)) | (1 << (to_next_idx as u8));
|
||||
chunk.path.offset = Vec2::new(
|
||||
ctx.rng.gen_range(-16.0, 16.0),
|
||||
ctx.rng.gen_range(-16.0, 16.0),
|
||||
@ -164,7 +162,11 @@ impl Civs {
|
||||
|
||||
// Place sites in world
|
||||
for site in this.sites.iter() {
|
||||
let wpos = site.center.map2(Vec2::from(TerrainChunkSize::RECT_SIZE), |e, sz: u32| e * sz as i32 + sz as i32 / 2);
|
||||
let wpos = site
|
||||
.center
|
||||
.map2(Vec2::from(TerrainChunkSize::RECT_SIZE), |e, sz: u32| {
|
||||
e * sz as i32 + sz as i32 / 2
|
||||
});
|
||||
|
||||
let world_site = match &site.kind {
|
||||
SiteKind::Settlement => {
|
||||
@ -491,7 +493,11 @@ fn walk_in_dir(sim: &WorldSim, a: Vec2<i32>, dir: Vec2<i32>) -> Option<f32> {
|
||||
if loc_suitable_for_walking(sim, a) && loc_suitable_for_walking(sim, a + dir) {
|
||||
let a_alt = sim.get(a)?.alt;
|
||||
let b_alt = sim.get(a + dir)?.alt;
|
||||
let water_cost = if sim.get(a + dir)?.river.near_water() { 25.0 } else { 0.0 };
|
||||
let water_cost = if sim.get(a + dir)?.river.near_water() {
|
||||
25.0
|
||||
} else {
|
||||
0.0
|
||||
};
|
||||
Some((b_alt - a_alt).abs() / 2.5)
|
||||
} else {
|
||||
None
|
||||
|
@ -1119,7 +1119,11 @@ impl<'a> Sampler<'a> for ColumnGen<'a> {
|
||||
};
|
||||
|
||||
const PATH_WIDTH: f32 = 5.0;
|
||||
let path_dist_factor = sim.get_nearest_path(wpos).map(|(dist, _)| dist / PATH_WIDTH).unwrap_or(1.0).min(1.0);
|
||||
let path_dist_factor = sim
|
||||
.get_nearest_path(wpos)
|
||||
.map(|(dist, _)| dist / PATH_WIDTH)
|
||||
.unwrap_or(1.0)
|
||||
.min(1.0);
|
||||
let ground = Lerp::lerp(
|
||||
sub_surface_color,
|
||||
ground,
|
||||
|
@ -2,8 +2,8 @@ mod diffusion;
|
||||
mod erosion;
|
||||
mod location;
|
||||
mod map;
|
||||
mod util;
|
||||
mod path;
|
||||
mod util;
|
||||
|
||||
// Reexports
|
||||
use self::erosion::Compute;
|
||||
@ -15,12 +15,12 @@ pub use self::{
|
||||
},
|
||||
location::Location,
|
||||
map::{MapConfig, MapDebug},
|
||||
path::PathData,
|
||||
util::{
|
||||
cdf_irwin_hall, downhill, get_oceans, local_cells, map_edge_factor, neighbors,
|
||||
uniform_idx_as_vec2, uniform_noise, uphill, vec2_as_uniform_idx, InverseCdf, ScaleBias,
|
||||
NEIGHBOR_DELTA,
|
||||
},
|
||||
path::PathData,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
@ -29,7 +29,10 @@ use crate::{
|
||||
civ::Place,
|
||||
column::ColumnGen,
|
||||
site::{Settlement, Site},
|
||||
util::{seed_expan, FastNoise, RandomField, Sampler, StructureGen2d, LOCALITY, CARDINAL_LOCALITY, NEIGHBORS},
|
||||
util::{
|
||||
seed_expan, FastNoise, RandomField, Sampler, StructureGen2d, CARDINAL_LOCALITY, LOCALITY,
|
||||
NEIGHBORS,
|
||||
},
|
||||
CONFIG,
|
||||
};
|
||||
use common::{
|
||||
@ -1777,15 +1780,18 @@ impl WorldSim {
|
||||
let chunk_pos = wpos.map2(Vec2::from(TerrainChunkSize::RECT_SIZE), |e, sz: u32| {
|
||||
e.div_euclid(sz as i32)
|
||||
});
|
||||
let get_chunk_centre = |chunk_pos: Vec2<i32>| chunk_pos.map2(Vec2::from(TerrainChunkSize::RECT_SIZE), |e, sz: u32| {
|
||||
e * sz as i32 + sz as i32 / 2
|
||||
});
|
||||
let get_chunk_centre = |chunk_pos: Vec2<i32>| {
|
||||
chunk_pos.map2(Vec2::from(TerrainChunkSize::RECT_SIZE), |e, sz: u32| {
|
||||
e * sz as i32 + sz as i32 / 2
|
||||
})
|
||||
};
|
||||
|
||||
LOCALITY
|
||||
.iter()
|
||||
.filter_map(|ctrl| {
|
||||
let chunk = self.get(chunk_pos + *ctrl)?;
|
||||
let ctrl_pos = get_chunk_centre(chunk_pos + *ctrl).map(|e| e as f32) + chunk.path.offset;
|
||||
let ctrl_pos =
|
||||
get_chunk_centre(chunk_pos + *ctrl).map(|e| e as f32) + chunk.path.offset;
|
||||
|
||||
let chunk_connections = chunk.path.neighbors.count_ones();
|
||||
if chunk_connections == 0 {
|
||||
@ -1803,35 +1809,36 @@ impl WorldSim {
|
||||
.unwrap();
|
||||
let start_pos_chunk = chunk_pos + *ctrl + start_rpos;
|
||||
(
|
||||
get_chunk_centre(start_pos_chunk).map(|e| e as f32) + self.get(start_pos_chunk)?.path.offset,
|
||||
get_chunk_centre(start_pos_chunk).map(|e| e as f32)
|
||||
+ self.get(start_pos_chunk)?.path.offset,
|
||||
Some(start_idx),
|
||||
)
|
||||
};
|
||||
|
||||
Some(NEIGHBORS
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(move |(i, _)| chunk.path.neighbors & (1 << *i as u8) != 0)
|
||||
.filter_map(move |(i, end_rpos)| {
|
||||
let end_pos_chunk = chunk_pos + *ctrl + end_rpos;
|
||||
let end_pos = get_chunk_centre(end_pos_chunk).map(|e| e as f32) + self.get(end_pos_chunk)?.path.offset;
|
||||
Some(
|
||||
NEIGHBORS
|
||||
.iter()
|
||||
.enumerate()
|
||||
.filter(move |(i, _)| chunk.path.neighbors & (1 << *i as u8) != 0)
|
||||
.filter_map(move |(i, end_rpos)| {
|
||||
let end_pos_chunk = chunk_pos + *ctrl + end_rpos;
|
||||
let end_pos = get_chunk_centre(end_pos_chunk).map(|e| e as f32)
|
||||
+ self.get(end_pos_chunk)?.path.offset;
|
||||
|
||||
let bez = QuadraticBezier2 {
|
||||
start: (start_pos + ctrl_pos) / 2.0,
|
||||
ctrl: ctrl_pos,
|
||||
end: (end_pos + ctrl_pos) / 2.0,
|
||||
};
|
||||
let nearest_interval = bez
|
||||
.binary_search_point_by_steps(
|
||||
wpos.map(|e| e as f32),
|
||||
6,
|
||||
0.01,
|
||||
)
|
||||
.0.clamped(0.0, 1.0);
|
||||
let pos = bez.evaluate(nearest_interval);
|
||||
let dist_sqrd = pos.distance_squared(wpos.map(|e| e as f32));
|
||||
Some((dist_sqrd, pos.map(|e| e.floor() as i32)))
|
||||
}))
|
||||
let bez = QuadraticBezier2 {
|
||||
start: (start_pos + ctrl_pos) / 2.0,
|
||||
ctrl: ctrl_pos,
|
||||
end: (end_pos + ctrl_pos) / 2.0,
|
||||
};
|
||||
let nearest_interval = bez
|
||||
.binary_search_point_by_steps(wpos.map(|e| e as f32), 6, 0.01)
|
||||
.0
|
||||
.clamped(0.0, 1.0);
|
||||
let pos = bez.evaluate(nearest_interval);
|
||||
let dist_sqrd = pos.distance_squared(wpos.map(|e| e as f32));
|
||||
Some((dist_sqrd, pos.map(|e| e.floor() as i32)))
|
||||
}),
|
||||
)
|
||||
})
|
||||
.flatten()
|
||||
.min_by_key(|(dist_sqrd, _)| (dist_sqrd * 1024.0) as i32)
|
||||
|
@ -2,7 +2,8 @@ use vek::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PathData {
|
||||
pub offset: Vec2<f32>, // Offset from centre of chunk: must not be more than half chunk width in any direction
|
||||
pub offset: Vec2<f32>, /* Offset from centre of chunk: must not be more than half chunk
|
||||
* width in any direction */
|
||||
pub neighbors: u8, // One bit for each neighbor
|
||||
}
|
||||
|
||||
|
@ -171,10 +171,14 @@ impl Archetype for House {
|
||||
let profile = Vec2::new(bound_offset.x, z);
|
||||
|
||||
let make_meta = |ori| {
|
||||
Rgb::new(match ori {
|
||||
Ori::East => 0,
|
||||
Ori::North => 2,
|
||||
}, 0, 0)
|
||||
Rgb::new(
|
||||
match ori {
|
||||
Ori::East => 0,
|
||||
Ori::North => 2,
|
||||
},
|
||||
0,
|
||||
0,
|
||||
)
|
||||
};
|
||||
|
||||
let make_block = |r, g, b| {
|
||||
@ -204,7 +208,10 @@ impl Archetype for House {
|
||||
.with_priority(facade_layer);
|
||||
let empty = BlockMask::nothing();
|
||||
let internal = BlockMask::new(Block::empty(), structural_layer);
|
||||
let end_window = BlockMask::new(Block::new(BlockKind::Window1, make_meta(ori.flip())), facade_layer);
|
||||
let end_window = BlockMask::new(
|
||||
Block::new(BlockKind::Window1, make_meta(ori.flip())),
|
||||
structural_layer,
|
||||
);
|
||||
let fire = BlockMask::new(Block::new(BlockKind::Ember, Rgb::white()), foundation_layer);
|
||||
|
||||
let ceil_height = 6;
|
||||
@ -311,15 +318,21 @@ impl Archetype for House {
|
||||
return Some(empty);
|
||||
} else {
|
||||
let (frame_bounds, frame_borders) = if profile.y >= ceil_height {
|
||||
(Aabr {
|
||||
min: Vec2::new(-1, ceil_height + 2),
|
||||
max: Vec2::new(1, ceil_height + 5),
|
||||
}, Vec2::new(1, 1))
|
||||
(
|
||||
Aabr {
|
||||
min: Vec2::new(-1, ceil_height + 2),
|
||||
max: Vec2::new(1, ceil_height + 5),
|
||||
},
|
||||
Vec2::new(1, 1),
|
||||
)
|
||||
} else {
|
||||
(Aabr {
|
||||
min: Vec2::new(2, foundation_height + 2),
|
||||
max: Vec2::new(width - 2, ceil_height - 2),
|
||||
}, Vec2::new(1, 0))
|
||||
(
|
||||
Aabr {
|
||||
min: Vec2::new(2, foundation_height + 2),
|
||||
max: Vec2::new(width - 2, ceil_height - 2),
|
||||
},
|
||||
Vec2::new(1, 0),
|
||||
)
|
||||
};
|
||||
let window_bounds = Aabr {
|
||||
min: (frame_bounds.min + frame_borders)
|
||||
@ -335,7 +348,7 @@ impl Archetype for House {
|
||||
if window_bounds.contains_point(surface_pos) {
|
||||
return Some(end_window);
|
||||
} else if frame_bounds.contains_point(surface_pos) {
|
||||
return Some(log.with_priority(facade_layer));
|
||||
return Some(log.with_priority(structural_layer));
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -50,10 +50,13 @@ impl<A: Archetype> Building<A> {
|
||||
pub fn sample(&self, pos: Vec3<i32>) -> Option<Block> {
|
||||
let rpos = pos - self.origin;
|
||||
self.skel
|
||||
.sample_closest(rpos.into(), |dist, bound_offset, center_offset, ori, branch| {
|
||||
self.archetype
|
||||
.draw(dist, bound_offset, center_offset, rpos.z, ori, branch)
|
||||
})
|
||||
.sample_closest(
|
||||
rpos.into(),
|
||||
|dist, bound_offset, center_offset, ori, branch| {
|
||||
self.archetype
|
||||
.draw(dist, bound_offset, center_offset, rpos.z, ori, branch)
|
||||
},
|
||||
)
|
||||
.finish()
|
||||
}
|
||||
}
|
||||
|
@ -611,10 +611,12 @@ impl Settlement {
|
||||
Crop::Sunflower => Some(BlockKind::Sunflower),
|
||||
_ => None,
|
||||
}
|
||||
.or_else(|| if roll(9, 256) == 0 {
|
||||
Some(BlockKind::Scarecrow)
|
||||
} else {
|
||||
None
|
||||
.or_else(|| {
|
||||
if roll(9, 256) == 0 {
|
||||
Some(BlockKind::Scarecrow)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.map(|kind| Block::new(kind, Rgb::white()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user