writing chunks instead of blocks
This commit is contained in:
+18
-17
@@ -8,7 +8,7 @@ use winit::event::Event;
|
||||
use player::Player;
|
||||
use world::World;
|
||||
|
||||
const RENDER_DIST: i32 = 3;
|
||||
pub const RENDER_DIST: i32 = 3;
|
||||
|
||||
pub enum GameState {
|
||||
Paused,
|
||||
@@ -61,18 +61,18 @@ impl Game {
|
||||
if dir.x != 0 { dir = Vector3{x: dir.x.clamp(-1, 1), y:0, z:0 } }
|
||||
else if dir.y != 0 { dir = Vector3{x:0, y:dir.y.clamp(-1, 1), z:0 } }
|
||||
else if dir.z != 0 { dir = Vector3{x:0, y:0, z:dir.z.clamp(-1, 1) } }
|
||||
else { }
|
||||
else { self.prev_chunk_pos = Some(prev_chunk_pos+dir); return; }
|
||||
|
||||
if dir.x != 0 || dir.y != 0 || dir.z != 0 {
|
||||
// Shift world
|
||||
renderer.shift(dir * world::chunk::SIZE as i32);
|
||||
// Load chunks at the edge
|
||||
let center = chunk_pos.clone() + RENDER_DIST*dir;
|
||||
let mask = Vector3{x: dir.x.abs(), y: dir.y.abs(), z: dir.z.abs()};
|
||||
for a in -RENDER_DIST..RENDER_DIST+1 {
|
||||
let pos = center + Vector3{x: mask.z*a, y: 0, z: mask.x*a};
|
||||
self.world.load_chunk(pos);
|
||||
}
|
||||
// Shift world
|
||||
println!("Shiftin by {:?}", dir);
|
||||
renderer.shift(dir * world::chunk::SIZE as i32);
|
||||
|
||||
// Load chunks at the edge
|
||||
let center = chunk_pos.clone() + RENDER_DIST*dir;
|
||||
let mask = Vector3{x: dir.x.abs(), y: dir.y.abs(), z: dir.z.abs()};
|
||||
for a in -RENDER_DIST..RENDER_DIST+1 {
|
||||
let pos = center + Vector3{x: mask.z*a, y: 0, z: mask.x*a};
|
||||
self.world.load_chunk(pos);
|
||||
}
|
||||
|
||||
self.prev_chunk_pos = Some(prev_chunk_pos+dir);
|
||||
@@ -117,11 +117,12 @@ impl Game {
|
||||
self.world.update();
|
||||
|
||||
// Send dirty chunks to renderer
|
||||
// TODO: Unload chunks above certain radius
|
||||
for (pos, chunk) in self.world.all_chunks() {
|
||||
if chunk.dirty {
|
||||
chunk.write_to(renderer, pos * world::chunk::SIZE as i32);
|
||||
chunk.dirty = false;
|
||||
if chunk_pos == self.prev_chunk_pos.unwrap_or(chunk_pos) {
|
||||
for (pos, chunk) in self.world.all_chunks() {
|
||||
if chunk.dirty {
|
||||
renderer.write_chunk(pos, chunk);
|
||||
chunk.dirty = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user