mirror of
https://github.com/IntQuant/noita_entangled_worlds.git
synced 2025-10-19 07:03:16 +00:00
try to implement world sync, prob made some mistakes but no crash is good enough for me
This commit is contained in:
parent
ec3857c6b9
commit
f78070e1b5
13 changed files with 735 additions and 440 deletions
16
shared/Cargo.lock
generated
16
shared/Cargo.lock
generated
|
@ -10,9 +10,9 @@ checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50"
|
|||
|
||||
[[package]]
|
||||
name = "bitcode"
|
||||
version = "0.6.6"
|
||||
version = "0.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf300f4aa6e66f3bdff11f1236a88c622fe47ea814524792240b4d554d9858ee"
|
||||
checksum = "648bd963d2e5d465377acecfb4b827f9f553b6bc97a8f61715779e9ed9e52b74"
|
||||
dependencies = [
|
||||
"arrayvec",
|
||||
"bitcode_derive",
|
||||
|
@ -23,9 +23,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "bitcode_derive"
|
||||
version = "0.6.5"
|
||||
version = "0.6.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "42b6b4cb608b8282dc3b53d0f4c9ab404655d562674c682db7e6c0458cc83c23"
|
||||
checksum = "ffebfc2d28a12b262c303cb3860ee77b91bd83b1f20f0bd2a9693008e2f55a9e"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
@ -80,9 +80,9 @@ checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.95"
|
||||
version = "1.0.101"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778"
|
||||
checksum = "89ae43fd86e4158d6db51ad8e2b80f313af9cc74f5c0e03ccb87de09998732de"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
@ -149,9 +149,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.104"
|
||||
version = "2.0.106"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "17b6f705963418cdb9927482fa304bc562ece2fdd4f616084c50b7023b435a40"
|
||||
checksum = "ede7c438028d4436d71104916910f5bb611972c5cfd7f89b8300a8186e6fada6"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
|
@ -16,7 +16,7 @@ pub struct ChunkCoord(pub i32, pub i32);
|
|||
#[derive(Debug, Encode, Decode, Clone)]
|
||||
pub struct NoitaWorldUpdate {
|
||||
pub coord: ChunkCoord,
|
||||
pub runs: Vec<PixelRun<RawPixel>>,
|
||||
pub pixels: [Option<CompactPixel>; CHUNK_SIZE * CHUNK_SIZE],
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Encode, Decode)]
|
||||
|
@ -50,13 +50,9 @@ impl RawPixel {
|
|||
CompactPixel(NonZeroU16::new(raw).unwrap())
|
||||
}
|
||||
pub fn from_compact(compact: CompactPixel) -> Self {
|
||||
let raw = u16::from(compact.0);
|
||||
let material = (raw >> 1) - 1;
|
||||
let flags = if raw & 1 == 1 {
|
||||
PixelFlags::Abnormal
|
||||
} else {
|
||||
PixelFlags::Normal
|
||||
};
|
||||
let raw = compact.raw();
|
||||
let material = compact.material();
|
||||
let flags = compact.flags();
|
||||
if raw == CompactPixel::UNKNOWN_RAW {
|
||||
RawPixel {
|
||||
flags: PixelFlags::Unknown,
|
||||
|
@ -66,6 +62,16 @@ impl RawPixel {
|
|||
RawPixel { flags, material }
|
||||
}
|
||||
}
|
||||
pub fn from_opt_compact(compact: Option<CompactPixel>) -> Self {
|
||||
if let Some(pixel) = compact {
|
||||
Self::from_compact(pixel)
|
||||
} else {
|
||||
RawPixel {
|
||||
material: 0,
|
||||
flags: PixelFlags::Normal,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// An entire pixel packed into 12 bits.
|
||||
|
@ -78,9 +84,28 @@ impl CompactPixel {
|
|||
pub fn from_raw(val: u16) -> Self {
|
||||
CompactPixel(NonZeroU16::new(val).unwrap())
|
||||
}
|
||||
pub fn from_material(val: u16) -> Option<Self> {
|
||||
if val == 0 {
|
||||
None
|
||||
} else {
|
||||
let val = (val + 1) & 2047;
|
||||
let val = val << 1;
|
||||
Some(CompactPixel(NonZeroU16::new(val).unwrap()))
|
||||
}
|
||||
}
|
||||
pub fn raw(self) -> u16 {
|
||||
u16::from(self.0)
|
||||
}
|
||||
pub fn material(self) -> u16 {
|
||||
(self.raw() >> 1) - 1
|
||||
}
|
||||
pub fn flags(self) -> PixelFlags {
|
||||
if self.raw() & 1 == 1 {
|
||||
PixelFlags::Abnormal
|
||||
} else {
|
||||
PixelFlags::Normal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for CompactPixel {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue