Updated and fixed world viewer example

This commit is contained in:
Joshua Barretto 2019-06-15 13:34:28 +01:00
parent a9d30bbfb6
commit bab7746a8a
3 changed files with 17 additions and 11 deletions

View File

@ -1,6 +1,6 @@
use std::ops::{Add, Mul, Sub};
use vek::*;
use veloren_world::World;
use veloren_world::{util::Sampler, World};
const W: usize = 640;
const H: usize = 480;
@ -8,6 +8,8 @@ const H: usize = 480;
fn main() {
let world = World::generate(0);
let sampler = world.sample_columns();
let mut win =
minifb::Window::new("World Viewer", W, H, minifb::WindowOptions::default()).unwrap();
@ -21,10 +23,8 @@ fn main() {
for j in 0..H {
let pos = focus + Vec2::new(i as i32, j as i32) * 4;
let alt = world
.sim()
.sampler()
.sample_2d(pos)
let alt = sampler
.get(pos)
.map(|sample| sample.alt.sub(64.0).add(gain).mul(0.7).max(0.0).min(255.0) as u8)
.unwrap_or(0);

View File

@ -3,16 +3,16 @@
mod all;
mod block;
mod column;
mod config;
pub mod config;
mod sim;
mod util;
pub mod util;
// Reexports
pub use crate::config::CONFIG;
use crate::{
block::BlockGen,
column::ColumnGen,
column::{ColumnGen, ColumnSample},
util::{HashCache, Sampler, SamplerMut},
};
use common::{
@ -46,7 +46,13 @@ impl World {
// TODO
}
pub fn sample(&self) -> impl SamplerMut<Index = Vec3<i32>, Sample = Option<Block>> + '_ {
pub fn sample_columns(
&self,
) -> impl Sampler<Index = Vec2<i32>, Sample = Option<ColumnSample>> + '_ {
ColumnGen::new(self)
}
pub fn sample_blocks(&self) -> impl SamplerMut<Index = Vec3<i32>, Sample = Option<Block>> + '_ {
BlockGen::new(self, ColumnGen::new(self))
}
@ -66,7 +72,7 @@ impl World {
let mut chunk = TerrainChunk::new(base_z - 8, stone, air, TerrainChunkMeta::void());
let mut sampler = self.sample();
let mut sampler = self.sample_blocks();
for x in 0..TerrainChunkSize::SIZE.x as i32 {
for y in 0..TerrainChunkSize::SIZE.y as i32 {

View File

@ -177,7 +177,7 @@ impl SimChunk {
.add(0.3)
.max(0.0);
let chaos = (gen_ctx.chaos_nz.get((wposf.div(6_000.0)).into_array()) as f32)
let chaos = (gen_ctx.chaos_nz.get((wposf.div(4_000.0)).into_array()) as f32)
.add(1.0)
.mul(0.5)
.powf(1.4)