mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
Slightly improve bit storage
This commit is contained in:
parent
74c3ae52f8
commit
69e1125ecb
4 changed files with 12 additions and 8 deletions
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
|
@ -1,3 +1,3 @@
|
||||||
{
|
{
|
||||||
"editor.formatOnSave": false
|
"editor.formatOnSave": true
|
||||||
}
|
}
|
|
@ -77,8 +77,8 @@ pub struct BitStorage {
|
||||||
mask: u64,
|
mask: u64,
|
||||||
size: usize,
|
size: usize,
|
||||||
values_per_long: u8,
|
values_per_long: u8,
|
||||||
divide_mul: i32,
|
divide_mul: u64,
|
||||||
divide_add: i32,
|
divide_add: u64,
|
||||||
divide_shift: i32,
|
divide_shift: i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,16 +138,16 @@ impl BitStorage {
|
||||||
mask,
|
mask,
|
||||||
size,
|
size,
|
||||||
values_per_long: values_per_long as u8,
|
values_per_long: values_per_long as u8,
|
||||||
divide_mul,
|
divide_mul: divide_mul as u32 as u64,
|
||||||
divide_add,
|
divide_add: divide_add as u32 as u64,
|
||||||
divide_shift,
|
divide_shift,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cell_index(&self, index: u64) -> usize {
|
pub fn cell_index(&self, index: u64) -> usize {
|
||||||
// as unsigned wrap
|
// as unsigned wrap
|
||||||
let first = self.divide_mul as u32 as u64;
|
let first = self.divide_mul;
|
||||||
let second = self.divide_add as u64;
|
let second = self.divide_add;
|
||||||
|
|
||||||
(((index * first) + second) >> 32 >> self.divide_shift)
|
(((index * first) + second) >> 32 >> self.divide_shift)
|
||||||
.try_into()
|
.try_into()
|
||||||
|
|
|
@ -205,12 +205,15 @@ pub struct Section {
|
||||||
impl McBufReadable for Section {
|
impl McBufReadable for Section {
|
||||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||||
let block_count = u16::read_into(buf)?;
|
let block_count = u16::read_into(buf)?;
|
||||||
|
|
||||||
// this is commented out because the vanilla server is wrong
|
// this is commented out because the vanilla server is wrong
|
||||||
// assert!(
|
// assert!(
|
||||||
// block_count <= 16 * 16 * 16,
|
// block_count <= 16 * 16 * 16,
|
||||||
// "A section has more blocks than what should be possible. This is a bug!"
|
// "A section has more blocks than what should be possible. This is a bug!"
|
||||||
// );
|
// );
|
||||||
|
|
||||||
let states = PalettedContainer::read_with_type(buf, &PalettedContainerType::BlockStates)?;
|
let states = PalettedContainer::read_with_type(buf, &PalettedContainerType::BlockStates)?;
|
||||||
|
|
||||||
for i in 0..states.storage.size() {
|
for i in 0..states.storage.size() {
|
||||||
if !BlockState::is_valid_state(states.storage.get(i) as u32) {
|
if !BlockState::is_valid_state(states.storage.get(i) as u32) {
|
||||||
return Err(format!(
|
return Err(format!(
|
||||||
|
@ -219,6 +222,7 @@ impl McBufReadable for Section {
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let biomes = PalettedContainer::read_with_type(buf, &PalettedContainerType::Biomes)?;
|
let biomes = PalettedContainer::read_with_type(buf, &PalettedContainerType::Biomes)?;
|
||||||
Ok(Section {
|
Ok(Section {
|
||||||
block_count,
|
block_count,
|
||||||
|
|
|
@ -6,7 +6,7 @@ async fn main() {
|
||||||
println!("Hello, world!");
|
println!("Hello, world!");
|
||||||
|
|
||||||
// let address = "95.111.249.143:10000";
|
// let address = "95.111.249.143:10000";
|
||||||
let address = "localhost:65519";
|
let address = "localhost:51028";
|
||||||
// let response = azalea_client::ping::ping_server(&address.try_into().unwrap())
|
// let response = azalea_client::ping::ping_server(&address.try_into().unwrap())
|
||||||
// .await
|
// .await
|
||||||
// .unwrap();
|
// .unwrap();
|
||||||
|
|
Loading…
Add table
Reference in a new issue