From 23e779c0d730718c1708c8ce71d830438a1454e4 Mon Sep 17 00:00:00 2001 From: Thinkofname Date: Wed, 20 Apr 2016 20:07:39 +0100 Subject: [PATCH] Make BlockSnapshots use BlockStorage --- src/world/mod.rs | 9 ++++----- src/world/storage.rs | 8 ++++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/world/mod.rs b/src/world/mod.rs index d67a8d8..8f198b6 100644 --- a/src/world/mod.rs +++ b/src/world/mod.rs @@ -473,7 +473,7 @@ impl World { pub fn capture_snapshot(&self, x: i32, y: i32, z: i32, w: i32, h: i32, d: i32) -> Snapshot { use std::cmp::{min, max}; 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), sky_light: nibble::Array::new((w * h * 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 { snapshot.sky_light.set(i, 0xF); - snapshot.blocks[i] = block::Missing{}.get_steven_id() as u16; } let cx1 = x >> 4; @@ -672,7 +671,7 @@ impl block::WorldAccess for World { } pub struct Snapshot { - blocks: Vec, + blocks: storage::BlockStorage, block_light: nibble::Array, sky_light: nibble::Array, biomes: Vec, @@ -694,12 +693,12 @@ impl Snapshot { } 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) { 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 { diff --git a/src/world/storage.rs b/src/world/storage.rs index 3639cda..4a2e776 100644 --- a/src/world/storage.rs +++ b/src/world/storage.rs @@ -14,14 +14,18 @@ pub struct BlockStorage { impl 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 { blocks: bit::Map::new(size, 4), block_map: vec![ - (block::Air{}, 0xFFFFFFFF) + (def, size as u32) ], rev_block_map: HashMap::with_hasher(BuildHasherDefault::default()), }; - storage.rev_block_map.insert(block::Air{}, 0); + storage.rev_block_map.insert(def, 0); storage }