Make BlockSnapshots use BlockStorage
This commit is contained in:
parent
94bfc1493b
commit
23e779c0d7
|
@ -473,7 +473,7 @@ impl World {
|
||||||
pub fn capture_snapshot(&self, x: i32, y: i32, z: i32, w: i32, h: i32, d: i32) -> Snapshot {
|
pub fn capture_snapshot(&self, x: i32, y: i32, z: i32, w: i32, h: i32, d: i32) -> Snapshot {
|
||||||
use std::cmp::{min, max};
|
use std::cmp::{min, max};
|
||||||
let mut snapshot = Snapshot {
|
let mut snapshot = Snapshot {
|
||||||
blocks: vec![0; (w * h * d) as usize],
|
blocks: storage::BlockStorage::new_default((w * h * d) as usize, block::Missing{}),
|
||||||
block_light: nibble::Array::new((w * h * d) as usize),
|
block_light: nibble::Array::new((w * h * d) as usize),
|
||||||
sky_light: nibble::Array::new((w * h * d) as usize),
|
sky_light: nibble::Array::new((w * h * d) as usize),
|
||||||
biomes: vec![0; (w * d) as usize],
|
biomes: vec![0; (w * d) as usize],
|
||||||
|
@ -483,7 +483,6 @@ impl World {
|
||||||
};
|
};
|
||||||
for i in 0 .. (w * h * d) as usize {
|
for i in 0 .. (w * h * d) as usize {
|
||||||
snapshot.sky_light.set(i, 0xF);
|
snapshot.sky_light.set(i, 0xF);
|
||||||
snapshot.blocks[i] = block::Missing{}.get_steven_id() as u16;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
let cx1 = x >> 4;
|
let cx1 = x >> 4;
|
||||||
|
@ -672,7 +671,7 @@ impl block::WorldAccess for World {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct Snapshot {
|
pub struct Snapshot {
|
||||||
blocks: Vec<u16>,
|
blocks: storage::BlockStorage,
|
||||||
block_light: nibble::Array,
|
block_light: nibble::Array,
|
||||||
sky_light: nibble::Array,
|
sky_light: nibble::Array,
|
||||||
biomes: Vec<u8>,
|
biomes: Vec<u8>,
|
||||||
|
@ -694,12 +693,12 @@ impl Snapshot {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_block(&self, x: i32, y: i32, z: i32) -> block::Block {
|
pub fn get_block(&self, x: i32, y: i32, z: i32) -> block::Block {
|
||||||
block::Block::by_steven_id(self.blocks[self.index(x, y, z)] as usize)
|
self.blocks.get(self.index(x, y, z))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_block(&mut self, x: i32, y: i32, z: i32, b: block::Block) {
|
pub fn set_block(&mut self, x: i32, y: i32, z: i32, b: block::Block) {
|
||||||
let idx = self.index(x, y, z);
|
let idx = self.index(x, y, z);
|
||||||
self.blocks[idx] = b.get_steven_id() as u16;
|
self.blocks.set(idx, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_block_light(&self, x: i32, y: i32, z: i32) -> u8 {
|
pub fn get_block_light(&self, x: i32, y: i32, z: i32) -> u8 {
|
||||||
|
|
|
@ -14,14 +14,18 @@ pub struct BlockStorage {
|
||||||
|
|
||||||
impl BlockStorage {
|
impl BlockStorage {
|
||||||
pub fn new(size: usize) -> BlockStorage {
|
pub fn new(size: usize) -> BlockStorage {
|
||||||
|
Self::new_default(size, block::Air{})
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn new_default(size: usize, def: block::Block) -> BlockStorage {
|
||||||
let mut storage = BlockStorage {
|
let mut storage = BlockStorage {
|
||||||
blocks: bit::Map::new(size, 4),
|
blocks: bit::Map::new(size, 4),
|
||||||
block_map: vec![
|
block_map: vec![
|
||||||
(block::Air{}, 0xFFFFFFFF)
|
(def, size as u32)
|
||||||
],
|
],
|
||||||
rev_block_map: HashMap::with_hasher(BuildHasherDefault::default()),
|
rev_block_map: HashMap::with_hasher(BuildHasherDefault::default()),
|
||||||
};
|
};
|
||||||
storage.rev_block_map.insert(block::Air{}, 0);
|
storage.rev_block_map.insert(def, 0);
|
||||||
storage
|
storage
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue