mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
add more stuff
This commit is contained in:
parent
122693a654
commit
345cecf7af
7 changed files with 67 additions and 19 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -4,8 +4,6 @@ flamegraph.svg
|
||||||
perf.data
|
perf.data
|
||||||
perf.data.old
|
perf.data.old
|
||||||
|
|
||||||
# TODO: remove this after chunk-decoding is merged
|
|
||||||
/login.txt
|
|
||||||
|
|
||||||
code-generator/Burger
|
code-generator/Burger
|
||||||
code-generator/client.jar
|
code-generator/client.jar
|
||||||
|
|
|
@ -177,7 +177,6 @@ impl Client {
|
||||||
match packet {
|
match packet {
|
||||||
GamePacket::ClientboundLoginPacket(p) => {
|
GamePacket::ClientboundLoginPacket(p) => {
|
||||||
println!("Got login packet {:?}", p);
|
println!("Got login packet {:?}", p);
|
||||||
std::fs::write("login.txt", format!("{:#?}", p)).expect("Unable to write file");
|
|
||||||
|
|
||||||
let mut state = state.lock().await;
|
let mut state = state.lock().await;
|
||||||
state.player.entity.id = p.player_id;
|
state.player.entity.id = p.player_id;
|
||||||
|
|
|
@ -23,6 +23,15 @@ impl ChunkPos {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<BlockPos> for ChunkPos {
|
||||||
|
fn from(pos: BlockPos) -> Self {
|
||||||
|
ChunkPos {
|
||||||
|
x: pos.x / 16,
|
||||||
|
z: pos.z / 16,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, Default)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
pub struct ChunkSectionPos {
|
pub struct ChunkSectionPos {
|
||||||
pub x: i32,
|
pub x: i32,
|
||||||
|
@ -35,3 +44,19 @@ impl ChunkSectionPos {
|
||||||
ChunkSectionPos { x, y, z }
|
ChunkSectionPos { x, y, z }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<BlockPos> for ChunkSectionPos {
|
||||||
|
fn from(pos: BlockPos) -> Self {
|
||||||
|
ChunkSectionPos {
|
||||||
|
x: pos.x / 16,
|
||||||
|
y: pos.y / 16,
|
||||||
|
z: pos.z / 16,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ChunkSectionPos> for ChunkPos {
|
||||||
|
fn from(pos: ChunkSectionPos) -> Self {
|
||||||
|
ChunkPos { x: pos.x, z: pos.z }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -70,9 +70,9 @@ const MAGIC: [(i32, i32, i32); 64] = [
|
||||||
];
|
];
|
||||||
|
|
||||||
/// A compact list of integers with the given number of bits per entry.
|
/// A compact list of integers with the given number of bits per entry.
|
||||||
#[derive(Clone)]
|
#[derive(Clone, Debug, Default)]
|
||||||
pub struct BitStorage {
|
pub struct BitStorage {
|
||||||
data: Vec<u64>,
|
pub data: Vec<u64>,
|
||||||
bits: usize,
|
bits: usize,
|
||||||
mask: u64,
|
mask: u64,
|
||||||
size: usize,
|
size: usize,
|
||||||
|
@ -103,9 +103,17 @@ impl BitStorage {
|
||||||
/// Create a new BitStorage with the given number of bits per entry.
|
/// Create a new BitStorage with the given number of bits per entry.
|
||||||
/// `size` is the number of entries in the BitStorage.
|
/// `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<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 values_per_long = 64 / bits;
|
||||||
let magic_index = values_per_long - 1;
|
let magic_index = values_per_long - 1;
|
||||||
let (divide_mul, divide_add, divide_shift) = MAGIC[magic_index as usize];
|
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 calculated_length = (size + values_per_long - 1) / values_per_long;
|
||||||
|
|
||||||
let mask = (1 << bits) - 1;
|
let mask = (1 << bits) - 1;
|
||||||
|
|
|
@ -67,6 +67,15 @@ impl IndexMut<&ChunkPos> for World {
|
||||||
&mut self.storage[pos]
|
&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 {
|
pub struct ChunkStorage {
|
||||||
view_center: ChunkPos,
|
view_center: ChunkPos,
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
use azalea_protocol::mc_buf::{McBufReadable, McBufVarReadable, McBufWritable, Readable, Writable};
|
use azalea_protocol::mc_buf::{McBufReadable, McBufVarReadable, McBufWritable, Readable, Writable};
|
||||||
use std::io::{Read, Write};
|
use std::io::{Read, Write};
|
||||||
|
|
||||||
|
use crate::BitStorage;
|
||||||
|
|
||||||
#[derive(Clone, Debug, Copy)]
|
#[derive(Clone, Debug, Copy)]
|
||||||
pub enum PalettedContainerType {
|
pub enum PalettedContainerType {
|
||||||
Biomes,
|
Biomes,
|
||||||
|
@ -12,7 +14,7 @@ pub struct PalettedContainer {
|
||||||
pub bits_per_entry: u8,
|
pub bits_per_entry: u8,
|
||||||
pub palette: Palette,
|
pub palette: Palette,
|
||||||
/// Compacted list of indices pointing to entry IDs in the Palette.
|
/// Compacted list of indices pointing to entry IDs in the Palette.
|
||||||
pub data: Vec<u64>,
|
pub storage: BitStorage,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PalettedContainer {
|
impl PalettedContainer {
|
||||||
|
@ -29,17 +31,23 @@ impl PalettedContainer {
|
||||||
Palette::biomes_read_with_bits_per_entry(buf, bits_per_entry)?
|
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)?;
|
let data = Vec::<u64>::read_into(buf)?;
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
bits_per_entry != 0 || data.is_empty(),
|
bits_per_entry != 0 || data.is_empty(),
|
||||||
"Bits per entry is 0 but data is not 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 {
|
Ok(PalettedContainer {
|
||||||
bits_per_entry,
|
bits_per_entry,
|
||||||
palette,
|
palette,
|
||||||
data,
|
storage,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -47,7 +55,7 @@ impl McBufWritable for PalettedContainer {
|
||||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||||
buf.write_byte(self.bits_per_entry)?;
|
buf.write_byte(self.bits_per_entry)?;
|
||||||
self.palette.write_into(buf)?;
|
self.palette.write_into(buf)?;
|
||||||
self.data.write_into(buf)?;
|
self.storage.data.write_into(buf)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
use azalea_client::{Account, Event};
|
use azalea_client::{Account, Event};
|
||||||
use azalea_core::ChunkPos;
|
use azalea_core::{BlockPos, ChunkPos};
|
||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() {
|
async fn main() {
|
||||||
|
@ -19,18 +19,19 @@ async fn main() {
|
||||||
while let Some(e) = client.next().await {
|
while let Some(e) = client.next().await {
|
||||||
match e {
|
match e {
|
||||||
// TODO: have a "loaded" or "ready" event that fires when all chunks are loaded
|
// TODO: have a "loaded" or "ready" event that fires when all chunks are loaded
|
||||||
Event::Login => {
|
Event::Login => {}
|
||||||
// let state = client.state.lock().await;
|
Event::Chat(p) => {
|
||||||
// let world = state.world.as_ref().unwrap();
|
println!("{}", p.message.to_ansi(None));
|
||||||
// let c = world[&ChunkPos::new(-1, -4)]
|
if p.message.to_ansi(None) == "<py5> ok" {
|
||||||
|
let state = client.state.lock().await;
|
||||||
|
let world = state.world.as_ref().unwrap();
|
||||||
|
// let c = world[&BlockPos::new(5, 78, -2)]
|
||||||
// .as_ref()
|
// .as_ref()
|
||||||
// .unwrap()
|
// .unwrap()
|
||||||
// .lock()
|
// .lock()
|
||||||
// .unwrap();
|
// .unwrap();
|
||||||
// println!("{:?}", c);
|
// println!("{:?}", c);
|
||||||
}
|
}
|
||||||
Event::Chat(p) => {
|
|
||||||
println!("{}", p.message.to_ansi(None));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue