pub struct FluidSnapshot {
pub particle_count: u32,
pub positions: Vec<u8>,
pub velocities: Vec<u8>,
pub checksum: u64,
pub frame: u64,
}Expand description
Serialized fluid state for netcode
Fields§
§particle_count: u32Number of particles
positions: Vec<u8>Serialized positions (N * 3 * 16 bytes)
velocities: Vec<u8>Serialized velocities (N * 3 * 16 bytes)
checksum: u64State checksum for desync detection: FNV-1a 64 over the positions’ byte length (u64 little-endian) and bytes, then the velocities’ length and bytes
frame: u64Frame number
Implementations§
Source§impl FluidSnapshot
impl FluidSnapshot
Sourcepub fn capture(
positions: &[Vec3Fix],
velocities: &[Vec3Fix],
frame: u64,
) -> Self
pub fn capture( positions: &[Vec3Fix], velocities: &[Vec3Fix], frame: u64, ) -> Self
Create snapshot from fluid particle data
positions and velocities must describe the same particle set and
so have the same length: particle_count is one count for both
arrays, and FluidSnapshot::restore deserializes that many of
each. Accepting a mismatch meant taking positions.len() as the
count for both, so a longer velocity array had its surplus silently
dropped on restore — data loss with no error, while
FluidSnapshot::verify still reported a match because it compares
checksums over the bytes rather than reading particle_count.
§Panics
Panics if the two slices have mismatched lengths.
Sourcepub fn restore(&self) -> Option<(Vec<Vec3Fix>, Vec<Vec3Fix>)>
pub fn restore(&self) -> Option<(Vec<Vec3Fix>, Vec<Vec3Fix>)>
Restore fluid state from snapshot
Sourcepub fn verify(&self, positions: &[Vec3Fix], velocities: &[Vec3Fix]) -> bool
pub fn verify(&self, positions: &[Vec3Fix], velocities: &[Vec3Fix]) -> bool
Verify checksum matches current data
Sourcepub fn size_bytes(&self) -> usize
pub fn size_bytes(&self) -> usize
Total serialized size in bytes
Trait Implementations§
Source§impl Clone for FluidSnapshot
impl Clone for FluidSnapshot
Auto Trait Implementations§
impl Freeze for FluidSnapshot
impl RefUnwindSafe for FluidSnapshot
impl Send for FluidSnapshot
impl Sync for FluidSnapshot
impl Unpin for FluidSnapshot
impl UnsafeUnpin for FluidSnapshot
impl UnwindSafe for FluidSnapshot
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more