mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Updated and fixed world viewer example
This commit is contained in:
parent
a9d30bbfb6
commit
bab7746a8a
@ -1,6 +1,6 @@
|
|||||||
use std::ops::{Add, Mul, Sub};
|
use std::ops::{Add, Mul, Sub};
|
||||||
use vek::*;
|
use vek::*;
|
||||||
use veloren_world::World;
|
use veloren_world::{util::Sampler, World};
|
||||||
|
|
||||||
const W: usize = 640;
|
const W: usize = 640;
|
||||||
const H: usize = 480;
|
const H: usize = 480;
|
||||||
@ -8,6 +8,8 @@ const H: usize = 480;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let world = World::generate(0);
|
let world = World::generate(0);
|
||||||
|
|
||||||
|
let sampler = world.sample_columns();
|
||||||
|
|
||||||
let mut win =
|
let mut win =
|
||||||
minifb::Window::new("World Viewer", W, H, minifb::WindowOptions::default()).unwrap();
|
minifb::Window::new("World Viewer", W, H, minifb::WindowOptions::default()).unwrap();
|
||||||
|
|
||||||
@ -21,10 +23,8 @@ fn main() {
|
|||||||
for j in 0..H {
|
for j in 0..H {
|
||||||
let pos = focus + Vec2::new(i as i32, j as i32) * 4;
|
let pos = focus + Vec2::new(i as i32, j as i32) * 4;
|
||||||
|
|
||||||
let alt = world
|
let alt = sampler
|
||||||
.sim()
|
.get(pos)
|
||||||
.sampler()
|
|
||||||
.sample_2d(pos)
|
|
||||||
.map(|sample| sample.alt.sub(64.0).add(gain).mul(0.7).max(0.0).min(255.0) as u8)
|
.map(|sample| sample.alt.sub(64.0).add(gain).mul(0.7).max(0.0).min(255.0) as u8)
|
||||||
.unwrap_or(0);
|
.unwrap_or(0);
|
||||||
|
|
||||||
|
@ -3,16 +3,16 @@
|
|||||||
mod all;
|
mod all;
|
||||||
mod block;
|
mod block;
|
||||||
mod column;
|
mod column;
|
||||||
mod config;
|
pub mod config;
|
||||||
mod sim;
|
mod sim;
|
||||||
mod util;
|
pub mod util;
|
||||||
|
|
||||||
// Reexports
|
// Reexports
|
||||||
pub use crate::config::CONFIG;
|
pub use crate::config::CONFIG;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
block::BlockGen,
|
block::BlockGen,
|
||||||
column::ColumnGen,
|
column::{ColumnGen, ColumnSample},
|
||||||
util::{HashCache, Sampler, SamplerMut},
|
util::{HashCache, Sampler, SamplerMut},
|
||||||
};
|
};
|
||||||
use common::{
|
use common::{
|
||||||
@ -46,7 +46,13 @@ impl World {
|
|||||||
// TODO
|
// 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))
|
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 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 x in 0..TerrainChunkSize::SIZE.x as i32 {
|
||||||
for y in 0..TerrainChunkSize::SIZE.y as i32 {
|
for y in 0..TerrainChunkSize::SIZE.y as i32 {
|
||||||
|
@ -177,7 +177,7 @@ impl SimChunk {
|
|||||||
.add(0.3)
|
.add(0.3)
|
||||||
.max(0.0);
|
.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)
|
.add(1.0)
|
||||||
.mul(0.5)
|
.mul(0.5)
|
||||||
.powf(1.4)
|
.powf(1.4)
|
||||||
|
Loading…
Reference in New Issue
Block a user