Skip to main content

DebrisSystem

Struct DebrisSystem 

Source
pub struct DebrisSystem {
    pub gravity: f64,
    pub terminal_speed: f64,
    pub max_yaw_rate: f32,
    pub solidity: Solidity,
    pub fracture_impulse: f64,
    /* private fields */
}
Expand description

Host-owned falling-island simulation + facade binding. Construct once, Self::spawn_island per detected island, Self::tick per frame, Self::drain_impacts to shatter.

Fields§

§gravity: f64

Gravity in world units/s², +z is down. Matches the particle default so debris and dust fall together.

§terminal_speed: f64

Terminal-speed clamp on the fall, world units/s.

§max_yaw_rate: f32

Cosmetic spin cap, rad/s: each island gets a deterministic per-island rate in [-max, max] (hashed from its position — no RNG state, replays are bit-identical).

§solidity: Solidity

What counts as solid ground (bedrock-placeholder policy) — the same knob box_overlaps_solid takes.

§fracture_impulse: f64

DT.5 — outward drift a fracture fragment inherits, world units/s (directed from the parent island’s centre to the fragment’s; zero for unsplit islands).

Implementations§

Source§

impl DebrisSystem

Source

pub fn new() -> Self

A system with the stock tuning: particle-matched gravity, a generous terminal clamp, a barely-perceptible spin.

Source

pub fn set_fracture_patterns( &mut self, colour_map: &[(Rgb, u8)], patterns: &[(u8, FracturePattern)], )

DT.5 — install the fracture side tables: colour_map is the host’s colour→material terrain map (also switches island models to material-mapped registration, so translucent / emissive voxels keep their look in flight), patterns maps material ids to FracturePatterns. An island splits per material group before falling: its rock breaks per the rock pattern, its crystal per the crystal pattern, each fragment its own body with a small outward Self::fracture_impulse. Empty tables (the default) keep every island Whole.

Source

pub fn spawn_island( &mut self, scene: &mut Scene, grid: GridId, island: Island, bake: BakeMode, ) -> bool

Extract island from grid (via Island::extract — carve + bake_bbox; mips are the caller’s obligation, same as any edit), split it per the fracture tables (DT.5 — Self::set_fracture_patterns; no tables ⇒ one piece), and register each fragment as a falling body at the exact world pose of the voxels it replaced, with an outward drift for fragments of a split. Sprite models/instances appear on the next Self::sync. Returns false (and does nothing) for a missing grid or an empty island.

Spawn inside geometry (an L-shaped island whose bbox wraps a surviving support, a detach flush under a shelf): a fragment’s AABB already overlapping foreign solid cannot fall — it is queued as an immediate DebrisImpact at zero speed (the shatter replaces it in place) and never becomes a body. An explicit policy, not an accident of the contact search: the accepted degradation of AABB-only collision (decision 4).

Source

pub fn update(&mut self, scene: &Scene, dt: f64)

Advance every body by dt seconds: semi-implicit Euler with the terminal clamp, cosmetic yaw, then the vertical collision march against scene. The frame’s displacement is walked in substeps of half the collision window (half.z + vws/2 — the thinnest thing a voxel scene can contain is one voxel), so a fast body cannot tunnel through a one-voxel shelf on a slow frame (vel·dt is unbounded: hosts pass real dt, hitches included). A blocked substep is binary-searched to flush contact; the body retires as a DebrisImpact. Pure simulation — no facade calls (see Self::sync).

A body whose horizontal drift carries it into a wall finds every vertical probe blocked: the contact search degenerates to its current position and it shatters mid-air against the wall — the same accepted mechanism as the spawn-inside-geometry policy on Self::spawn_island.

Source

pub fn sync(&mut self, renderer: &mut SceneRenderer)

Mirror the simulation into the facade: retire handles of landed bodies, spawn a model + pre-posed instance for each newborn (no axis-aligned first-frame flash), and batch-move everything alive via one set_sprite_instance_transforms. The facade tombstones removed models — a host shattering many islands should call compact_sprite_models periodically.

Source

pub fn tick(&mut self, renderer: &mut SceneRenderer, scene: &Scene, dt: f64)

One-shot per-frame step: Self::update then Self::sync.

Source

pub fn drain_impacts(&mut self) -> Drain<'_, DebrisImpact>

Drain the impacts accumulated by Self::update — DT.3’s shatter consumes these (each carries its island’s voxels).

Source

pub fn debris_count(&self) -> usize

Number of bodies currently falling.

Trait Implementations§

Source§

impl Default for DebrisSystem

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(value: T, _simd: S) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more