veloren/world/examples/city.rs
Joshua Yanovski 8ae2692b6e Allow canceling chunk generation.
Currently we only do this when no players are in range of the chunk.  We
also send the first client who posted the chunk a message indicating
that it's canceled, the hope being that this will be a performance win
in single player mode since you don't have to wait three seconds to
realize that the server won't generate the chunk for you.

We now check an atomic flag for every column sample in a chunk.  We
could probably do this less frequently, but since it's a relaxed load it
has essentially no performance impact on Intel architectures.
2019-10-16 11:39:41 +00:00

36 lines
880 B
Rust

use rand::thread_rng;
use vek::*;
use veloren_world::sim::Settlement;
const W: usize = 640;
const H: usize = 480;
fn main() {
let mut win =
minifb::Window::new("City Viewer", W, H, minifb::WindowOptions::default()).unwrap();
let settlement = Settlement::generate(&mut thread_rng());
while win.is_open() {
let mut buf = vec![0; W * H];
for i in 0..W {
for j in 0..H {
let pos = Vec2::new(i as f32, j as f32) * 0.002;
let seed = settlement.get_at(pos).map(|b| b.seed).unwrap_or(0);
buf[j * W + i] = u32::from_le_bytes([
(seed >> 0) as u8,
(seed >> 8) as u8,
(seed >> 16) as u8,
(seed >> 24) as u8,
]);
}
}
win.update_with_buffer(&buf).unwrap();
}
}