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,
|
||||
size: usize,
|
||||
values_per_long: u8,
|
||||
divide_mul: i32,
|
||||
divide_add: i32,
|
||||
divide_mul: u64,
|
||||
divide_add: u64,
|
||||
divide_shift: i32,
|
||||
}
|
||||
|
||||
|
@ -138,16 +138,16 @@ impl BitStorage {
|
|||
mask,
|
||||
size,
|
||||
values_per_long: values_per_long as u8,
|
||||
divide_mul,
|
||||
divide_add,
|
||||
divide_mul: divide_mul as u32 as u64,
|
||||
divide_add: divide_add as u32 as u64,
|
||||
divide_shift,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn cell_index(&self, index: u64) -> usize {
|
||||
// as unsigned wrap
|
||||
let first = self.divide_mul as u32 as u64;
|
||||
let second = self.divide_add as u64;
|
||||
let first = self.divide_mul;
|
||||
let second = self.divide_add;
|
||||
|
||||
(((index * first) + second) >> 32 >> self.divide_shift)
|
||||
.try_into()
|
||||
|
|
|
@ -205,12 +205,15 @@ pub struct Section {
|
|||
impl McBufReadable for Section {
|
||||
fn read_into(buf: &mut impl Read) -> Result<Self, String> {
|
||||
let block_count = u16::read_into(buf)?;
|
||||
|
||||
// this is commented out because the vanilla server is wrong
|
||||
// assert!(
|
||||
// block_count <= 16 * 16 * 16,
|
||||
// "A section has more blocks than what should be possible. This is a bug!"
|
||||
// );
|
||||
|
||||
let states = PalettedContainer::read_with_type(buf, &PalettedContainerType::BlockStates)?;
|
||||
|
||||
for i in 0..states.storage.size() {
|
||||
if !BlockState::is_valid_state(states.storage.get(i) as u32) {
|
||||
return Err(format!(
|
||||
|
@ -219,6 +222,7 @@ impl McBufReadable for Section {
|
|||
));
|
||||
}
|
||||
}
|
||||
|
||||
let biomes = PalettedContainer::read_with_type(buf, &PalettedContainerType::Biomes)?;
|
||||
Ok(Section {
|
||||
block_count,
|
||||
|
|
|
@ -6,7 +6,7 @@ async fn main() {
|
|||
println!("Hello, world!");
|
||||
|
||||
// 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())
|
||||
// .await
|
||||
// .unwrap();
|
||||
|
|
Loading…
Add table
Reference in a new issue