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-12-03 01:07:44 +00:00
|
|
|
use veloren_world::{sim::WorldOpts, util::Sampler, World};
|
2019-05-21 00:57:16 +00:00
|
|
|
|
|
|
|
const W: usize = 640;
|
|
|
|
const H: usize = 480;
|
|
|
|
|
|
|
|
fn main() {
|
2020-02-01 20:39:39 +00:00
|
|
|
let world = World::generate(0, WorldOpts {
|
|
|
|
seed_elements: true,
|
|
|
|
..WorldOpts::default()
|
|
|
|
});
|
2019-05-21 00:57:16 +00:00
|
|
|
|
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;
|
2019-06-18 21:22:31 +00:00
|
|
|
let mut scale = 4;
|
2019-05-21 00:57:16 +00:00
|
|
|
|
|
|
|
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 {
|
2019-06-18 21:22:31 +00:00
|
|
|
let pos = focus + Vec2::new(i as i32, j as i32) * scale;
|
2019-05-21 00:57:16 +00:00
|
|
|
|
2020-03-27 13:16:02 +00:00
|
|
|
let (alt, place) = sampler
|
2020-08-12 17:29:51 +00:00
|
|
|
.get((pos, world.index()))
|
2019-06-19 14:55:26 +00:00
|
|
|
.map(|sample| {
|
|
|
|
(
|
|
|
|
sample.alt.sub(64.0).add(gain).mul(0.7).max(0.0).min(255.0) as u8,
|
2020-03-27 13:16:02 +00:00
|
|
|
sample.chunk.place,
|
2019-06-19 14:55:26 +00:00
|
|
|
)
|
|
|
|
})
|
2019-06-18 21:22:31 +00:00
|
|
|
.unwrap_or((0, None));
|
2019-05-21 00:57:16 +00:00
|
|
|
|
2020-03-27 13:16:02 +00:00
|
|
|
let place_color = place
|
|
|
|
.map(|p| ((p.id() % 256) as u8 * 17, (p.id() % 256) as u8 * 13))
|
2019-06-19 14:55:26 +00:00
|
|
|
.unwrap_or((0, 0));
|
2019-06-18 21:22:31 +00:00
|
|
|
|
2020-03-27 13:16:02 +00:00
|
|
|
buf[j * W + i] = u32::from_le_bytes([place_color.0, place_color.1, alt, alt]);
|
2019-05-21 00:57:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let spd = 32;
|
|
|
|
if win.is_key_down(minifb::Key::W) {
|
2019-06-18 21:22:31 +00:00
|
|
|
focus.y -= spd * scale;
|
2019-05-21 00:57:16 +00:00
|
|
|
}
|
|
|
|
if win.is_key_down(minifb::Key::A) {
|
2019-06-18 21:22:31 +00:00
|
|
|
focus.x -= spd * scale;
|
2019-05-21 00:57:16 +00:00
|
|
|
}
|
|
|
|
if win.is_key_down(minifb::Key::S) {
|
2019-06-18 21:22:31 +00:00
|
|
|
focus.y += spd * scale;
|
2019-05-21 00:57:16 +00:00
|
|
|
}
|
|
|
|
if win.is_key_down(minifb::Key::D) {
|
2019-06-18 21:22:31 +00:00
|
|
|
focus.x += spd * scale;
|
2019-05-21 00:57:16 +00:00
|
|
|
}
|
|
|
|
if win.is_key_down(minifb::Key::Q) {
|
|
|
|
gain += 10.0;
|
|
|
|
}
|
|
|
|
if win.is_key_down(minifb::Key::E) {
|
|
|
|
gain -= 10.0;
|
|
|
|
}
|
2019-06-18 21:22:31 +00:00
|
|
|
if win.is_key_down(minifb::Key::R) {
|
2019-06-22 21:44:27 +00:00
|
|
|
scale += 6;
|
2019-06-18 21:22:31 +00:00
|
|
|
}
|
|
|
|
if win.is_key_down(minifb::Key::F) {
|
2019-06-22 21:44:27 +00:00
|
|
|
scale -= 6;
|
2019-06-18 21:22:31 +00:00
|
|
|
}
|
2019-05-21 00:57:16 +00:00
|
|
|
|
2020-04-23 19:05:44 +00:00
|
|
|
win.update_with_buffer_size(&buf, W, H).unwrap();
|
2019-05-21 00:57:16 +00:00
|
|
|
}
|
|
|
|
}
|