preloading stats
This commit is contained in:
+12
-12
@@ -1,13 +1,14 @@
|
|||||||
mod camera_controller;
|
mod camera_controller;
|
||||||
mod player;
|
mod player;
|
||||||
pub mod world;
|
pub mod world;
|
||||||
|
use std::time::Instant;
|
||||||
use crate::renderer::renderer_view::RendererView;
|
use crate::renderer::renderer_view::RendererView;
|
||||||
use cgmath::Vector3;
|
use cgmath::Vector3;
|
||||||
use winit::event::Event;
|
use winit::event::Event;
|
||||||
use player::Player;
|
use player::Player;
|
||||||
use world::World;
|
use world::World;
|
||||||
|
|
||||||
const RENDER_DIST: i32 = 1;
|
const RENDER_DIST: i32 = 3;
|
||||||
|
|
||||||
pub enum GameState {
|
pub enum GameState {
|
||||||
Paused,
|
Paused,
|
||||||
@@ -35,6 +36,8 @@ impl Game {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Preload chunks around player
|
// Preload chunks around player
|
||||||
|
let timer = Instant::now();
|
||||||
|
let mut count = 0;
|
||||||
for x in -RENDER_DIST..RENDER_DIST+1 {
|
for x in -RENDER_DIST..RENDER_DIST+1 {
|
||||||
for z in -RENDER_DIST..RENDER_DIST+1 {
|
for z in -RENDER_DIST..RENDER_DIST+1 {
|
||||||
let pos = Vector3{x, y: 0, z};
|
let pos = Vector3{x, y: 0, z};
|
||||||
@@ -42,9 +45,11 @@ impl Game {
|
|||||||
let chunk = instance.world.get_chunk(&pos).unwrap();
|
let chunk = instance.world.get_chunk(&pos).unwrap();
|
||||||
chunk.write_to(renderer, pos * world::chunk::SIZE as i32);
|
chunk.write_to(renderer, pos * world::chunk::SIZE as i32);
|
||||||
println!("Writing chunk to {:?}", pos * world::chunk::SIZE as i32);
|
println!("Writing chunk to {:?}", pos * world::chunk::SIZE as i32);
|
||||||
|
count += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
println!("Preloaded {} chunks in {} ms (about {} voxels)", count, timer.elapsed().as_millis(), count * world::block::SIZE_QB);
|
||||||
|
|
||||||
// Return generated instance
|
// Return generated instance
|
||||||
instance
|
instance
|
||||||
@@ -94,18 +99,13 @@ impl Game {
|
|||||||
let mask = Vector3{x: dir.x.abs(), y: dir.y.abs(), z: dir.z.abs()};
|
let mask = Vector3{x: dir.x.abs(), y: dir.y.abs(), z: dir.z.abs()};
|
||||||
println!("Load at {:?}", center);
|
println!("Load at {:?}", center);
|
||||||
|
|
||||||
let pos = center; //+ Vector3{x: mask.z*a, y: 0, z: mask.x*a};
|
for a in -RENDER_DIST..RENDER_DIST+1 {
|
||||||
self.world.load_chunk(pos);
|
let pos = center + Vector3{x: mask.z*a, y: 0, z: mask.x*a};
|
||||||
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 {
|
self.world.load_chunk(pos);
|
||||||
// let pos = center; //+ Vector3{x: mask.z*a, y: 0, z: mask.x*a};
|
let chunk = self.world.get_chunk(&pos).unwrap();
|
||||||
|
chunk.write_to(renderer, pos * world::chunk::SIZE as i32);
|
||||||
// self.world.load_chunk(pos);
|
}
|
||||||
// let chunk = self.world.get_chunk(&pos).unwrap();
|
|
||||||
// chunk.write_to(renderer, pos * world::chunk::SIZE as i32);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.prev_chunk_pos = Some(chunk_pos);
|
self.prev_chunk_pos = Some(chunk_pos);
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::game::world::block::WorldBlock;
|
|||||||
//note: remember to update in main.frag
|
//note: remember to update in main.frag
|
||||||
pub const BLOCK_SIZE : usize = 32; // 32x32x32 block size
|
pub const BLOCK_SIZE : usize = 32; // 32x32x32 block size
|
||||||
pub const BLOCK_TEX_SIZE : usize = 40; // number of blocks in texture (32^3 = 1GB, 40^3 = 2GB)
|
pub const BLOCK_TEX_SIZE : usize = 40; // number of blocks in texture (32^3 = 1GB, 40^3 = 2GB)
|
||||||
pub const NODE_TEX_SIZE: usize = 64; // 32x32x32 nodes in texture
|
pub const NODE_TEX_SIZE: usize = 128; // 32x32x32 nodes in texture
|
||||||
const BLOCK_SIZE_QB: usize = BLOCK_SIZE*BLOCK_SIZE*BLOCK_SIZE;
|
const BLOCK_SIZE_QB: usize = BLOCK_SIZE*BLOCK_SIZE*BLOCK_SIZE;
|
||||||
|
|
||||||
const BLOCK_TEX_SIZE_SQ: usize = BLOCK_TEX_SIZE*BLOCK_TEX_SIZE;
|
const BLOCK_TEX_SIZE_SQ: usize = BLOCK_TEX_SIZE*BLOCK_TEX_SIZE;
|
||||||
|
|||||||
Reference in New Issue
Block a user