bug fixes, faster node texture shift, loading +z not working (0,0,2 chunk loading only one line)

This commit is contained in:
Piotrek
2021-05-15 17:07:20 +02:00
parent 00c518b9c1
commit 16edbfea42
5 changed files with 59 additions and 54 deletions
+21 -24
View File
@@ -7,6 +7,7 @@ use winit::event::Event;
use player::Player;
use world::World;
const RENDER_DIST: i32 = 1;
pub enum GameState {
Paused,
@@ -34,9 +35,9 @@ impl Game {
};
// Preload chunks around player
for x in -2..2 {
for z in -2..2 {
let pos = Vector3{x, y: 00, z};
for x in -RENDER_DIST..RENDER_DIST+1 {
for z in -RENDER_DIST..RENDER_DIST+1 {
let pos = Vector3{x, y: 0, z};
if instance.world.load_chunk(pos) {
let chunk = instance.world.get_chunk(&pos).unwrap();
chunk.write_to(renderer, pos * world::chunk::SIZE as i32);
@@ -81,35 +82,31 @@ impl Game {
if self.prev_chunk_pos == None || self.prev_chunk_pos != Some(chunk_pos) {
renderer.get_ui().set_text("World", 2, format!("Chunk: {}, {}, {}", chunk_pos.x, chunk_pos.y, chunk_pos.z));
// Shift world
let dir = chunk_pos - self.prev_chunk_pos.unwrap_or(chunk_pos); //TODO: clamp to -1,1
renderer.shift(dir * world::chunk::SIZE as i32);
if dir.x != 0 || dir.y != 0 || dir.z != 0 {
// Load chunks at the edge
let center = chunk_pos.clone() + 2*dir;
let mask = Vector3{x: dir.x.abs(), y: dir.y.abs(), z: dir.z.abs()};
println!("Load at {:?}", center);
// Shift world
renderer.shift(dir * world::chunk::SIZE as i32);
for a in -2..3 {
let pos = center + Vector3{x: mask.z*a, y: 0, z: mask.x*a};
// 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()};
println!("Load at {:?}", center);
let pos = center; //+ Vector3{x: mask.z*a, y: 0, z: mask.x*a};
self.world.load_chunk(pos);
let chunk = self.world.get_chunk(&pos).unwrap();
chunk.write_to(renderer, pos * world::chunk::SIZE as i32);
// 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);
// let chunk = self.world.get_chunk(&pos).unwrap();
// chunk.write_to(renderer, pos * world::chunk::SIZE as i32);
// }
}
//println!("Writing chunk to {:?}", pos * world::chunk::SIZE as i32);
// for i in -2..2 {
// }
// if self.world.load_chunk(chunk_pos) {
// let chunk = self.world.get_chunk(&chunk_pos).unwrap();
// chunk.write_to(renderer, chunk_pos * world::chunk::SIZE as i32);
// println!("Writing chunk to {:?}", chunk_pos * world::chunk::SIZE as i32);
// }
self.prev_chunk_pos = Some(chunk_pos);
}