2019-05-21 22:31:38 +00:00
|
|
|
use std::ops::{Add, Mul, Sub};
|
2019-05-21 00:57:16 +00:00
|
|
|
use vek::*;
|
2019-06-15 12:34:28 +00:00
|
|
|
use veloren_world::{util::Sampler, World};
|
2019-05-21 00:57:16 +00:00
|
|
|
|
|
|
|
const W: usize = 640;
|
|
|
|
const H: usize = 480;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let world = World::generate(0);
|
|
|
|
|
2019-06-15 12:34:28 +00:00
|
|
|
let sampler = world.sample_columns();
|
|
|
|
|
2019-05-21 22:31:38 +00:00
|
|
|
let mut win =
|
|
|
|
minifb::Window::new("World Viewer", W, H, minifb::WindowOptions::default()).unwrap();
|
2019-05-21 00:57:16 +00:00
|
|
|
|
|
|
|
let mut focus = Vec2::zero();
|
|
|
|
let mut gain = 1.0;
|
|
|
|
|
|
|
|
while win.is_open() {
|
2019-06-15 14:50:54 +00:00
|
|
|
let mut buf = vec![0; W * H];
|
2019-05-21 00:57:16 +00:00
|
|
|
|
|
|
|
for i in 0..W {
|
|
|
|
for j in 0..H {
|
|
|
|
let pos = focus + Vec2::new(i as i32, j as i32) * 4;
|
|
|
|
|
2019-06-15 12:34:28 +00:00
|
|
|
let alt = sampler
|
|
|
|
.get(pos)
|
2019-05-21 22:31:38 +00:00
|
|
|
.map(|sample| sample.alt.sub(64.0).add(gain).mul(0.7).max(0.0).min(255.0) as u8)
|
2019-05-21 00:57:16 +00:00
|
|
|
.unwrap_or(0);
|
|
|
|
|
|
|
|
buf[j * W + i] = u32::from_le_bytes([alt; 4]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let spd = 32;
|
|
|
|
if win.is_key_down(minifb::Key::W) {
|
|
|
|
focus.y -= spd;
|
|
|
|
}
|
|
|
|
if win.is_key_down(minifb::Key::A) {
|
|
|
|
focus.x -= spd;
|
|
|
|
}
|
|
|
|
if win.is_key_down(minifb::Key::S) {
|
|
|
|
focus.y += spd;
|
|
|
|
}
|
|
|
|
if win.is_key_down(minifb::Key::D) {
|
|
|
|
focus.x += spd;
|
|
|
|
}
|
|
|
|
if win.is_key_down(minifb::Key::Q) {
|
|
|
|
gain += 10.0;
|
|
|
|
}
|
|
|
|
if win.is_key_down(minifb::Key::E) {
|
|
|
|
gain -= 10.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
win.update_with_buffer(&buf).unwrap();
|
|
|
|
}
|
|
|
|
}
|