Pausing rendering, warnings cleanup, more statistics
This commit is contained in:
@@ -1,7 +1,4 @@
|
||||
use cgmath::Point3;
|
||||
use std::iter::FromIterator;
|
||||
use std::io::Write;
|
||||
use flate2::{write::DeflateEncoder, Compression};
|
||||
|
||||
pub const SIZE: usize = 32;
|
||||
pub const SIZE_QB: usize = SIZE*SIZE*SIZE;
|
||||
|
||||
+9
-15
@@ -1,20 +1,20 @@
|
||||
use std::time::Instant;
|
||||
use flate2::Compression;
|
||||
use flate2::write::DeflateEncoder;
|
||||
use flate2::read::DeflateDecoder;
|
||||
use byteorder::LittleEndian;
|
||||
use byteorder::ByteOrder;
|
||||
use cgmath::Point3;
|
||||
use std::io::Write;
|
||||
use std::convert::TryInto;
|
||||
use lzzzz::lz4;
|
||||
use std::io::Read;
|
||||
use crate::game::world::{WorldBlock, block};
|
||||
|
||||
pub const SIZE: usize = 32;
|
||||
const SIZE_SQ: usize = SIZE*SIZE;
|
||||
const SIZE_QB: usize = SIZE*SIZE*SIZE;
|
||||
|
||||
// 1 chunk times on i7-5930K
|
||||
// alg | size | compr | decom
|
||||
// raw 32.89kB 0.06s 1.19s
|
||||
// deflate fast 1.23kB 1.22s 5.46s
|
||||
// lz4 1.6kB 0.07s 1.23s
|
||||
|
||||
|
||||
pub struct WorldChunk {
|
||||
nodes: Box<[u32]>,
|
||||
blocks: Vec<WorldBlock>
|
||||
@@ -30,15 +30,15 @@ impl WorldChunk {
|
||||
|
||||
pub fn from_bytes(bytes: Vec<u8>) -> Self {
|
||||
let mut instance = Self::new();
|
||||
let (header_bytes, bytes) = bytes.split_at(128);
|
||||
let (node_bytes, block_bytes_compressed) = bytes.split_at((SIZE_QB*4) as usize);
|
||||
|
||||
// Header
|
||||
let (header_bytes, bytes) = bytes.split_at(128);
|
||||
let file_ver = header_bytes[0];
|
||||
let num_blocks = LittleEndian::read_u32(&header_bytes[1..5]) as usize;
|
||||
assert_eq!(file_ver, 1);
|
||||
|
||||
// Nodes
|
||||
let (node_bytes, block_bytes_compressed) = bytes.split_at((SIZE_QB*4) as usize);
|
||||
for i in 0..SIZE_QB {
|
||||
let idx = (i*4) as usize;
|
||||
let val = u32::from_le_bytes([node_bytes[idx], node_bytes[idx+1], node_bytes[idx+2], node_bytes[idx+3]]);
|
||||
@@ -79,12 +79,6 @@ impl WorldChunk {
|
||||
}
|
||||
lz4::compress_to_vec(&buf, &mut bytes, lz4::ACC_LEVEL_DEFAULT).unwrap();
|
||||
|
||||
|
||||
// alg | size | compr | decom
|
||||
// raw 32.89kB 0.06s 1.19s
|
||||
// deflate fast 1.23kB 1.22s 5.46s
|
||||
// lz4 1.6kB 0.07s 1.23s
|
||||
|
||||
bytes
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ impl WorldGen {
|
||||
let noise = Perlin::new();
|
||||
|
||||
// Generate height map
|
||||
let (map, max) = WorldGen::gen_height_map(block_pos.x as usize, block_pos.z as usize, &mut rng, &noise);
|
||||
let (map, _max) = WorldGen::gen_height_map(block_pos.x as usize, block_pos.z as usize, &mut rng, &noise);
|
||||
|
||||
// Fill
|
||||
for x in 0..block::SIZE {
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
mod generator;
|
||||
pub mod chunk;
|
||||
pub mod block;
|
||||
use std::time::Instant;
|
||||
use linked_hash_map::LinkedHashMap;
|
||||
use std::path::PathBuf;
|
||||
use std::path::Path;
|
||||
use std::io::Write;
|
||||
use std::io::Read;
|
||||
use std::fs;
|
||||
use cgmath::{Point3, InnerSpace};
|
||||
use cgmath::Point3;
|
||||
use std::collections::HashMap;
|
||||
use generator::WorldGen;
|
||||
use chunk::WorldChunk;
|
||||
use block::WorldBlock;
|
||||
use yaml_rust::{Yaml, YamlLoader, YamlEmitter};
|
||||
use yaml_rust::{Yaml, YamlEmitter};
|
||||
|
||||
|
||||
pub struct World {
|
||||
@@ -101,7 +99,7 @@ impl World {
|
||||
file.read_to_end(&mut bytes).expect("Failed to read file");
|
||||
let chunk = WorldChunk::from_bytes(bytes);
|
||||
|
||||
println!("loaded {:?}", pos);
|
||||
println!("Load: Chunk {}, {}, {}", pos.x, pos.y, pos.z);
|
||||
self.chunks.insert(pos, chunk);
|
||||
count += 1;
|
||||
}
|
||||
@@ -117,7 +115,7 @@ impl World {
|
||||
// Create chunk if does not exist
|
||||
if let None = self.chunks.get(&ch_pos) {
|
||||
self.chunks.insert(ch_pos.clone(), WorldChunk::new());
|
||||
println!("Alloc chunk [{}, {}, {}]", ch_pos.x, ch_pos.y, ch_pos.z);
|
||||
println!("Alloc: Chunk [{}, {}, {}]", ch_pos.x, ch_pos.y, ch_pos.z);
|
||||
}
|
||||
// Generate block for chunk
|
||||
let chunk = self.chunks.get_mut(&ch_pos).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user