Skip to main content

Balls

Struct Balls 

Source
pub struct Balls {
Show 24 fields bodies: Pending<Entity, RigidBodyHandle>, instances: Pending<Entity, RenderEntity>, shows: Pending<Entity, bool>, retired: Pending<(), Vec<BallInstance>>, settled_bodies: Vec<(Entity, Settled<RigidBodyHandle>)>, settled_instances: Vec<(Entity, Settled<RenderEntity>)>, settled_shows: Vec<(Entity, Settled<bool>)>, settled_retired: Vec<((), Settled<Vec<BallInstance>>)>, expired: Vec<Entity>, sweep_asked: bool, drops: u32, clear: bool, last_snapshot: Option<Arc<GamePhysics>>, requests: u32, spawn_elapsed: f32, sweep_elapsed: f32, status_elapsed: f32, pub automatic_drops: bool, poses_sent: usize, showing: Vec<ShowCandidate>, sweeping: Vec<BallInstance>, despawns: Vec<RigidBodyHandle>, orphans: Vec<RenderEntity>, rng: u64,
}
Expand description

The balls, living on their own entity in the gameplay world.

A body’s pose is authoritative in the physics world and drawn by the render world, so this object is the one place the two meet: it reads the handles the snapshot names off the ball entities, and publishes the resulting poses as a job.

It reaches the other worlds through the Scene its tick is handed, so it keeps no channel of its own: what it does keep is the answers waiting to be folded into the balls they name, and the buffers those answers land in, so a tick that folds nothing allocates nothing but the poses it sends.

Fields§

§bodies: Pending<Entity, RigidBodyHandle>

The bodies the physics world owes: one request per ball, asked under the ball it is for.

§instances: Pending<Entity, RenderEntity>

The instances the render world owes: one request per ball, asked under the ball it is for.

§shows: Pending<Entity, bool>

The shows the render world owes: one request per ball, asked under the ball whose instance is being shown. What it answers is whether the instance really wears its assets.

§retired: Pending<(), Vec<BallInstance>>

What a sweep swept away: one request per sweep, asked under no key at all, because what it names is the whole scene rather than one ball.

§settled_bodies: Vec<(Entity, Settled<RigidBodyHandle>)>

Where the answers land, reused across ticks.

§settled_instances: Vec<(Entity, Settled<RenderEntity>)>§settled_shows: Vec<(Entity, Settled<bool>)>§settled_retired: Vec<((), Settled<Vec<BallInstance>>)>§expired: Vec<Entity>

The balls a request was given up on this tick, and has to reclaim.

§sweep_asked: bool

Whether a sweep is still owed an answer: a second sweep asked before the first answered would have its answer dropped, and with it the instances the first one retired.

§drops: u32

How many drops have been made, picking each ball’s look. The counter only orders the looks: a ball is found by its entity, not by it.

§clear: bool

A clear requested but not yet consumed by the tick.

§last_snapshot: Option<Arc<GamePhysics>>

The snapshot the previous tick published, to skip repeated work.

§requests: u32

Ball drops requested but not yet consumed by the tick.

§spawn_elapsed: f32

Seconds since the previous automatic drop.

§sweep_elapsed: f32

Seconds since the previous view sweep.

§status_elapsed: f32

Seconds since the previous status line.

§automatic_drops: bool

Whether the spawn cadence drops balls without a panel request.

§poses_sent: usize

Pose entries the last job carried, for the status line.

§showing: Vec<ShowCandidate>

The balls the tick has decided to show, reused across ticks.

§sweeping: Vec<BallInstance>

The instances a sweep tests against the camera’s view, reused across sweeps.

§despawns: Vec<RigidBodyHandle>

The bodies a tick has to send away, kept until a send goes through so a full queue only delays the cleanup.

§orphans: Vec<RenderEntity>

The instances that have nobody left to stand for, kept the same way.

§rng: u64

The xorshift state for spawn placement.

Implementations§

Source§

impl Balls

Source

pub fn new(scene: &Scene) -> Self

The balls, driving the worlds their tick is handed.

Source

pub fn queue_drop(&mut self)

Ask for one more ball on the next tick.

Source

pub fn queue_clear(&mut self)

Ask the next tick to put every ball away.

Source

fn random_signed(&mut self) -> f32

The next symmetric random float in -1..1.

Source

fn drop_ball(&mut self, world: &World, state: Entity, scene: &Scene)

Spawn one ball and ask the render and physics worlds for its halves.

The look picks the collider shape as well as the mesh and material, so both worlds agree on what the drop is. The ball entity is queued first: it is what both answers name, so neither half can arrive for a ball that does not exist.

A world that refuses the request outright — its queue is full, or it has stopped — costs this drop and no more: the ball is despawned before any answer can name it.

Source

fn clear_balls(&mut self, world: &World, scene: &Scene)

Put every ball away, bodies and instances included.

The instances are despawned rather than kept hidden: one the camera cannot see has no reason to stay. The music is left alone — the panel drives it, not the balls. A ball whose halves are still in flight is gone by the time they arrive, so they are cleaned up as orphans.

Source

fn fold_answers( &mut self, world: &World, state: Entity, scene: &Scene, delta_seconds: f32, )

Fold the answers the other worlds sent since the last tick into the balls they name, show the ones that now have both halves, and put away the ones that waited too long.

Every wait is bounded by the same timeout, so this is the one place a request is given up on: an answer that never came names its ball, and the ball is reclaimed with whatever halves it did receive.

Source

fn despawn_bodies(&mut self, scene: &Scene)

Despawn the bodies the tick has collected, in one job.

A despawn is idempotent, so the list is kept until a send goes through: a full queue delays the cleanup by a tick instead of losing it.

Source

fn despawn_instances(&mut self, scene: &Scene)

Despawn the instances the tick has collected, in one job.

Source

fn sweep_outside_view(&mut self, world: &World, scene: &Scene)

Ask the render world to despawn the shown instances the camera can no longer see. Each answer names the ball it belonged to, so the body and the ball entity go with the instance.

The sweep repeats every SWEEP_PERIOD seconds, so a ball the camera loses is put away within one period, and one whose sweep met a full queue within two.

Source

fn publish(&mut self, world: &World, scene: &Scene)

Publish the snapshot’s poses onto the balls they name.

Auto Trait Implementations§

§

impl !Unpin for Balls

§

impl !UnsafeUnpin for Balls

§

impl Forget for Balls

§

impl Freeze for Balls

§

impl RefUnwindSafe for Balls

§

impl Send for Balls

§

impl Sync for Balls

§

impl UnwindSafe for Balls

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
§

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

§

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

Source§

impl<T> Component for T
where T: 'static,

§

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

§

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.
§

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.
§

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.
§

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.
§

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

§

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

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

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

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

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

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

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

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

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

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

§

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

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

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

§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

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

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

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

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

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
§

impl<F, T> IntoSample<T> for F
where T: FromSample<F>,

§

fn into_sample(self) -> T

§

impl<T> MaybeSync for T
where T: Sync + ?Sized,

§

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

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

§

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

§

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

§

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

§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
§

impl<T> Upcast<T> for T

§

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

§

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

§

impl<T> WasmNotSendSync for T
where T: WasmNotSend + WasmNotSync,

§

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

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

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