aboutsummaryrefslogtreecommitdiff
path: root/azalea-world
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-world')
-rw-r--r--azalea-world/src/bit_storage.rs12
-rw-r--r--azalea-world/src/lib.rs9
-rw-r--r--azalea-world/src/palette.rs14
3 files changed, 30 insertions, 5 deletions
diff --git a/azalea-world/src/bit_storage.rs b/azalea-world/src/bit_storage.rs
index 9cc3a053..211a4a04 100644
--- a/azalea-world/src/bit_storage.rs
+++ b/azalea-world/src/bit_storage.rs
@@ -70,9 +70,9 @@ const MAGIC: [(i32, i32, i32); 64] = [
];
/// A compact list of integers with the given number of bits per entry.
-#[derive(Clone)]
+#[derive(Clone, Debug, Default)]
pub struct BitStorage {
- data: Vec<u64>,
+ pub data: Vec<u64>,
bits: usize,
mask: u64,
size: usize,
@@ -103,9 +103,17 @@ impl BitStorage {
/// Create a new BitStorage with the given number of bits per entry.
/// `size` is the number of entries in the BitStorage.
pub fn new(bits: usize, size: usize, data: Option<Vec<u64>>) -> Result<Self, BitStorageError> {
+ if let Some(data) = &data {
+ if data.len() == 0 {
+ // TODO: make 0 bit storage actually work
+ return Ok(BitStorage::default());
+ }
+ }
+
let values_per_long = 64 / bits;
let magic_index = values_per_long - 1;
let (divide_mul, divide_add, divide_shift) = MAGIC[magic_index as usize];
+ println!("values_per_long: {}, size: {}", values_per_long, size);
let calculated_length = (size + values_per_long - 1) / values_per_long;
let mask = (1 << bits) - 1;
diff --git a/azalea-world/src/lib.rs b/azalea-world/src/lib.rs
index 4b8c21e9..4da2fb0f 100644
--- a/azalea-world/src/lib.rs
+++ b/azalea-world/src/lib.rs
@@ -67,6 +67,15 @@ impl IndexMut<&ChunkPos> for World {
&mut self.storage[pos]
}
}
+// impl Index<&BlockPos> for World {
+// type Output = Option<Arc<Mutex<Chunk>>>;
+
+// fn index(&self, pos: &BlockPos) -> &Self::Output {
+// let chunk = &self[ChunkPos::from(pos)];
+// // chunk.
+
+// }
+// }
pub struct ChunkStorage {
view_center: ChunkPos,
diff --git a/azalea-world/src/palette.rs b/azalea-world/src/palette.rs
index db722a5b..c33992b1 100644
--- a/azalea-world/src/palette.rs
+++ b/azalea-world/src/palette.rs
@@ -1,6 +1,8 @@
use azalea_protocol::mc_buf::{McBufReadable, McBufVarReadable, McBufWritable, Readable, Writable};
use std::io::{Read, Write};
+use crate::BitStorage;
+
#[derive(Clone, Debug, Copy)]
pub enum PalettedContainerType {
Biomes,
@@ -12,7 +14,7 @@ pub struct PalettedContainer {
pub bits_per_entry: u8,
pub palette: Palette,
/// Compacted list of indices pointing to entry IDs in the Palette.
- pub data: Vec<u64>,
+ pub storage: BitStorage,
}
impl PalettedContainer {
@@ -29,17 +31,23 @@ impl PalettedContainer {
Palette::biomes_read_with_bits_per_entry(buf, bits_per_entry)?
}
};
+ let size = match type_ {
+ PalettedContainerType::BlockStates => 4096,
+ PalettedContainerType::Biomes => 64,
+ };
let data = Vec::<u64>::read_into(buf)?;
debug_assert!(
bits_per_entry != 0 || data.is_empty(),
"Bits per entry is 0 but data is not empty."
);
+ println!("data: {:?}", data);
+ let storage = BitStorage::new(bits_per_entry.into(), size, Some(data)).unwrap();
Ok(PalettedContainer {
bits_per_entry,
palette,
- data,
+ storage,
})
}
}
@@ -47,7 +55,7 @@ impl McBufWritable for PalettedContainer {
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
buf.write_byte(self.bits_per_entry)?;
self.palette.write_into(buf)?;
- self.data.write_into(buf)?;
+ self.storage.data.write_into(buf)?;
Ok(())
}
}