aboutsummaryrefslogtreecommitdiff
path: root/azalea-world/src
diff options
context:
space:
mode:
authormat <git@matdoes.dev>2025-02-23 17:39:17 +0000
committermat <git@matdoes.dev>2025-02-23 17:39:17 +0000
commit6a5ab34a2db56c22e1051dfaabf98322c50f53bd (patch)
treebf0e13174c5bbb2bc6885ea357683a030aff5465 /azalea-world/src
parent2be4f0f2b66eb7181badec0134c3c3565e3cbd7f (diff)
downloadazalea-drasl-6a5ab34a2db56c22e1051dfaabf98322c50f53bd.tar.xz
azalea-language now does a binary search instead of a hashmap lookup
Diffstat (limited to 'azalea-world/src')
-rwxr-xr-xazalea-world/src/bit_storage.rs12
-rwxr-xr-xazalea-world/src/chunk_storage.rs2
-rw-r--r--azalea-world/src/heightmap.rs2
-rwxr-xr-xazalea-world/src/palette.rs4
4 files changed, 12 insertions, 8 deletions
diff --git a/azalea-world/src/bit_storage.rs b/azalea-world/src/bit_storage.rs
index 1b0c1a56..7d1b72e1 100755
--- a/azalea-world/src/bit_storage.rs
+++ b/azalea-world/src/bit_storage.rs
@@ -101,7 +101,11 @@ impl Error for BitStorageError {}
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> {
+ pub fn new(
+ bits: usize,
+ size: usize,
+ data: Option<Box<[u64]>>,
+ ) -> Result<Self, BitStorageError> {
if let Some(data) = &data {
// 0 bit storage
if data.is_empty() {
@@ -132,11 +136,11 @@ impl BitStorage {
}
data
} else {
- vec![0; calculated_length]
+ vec![0; calculated_length].into()
};
Ok(BitStorage {
- data: using_data.into(),
+ data: using_data,
bits,
mask,
size,
@@ -252,7 +256,7 @@ mod tests {
1, 2, 2, 3, 4, 4, 5, 6, 6, 4, 8, 0, 7, 4, 3, 13, 15, 16, 9, 14, 10, 12, 0, 2,
];
let compact_data: [u64; 2] = [0x0020863148418841, 0x01018A7260F68C87];
- let storage = BitStorage::new(5, data.len(), Some(compact_data.to_vec())).unwrap();
+ let storage = BitStorage::new(5, data.len(), Some(Box::new(compact_data))).unwrap();
for (i, expected) in data.iter().enumerate() {
assert_eq!(storage.get(i), *expected);
diff --git a/azalea-world/src/chunk_storage.rs b/azalea-world/src/chunk_storage.rs
index 9592abbf..db5ac877 100755
--- a/azalea-world/src/chunk_storage.rs
+++ b/azalea-world/src/chunk_storage.rs
@@ -353,7 +353,7 @@ impl Chunk {
warn!("Heightmap {name} is not a long array");
continue;
};
- let data: Vec<u64> = data.iter().map(|x| *x as u64).collect();
+ let data: Box<[u64]> = data.iter().map(|x| *x as u64).collect();
let heightmap = Heightmap::new(kind, dimension_height, min_y, data);
heightmaps.insert(kind, heightmap);
}
diff --git a/azalea-world/src/heightmap.rs b/azalea-world/src/heightmap.rs
index 35142cf2..f1ef30d2 100644
--- a/azalea-world/src/heightmap.rs
+++ b/azalea-world/src/heightmap.rs
@@ -56,7 +56,7 @@ impl HeightmapKind {
}
impl Heightmap {
- pub fn new(kind: HeightmapKind, dimension_height: u32, min_y: i32, data: Vec<u64>) -> Self {
+ pub fn new(kind: HeightmapKind, dimension_height: u32, min_y: i32, data: Box<[u64]>) -> Self {
let bits = math::ceil_log2(dimension_height + 1);
let data = BitStorage::new(bits as usize, 16 * 16, Some(data)).unwrap();
Self { kind, data, min_y }
diff --git a/azalea-world/src/palette.rs b/azalea-world/src/palette.rs
index dd5f7daa..97786e7c 100755
--- a/azalea-world/src/palette.rs
+++ b/azalea-world/src/palette.rs
@@ -31,7 +31,7 @@ impl PalettedContainer {
pub fn new(container_type: PalettedContainerKind) -> Self {
let palette = Palette::SingleValue(0);
let size = container_type.size();
- let storage = BitStorage::new(0, size, Some(vec![])).unwrap();
+ let storage = BitStorage::new(0, size, Some(Box::new([]))).unwrap();
PalettedContainer {
bits_per_entry: 0,
@@ -76,7 +76,7 @@ impl PalettedContainer {
bits_per_entry.into(),
size,
if data.is_empty() {
- Some(vec![])
+ Some(Box::new([]))
} else {
// we're going to update the data after creating the bitstorage
None