mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Make minimap title show location names
This commit is contained in:
parent
ab2c0ad085
commit
4644199f1b
@ -5,6 +5,9 @@ use conrod_core::{
|
||||
};
|
||||
|
||||
use super::{img_ids::Imgs, Fonts, Show, TEXT_COLOR};
|
||||
use client::{self, Client};
|
||||
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
|
||||
widget_ids! {
|
||||
struct Ids {
|
||||
@ -19,6 +22,8 @@ widget_ids! {
|
||||
pub struct MiniMap<'a> {
|
||||
show: &'a Show,
|
||||
|
||||
client: &'a Client,
|
||||
|
||||
imgs: &'a Imgs,
|
||||
fonts: &'a Fonts,
|
||||
|
||||
@ -27,9 +32,10 @@ pub struct MiniMap<'a> {
|
||||
}
|
||||
|
||||
impl<'a> MiniMap<'a> {
|
||||
pub fn new(show: &'a Show, imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
|
||||
pub fn new(show: &'a Show, client: &'a Client, imgs: &'a Imgs, fonts: &'a Fonts) -> Self {
|
||||
Self {
|
||||
show,
|
||||
client,
|
||||
imgs,
|
||||
fonts,
|
||||
common: widget::CommonBuilder::default(),
|
||||
@ -103,12 +109,18 @@ impl<'a> Widget for MiniMap<'a> {
|
||||
}
|
||||
|
||||
// Title
|
||||
// TODO: Make it display the actual location.
|
||||
Text::new("Region Name")
|
||||
.mid_top_with_margin_on(state.ids.mmap_frame, 3.0)
|
||||
.font_size(14)
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.ids.mmap_location, ui);
|
||||
match self.client.current_chunk() {
|
||||
Some(chunk) => Text::new(chunk.meta().name())
|
||||
.mid_top_with_margin_on(state.ids.mmap_frame, 3.0)
|
||||
.font_size(14)
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.ids.mmap_location, ui),
|
||||
None => Text::new("Wait what")
|
||||
.mid_top_with_margin_on(state.ids.mmap_frame, 3.0)
|
||||
.font_size(14)
|
||||
.color(TEXT_COLOR)
|
||||
.set(state.ids.mmap_location, ui),
|
||||
}
|
||||
|
||||
None
|
||||
}
|
||||
|
@ -38,6 +38,7 @@ use conrod_core::{
|
||||
};
|
||||
use specs::Join;
|
||||
use std::collections::VecDeque;
|
||||
use std::{cell::RefCell, rc::Rc};
|
||||
use vek::*;
|
||||
|
||||
const XP_COLOR: Color = Color::Rgba(0.59, 0.41, 0.67, 1.0);
|
||||
@ -522,7 +523,9 @@ impl Hud {
|
||||
}
|
||||
|
||||
// MiniMap
|
||||
match MiniMap::new(&self.show, &self.imgs, &self.fonts).set(self.ids.minimap, ui_widgets) {
|
||||
match MiniMap::new(&self.show, client, &self.imgs, &self.fonts)
|
||||
.set(self.ids.minimap, ui_widgets)
|
||||
{
|
||||
Some(minimap::Event::Toggle) => self.show.toggle_mini_map(),
|
||||
None => {}
|
||||
}
|
||||
|
@ -27,7 +27,9 @@ impl Meshable for Segment {
|
||||
pos,
|
||||
offs + pos.map(|e| e as f32),
|
||||
col,
|
||||
|origin, norm, col, ao, light| FigureVertex::new(origin, norm, col * ao * light, 0),
|
||||
|origin, norm, col, ao, light| {
|
||||
FigureVertex::new(origin, norm, col * ao * light, 0)
|
||||
},
|
||||
true,
|
||||
&[[[1.0; 3]; 3]; 3],
|
||||
);
|
||||
|
@ -79,7 +79,14 @@ impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone> Meshable for
|
||||
pos,
|
||||
offs,
|
||||
col,
|
||||
|pos, norm, col, ao, light| TerrainVertex::new(pos, norm, Lerp::lerp(Rgb::zero(), col, ao), light),
|
||||
|pos, norm, col, ao, light| {
|
||||
TerrainVertex::new(
|
||||
pos,
|
||||
norm,
|
||||
Lerp::lerp(Rgb::zero(), col, ao),
|
||||
light,
|
||||
)
|
||||
},
|
||||
false,
|
||||
&neighbour_light,
|
||||
);
|
||||
@ -97,7 +104,8 @@ impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone> Meshable for
|
||||
.ok()
|
||||
.and_then(|vox| vox.get_opacity())
|
||||
{
|
||||
(neighbour_light[0][i][j] * (1.0 - opacity * 0.2)).max(1.0 - opacity * 1.0)
|
||||
(neighbour_light[0][i][j] * (1.0 - opacity * 0.2))
|
||||
.max(1.0 - opacity * 1.0)
|
||||
} else {
|
||||
(neighbour_light[0][i][j] * 1.035).min(1.0)
|
||||
};
|
||||
@ -110,7 +118,8 @@ impl<V: BaseVol<Vox = Block> + ReadVol + Debug, S: VolSize + Clone> Meshable for
|
||||
.map(|col| col.iter())
|
||||
.flatten()
|
||||
.copied()
|
||||
.fold(0.0, |a, x| a + x) / 9.0; 3]; 3];
|
||||
.fold(0.0, |a, x| a + x)
|
||||
/ 9.0; 3]; 3];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,14 @@ use crate::render::{
|
||||
/// Given volume, position, and cardinal directions, compute each vertex's AO value.
|
||||
/// `dirs` should be a slice of length 5 so that the sliding window of size 2 over the slice
|
||||
/// yields each vertex' adjacent positions.
|
||||
fn get_ao_quad<V: ReadVol>(vol: &V, pos: Vec3<i32>, shift: Vec3<i32>, dirs: &[Vec3<i32>], corners: &[[usize; 3]; 4], darknesses: &[[[f32; 3]; 3]; 3]) -> Vec4<(f32, f32)> {
|
||||
fn get_ao_quad<V: ReadVol>(
|
||||
vol: &V,
|
||||
pos: Vec3<i32>,
|
||||
shift: Vec3<i32>,
|
||||
dirs: &[Vec3<i32>],
|
||||
corners: &[[usize; 3]; 4],
|
||||
darknesses: &[[[f32; 3]; 3]; 3],
|
||||
) -> Vec4<(f32, f32)> {
|
||||
dirs.windows(2)
|
||||
.enumerate()
|
||||
.map(|(i, offs)| {
|
||||
@ -32,20 +39,23 @@ fn get_ao_quad<V: ReadVol>(vol: &V, pos: Vec3<i32>, shift: Vec3<i32>, dirs: &[Ve
|
||||
.flatten()
|
||||
.fold(0.0, |a: f32, x| a.max(*x));
|
||||
|
||||
(darkness, if s1 && s2 {
|
||||
0.0
|
||||
} else {
|
||||
let corner = vol
|
||||
.get(pos + shift + offs[0] + offs[1])
|
||||
.map(|v| !v.is_empty())
|
||||
.unwrap_or(false);
|
||||
// Map both 1 and 2 neighbors to 0.5 occlusion.
|
||||
if s1 || s2 || corner {
|
||||
0.5
|
||||
(
|
||||
darkness,
|
||||
if s1 && s2 {
|
||||
0.0
|
||||
} else {
|
||||
1.0
|
||||
}
|
||||
})
|
||||
let corner = vol
|
||||
.get(pos + shift + offs[0] + offs[1])
|
||||
.map(|v| !v.is_empty())
|
||||
.unwrap_or(false);
|
||||
// Map both 1 and 2 neighbors to 0.5 occlusion.
|
||||
if s1 || s2 || corner {
|
||||
0.5
|
||||
} else {
|
||||
1.0
|
||||
}
|
||||
},
|
||||
)
|
||||
})
|
||||
.collect::<Vec4<(f32, f32)>>()
|
||||
}
|
||||
@ -73,25 +83,13 @@ fn create_quad<P: Pipeline, F: Fn(Vec3<f32>, Vec3<f32>, Rgb<f32>, f32, f32) -> P
|
||||
vcons(origin + unit_y, norm, col, darkness[3], ao_map[3]),
|
||||
vcons(origin, norm, col, darkness[0], ao_map[0]),
|
||||
vcons(origin + unit_x, norm, col, darkness[1], ao_map[1]),
|
||||
vcons(
|
||||
origin + unit_x + unit_y,
|
||||
norm,
|
||||
col,
|
||||
darkness[2],
|
||||
ao_map[2],
|
||||
),
|
||||
vcons(origin + unit_x + unit_y, norm, col, darkness[2], ao_map[2]),
|
||||
)
|
||||
} else {
|
||||
Quad::new(
|
||||
vcons(origin, norm, col, darkness[0], ao_map[0]),
|
||||
vcons(origin + unit_x, norm, col, darkness[1], ao_map[1]),
|
||||
vcons(
|
||||
origin + unit_x + unit_y,
|
||||
norm,
|
||||
col,
|
||||
darkness[2],
|
||||
ao_map[2],
|
||||
),
|
||||
vcons(origin + unit_x + unit_y, norm, col, darkness[2], ao_map[2]),
|
||||
vcons(origin + unit_y, norm, col, darkness[3], ao_map[3]),
|
||||
)
|
||||
}
|
||||
@ -125,7 +123,14 @@ pub fn push_vox_verts<
|
||||
Vec3::unit_y(),
|
||||
-Vec3::unit_x(),
|
||||
col,
|
||||
get_ao_quad(vol, pos, -Vec3::unit_x(), &[-z, -y, z, y, -z], &[[0; 3]; 4], darknesses),
|
||||
get_ao_quad(
|
||||
vol,
|
||||
pos,
|
||||
-Vec3::unit_x(),
|
||||
&[-z, -y, z, y, -z],
|
||||
&[[0; 3]; 4],
|
||||
darknesses,
|
||||
),
|
||||
&vcons,
|
||||
));
|
||||
}
|
||||
@ -141,7 +146,14 @@ pub fn push_vox_verts<
|
||||
Vec3::unit_z(),
|
||||
Vec3::unit_x(),
|
||||
col,
|
||||
get_ao_quad(vol, pos, Vec3::unit_x(), &[-y, -z, y, z, -y], &[[0; 3]; 4], darknesses),
|
||||
get_ao_quad(
|
||||
vol,
|
||||
pos,
|
||||
Vec3::unit_x(),
|
||||
&[-y, -z, y, z, -y],
|
||||
&[[0; 3]; 4],
|
||||
darknesses,
|
||||
),
|
||||
&vcons,
|
||||
));
|
||||
}
|
||||
@ -157,7 +169,14 @@ pub fn push_vox_verts<
|
||||
Vec3::unit_z(),
|
||||
-Vec3::unit_y(),
|
||||
col,
|
||||
get_ao_quad(vol, pos, -Vec3::unit_y(), &[-x, -z, x, z, -x], &[[0; 3]; 4], darknesses),
|
||||
get_ao_quad(
|
||||
vol,
|
||||
pos,
|
||||
-Vec3::unit_y(),
|
||||
&[-x, -z, x, z, -x],
|
||||
&[[0; 3]; 4],
|
||||
darknesses,
|
||||
),
|
||||
&vcons,
|
||||
));
|
||||
}
|
||||
@ -173,7 +192,14 @@ pub fn push_vox_verts<
|
||||
Vec3::unit_x(),
|
||||
Vec3::unit_y(),
|
||||
col,
|
||||
get_ao_quad(vol, pos, Vec3::unit_y(), &[-z, -x, z, x, -z], &[[0; 3]; 4], darknesses),
|
||||
get_ao_quad(
|
||||
vol,
|
||||
pos,
|
||||
Vec3::unit_y(),
|
||||
&[-z, -x, z, x, -z],
|
||||
&[[0; 3]; 4],
|
||||
darknesses,
|
||||
),
|
||||
&vcons,
|
||||
));
|
||||
}
|
||||
@ -189,7 +215,14 @@ pub fn push_vox_verts<
|
||||
Vec3::unit_x(),
|
||||
-Vec3::unit_z(),
|
||||
col,
|
||||
get_ao_quad(vol, pos, -Vec3::unit_z(), &[-y, -x, y, x, -y], &[[0; 3]; 4], darknesses),
|
||||
get_ao_quad(
|
||||
vol,
|
||||
pos,
|
||||
-Vec3::unit_z(),
|
||||
&[-y, -x, y, x, -y],
|
||||
&[[0; 3]; 4],
|
||||
darknesses,
|
||||
),
|
||||
&vcons,
|
||||
));
|
||||
}
|
||||
@ -205,7 +238,14 @@ pub fn push_vox_verts<
|
||||
Vec3::unit_y(),
|
||||
Vec3::unit_z(),
|
||||
col,
|
||||
get_ao_quad(vol, pos, Vec3::unit_z(), &[-x, -y, x, y, -x], &[[0, 0, 1], [1, 0, 1], [1, 1, 1], [0, 1, 1]], darknesses),
|
||||
get_ao_quad(
|
||||
vol,
|
||||
pos,
|
||||
Vec3::unit_z(),
|
||||
&[-x, -y, x, y, -x],
|
||||
&[[0, 0, 1], [1, 0, 1], [1, 1, 1], [0, 1, 1]],
|
||||
darknesses,
|
||||
),
|
||||
&vcons,
|
||||
));
|
||||
}
|
||||
|
@ -26,16 +26,22 @@ fn main() {
|
||||
|
||||
let (alt, location) = sampler
|
||||
.get(pos)
|
||||
.map(|sample| (
|
||||
sample.alt.sub(64.0).add(gain).mul(0.7).max(0.0).min(255.0) as u8,
|
||||
sample.location,
|
||||
))
|
||||
.map(|sample| {
|
||||
(
|
||||
sample.alt.sub(64.0).add(gain).mul(0.7).max(0.0).min(255.0) as u8,
|
||||
sample.location,
|
||||
)
|
||||
})
|
||||
.unwrap_or((0, None));
|
||||
|
||||
let loc_color = location.map(|l| (
|
||||
l.name().bytes().nth(0).unwrap() * 17,
|
||||
l.name().bytes().nth(1).unwrap() * 17,
|
||||
)).unwrap_or((0, 0));
|
||||
let loc_color = location
|
||||
.map(|l| {
|
||||
(
|
||||
l.name().bytes().nth(0).unwrap() * 17,
|
||||
l.name().bytes().nth(1).unwrap() * 17,
|
||||
)
|
||||
})
|
||||
.unwrap_or((0, 0));
|
||||
|
||||
buf[j * W + i] = u32::from_le_bytes([loc_color.0, loc_color.1, alt, alt]);
|
||||
}
|
||||
|
@ -170,7 +170,15 @@ impl<'a> SamplerMut for BlockGen<'a> {
|
||||
let field1 = RandomField::new(self.world.sim().seed + 1);
|
||||
let field2 = RandomField::new(self.world.sim().seed + 2);
|
||||
|
||||
Some(Block::new(2, stone_col - Rgb::new(field0.get(wpos) as u8 % 32, field1.get(wpos) as u8 % 32, field2.get(wpos) as u8 % 32)))
|
||||
Some(Block::new(
|
||||
2,
|
||||
stone_col
|
||||
- Rgb::new(
|
||||
field0.get(wpos) as u8 % 32,
|
||||
field1.get(wpos) as u8 % 32,
|
||||
field2.get(wpos) as u8 % 32,
|
||||
),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -1,10 +1,4 @@
|
||||
use crate::{
|
||||
all::ForestKind,
|
||||
util::Sampler,
|
||||
sim::Location,
|
||||
World,
|
||||
CONFIG,
|
||||
};
|
||||
use crate::{all::ForestKind, sim::Location, util::Sampler, World, CONFIG};
|
||||
use common::{
|
||||
terrain::{Block, TerrainChunkSize},
|
||||
vol::{VolSize, Vox},
|
||||
@ -174,5 +168,5 @@ pub struct ColumnSample<'a> {
|
||||
pub rock: f32,
|
||||
pub cliff: f32,
|
||||
pub temp: f32,
|
||||
pub location: Option<&'a Arc<Location>>
|
||||
pub location: Option<&'a Arc<Location>>,
|
||||
}
|
||||
|
@ -62,18 +62,19 @@ impl World {
|
||||
let water = Block::new(5, Rgb::new(100, 150, 255));
|
||||
|
||||
let chunk_size2d = Vec2::from(TerrainChunkSize::SIZE);
|
||||
let (base_z, sim_chunk) = match self.sim.get_interpolated(
|
||||
chunk_pos.map2(chunk_size2d, |e, sz: u32| e * sz as i32 + sz as i32 / 2),
|
||||
|chunk| chunk.get_base_z(),
|
||||
).and_then(|base_z| self.sim.get(chunk_pos).map(|sim_chunk| (base_z, sim_chunk))) {
|
||||
let (base_z, sim_chunk) = match self
|
||||
.sim
|
||||
.get_interpolated(
|
||||
chunk_pos.map2(chunk_size2d, |e, sz: u32| e * sz as i32 + sz as i32 / 2),
|
||||
|chunk| chunk.get_base_z(),
|
||||
)
|
||||
.and_then(|base_z| self.sim.get(chunk_pos).map(|sim_chunk| (base_z, sim_chunk)))
|
||||
{
|
||||
Some((base_z, sim_chunk)) => (base_z as i32, sim_chunk),
|
||||
None => return TerrainChunk::new(0, water, air, TerrainChunkMeta::void()),
|
||||
};
|
||||
|
||||
let meta = TerrainChunkMeta::new(
|
||||
sim_chunk.get_name(),
|
||||
sim_chunk.get_biome(),
|
||||
);
|
||||
let meta = TerrainChunkMeta::new(sim_chunk.get_name(), sim_chunk.get_biome());
|
||||
|
||||
let mut chunk = TerrainChunk::new(base_z - 8, stone, air, meta);
|
||||
|
||||
|
@ -9,16 +9,12 @@ use common::{
|
||||
vol::VolSize,
|
||||
};
|
||||
use noise::{BasicMulti, HybridMulti, MultiFractal, NoiseFn, RidgedMulti, Seedable, SuperSimplex};
|
||||
use rand::{prng::XorShiftRng, Rng, SeedableRng};
|
||||
use std::{
|
||||
ops::{Add, Div, Mul, Neg, Sub},
|
||||
sync::Arc,
|
||||
};
|
||||
use vek::*;
|
||||
use rand::{
|
||||
Rng,
|
||||
SeedableRng,
|
||||
prng::XorShiftRng,
|
||||
};
|
||||
|
||||
pub const WORLD_SIZE: Vec2<usize> = Vec2 { x: 1024, y: 1024 };
|
||||
|
||||
@ -86,10 +82,22 @@ impl WorldSim {
|
||||
chunks,
|
||||
gen_ctx,
|
||||
rng: XorShiftRng::from_seed([
|
||||
(seed >> 0) as u8, 0, 0, 0,
|
||||
(seed >> 8) as u8, 0, 0, 0,
|
||||
(seed >> 16) as u8, 0, 0, 0,
|
||||
(seed >> 24) as u8, 0, 0, 0,
|
||||
(seed >> 0) as u8,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
(seed >> 8) as u8,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
(seed >> 16) as u8,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
(seed >> 24) as u8,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
]),
|
||||
};
|
||||
|
||||
@ -127,15 +135,14 @@ impl WorldSim {
|
||||
|
||||
let location = self.get(pos).unwrap().location.clone();
|
||||
|
||||
let rpos = Vec2::new(
|
||||
rng.gen::<i32>(),
|
||||
rng.gen::<i32>(),
|
||||
).map(|e| e.abs() % 3 - 1);
|
||||
let rpos =
|
||||
Vec2::new(rng.gen::<i32>(), rng.gen::<i32>()).map(|e| e.abs() % 3 - 1);
|
||||
|
||||
if let Some(other) = &mut self.get_mut(pos + rpos) {
|
||||
if other.location.is_none()
|
||||
&& rng.gen::<f32>() > other.chaos * 1.5
|
||||
&& other.alt > CONFIG.sea_level {
|
||||
&& other.alt > CONFIG.sea_level
|
||||
{
|
||||
other.location = location;
|
||||
}
|
||||
}
|
||||
@ -206,8 +213,7 @@ impl WorldSim {
|
||||
let mut x = [T::default(); 4];
|
||||
|
||||
for (x_idx, j) in (-1..3).enumerate() {
|
||||
let y0 =
|
||||
f(self.get(pos.map2(Vec2::new(j, -1), |e, q| e.max(0.0) as i32 + q))?);
|
||||
let y0 = f(self.get(pos.map2(Vec2::new(j, -1), |e, q| e.max(0.0) as i32 + q))?);
|
||||
let y1 = f(self.get(pos.map2(Vec2::new(j, 0), |e, q| e.max(0.0) as i32 + q))?);
|
||||
let y2 = f(self.get(pos.map2(Vec2::new(j, 1), |e, q| e.max(0.0) as i32 + q))?);
|
||||
let y3 = f(self.get(pos.map2(Vec2::new(j, 2), |e, q| e.max(0.0) as i32 + q))?);
|
||||
@ -252,7 +258,12 @@ impl SimChunk {
|
||||
let chaos = (gen_ctx.chaos_nz.get((wposf.div(4_000.0)).into_array()) as f32)
|
||||
.add(1.0)
|
||||
.mul(0.5)
|
||||
.mul((gen_ctx.chaos_nz.get((wposf.div(8_000.0)).into_array()) as f32).powf(2.0).add(0.5).min(1.0))
|
||||
.mul(
|
||||
(gen_ctx.chaos_nz.get((wposf.div(8_000.0)).into_array()) as f32)
|
||||
.powf(2.0)
|
||||
.add(0.5)
|
||||
.min(1.0),
|
||||
)
|
||||
.powf(1.4)
|
||||
.add(0.1 * hill);
|
||||
|
||||
@ -338,9 +349,7 @@ impl SimChunk {
|
||||
}
|
||||
|
||||
pub fn get_name(&self) -> Option<String> {
|
||||
self.location
|
||||
.as_ref()
|
||||
.map(|l| l.name().to_string())
|
||||
self.location.as_ref().map(|l| l.name().to_string())
|
||||
}
|
||||
|
||||
pub fn get_biome(&self) -> BiomeKind {
|
||||
|
Loading…
Reference in New Issue
Block a user