veloren/world/examples/view.rs

77 lines
2.1 KiB
Rust
Raw Normal View History

use std::ops::{Add, Mul, Sub};
use vek::*;
use veloren_world::{sim::WorldOpts, util::Sampler, World};
const W: usize = 640;
const H: usize = 480;
fn main() {
let world = World::generate(0, WorldOpts {
seed_elements: true,
..WorldOpts::default()
});
2019-06-15 12:34:28 +00:00
let sampler = world.sample_columns();
let mut win =
minifb::Window::new("World Viewer", W, H, minifb::WindowOptions::default()).unwrap();
let mut focus = Vec2::zero();
let mut gain = 1.0;
2019-06-18 21:22:31 +00:00
let mut scale = 4;
while win.is_open() {
let mut buf = vec![0; W * H];
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;
2020-03-27 13:16:02 +00:00
let (alt, place) = sampler
2019-06-15 12:34:28 +00:00
.get(pos)
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));
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]);
}
}
let spd = 32;
if win.is_key_down(minifb::Key::W) {
2019-06-18 21:22:31 +00:00
focus.y -= spd * scale;
}
if win.is_key_down(minifb::Key::A) {
2019-06-18 21:22:31 +00:00
focus.x -= spd * scale;
}
if win.is_key_down(minifb::Key::S) {
2019-06-18 21:22:31 +00:00
focus.y += spd * scale;
}
if win.is_key_down(minifb::Key::D) {
2019-06-18 21:22:31 +00:00
focus.x += spd * scale;
}
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
}
2020-04-23 19:05:44 +00:00
win.update_with_buffer_size(&buf, W, H).unwrap();
}
}