Expand description
The physics threaded world: a fixed-step rapier simulation on its own thread.
Gameplay sends jobs that build bodies; the thread steps the simulation at
a fixed rate. A step drains rapier’s contact events into
PhysicsContacts, the world’s own component, and publishes nothing by
itself: a caller that wants the body transforms or the contacts subscribes
with a collector of its own. Rapier’s math types are glam aliases, so
whatever a collector copies crosses threads with no conversion.
Contacts are events, not state. A step’s contacts sit in
PhysicsContacts until the next step overwrites them, so a caller that
must see every one of them — bullet damage, say — has its collector queue
them as they appear. A snapshot mailbox keeps only the newest, which is
right for transforms and wrong for contacts.
Re-exports§
use std::sync::mpsc::Receiver;🔒use std::sync::mpsc::channel;🔒use std::time::Duration;🔒use glam::Quat;🔒use glam::Vec3;🔒use unlit_ecs::Bundle;🔒use unlit_ecs::DynamicBundle;🔒use unlit_ecs::Entity;🔒use unlit_ecs::World;🔒use crate::handle::WorldHandle;🔒use crate::thread::FixedClock;🔒use crate::thread::fixed_steps;🔒use crate::world::WorldRunner;🔒use unlit_ecs::bundle;🔒use rapier3d::prelude::*;🔒
Structs§
- Body
Desc - A falling, bouncing body: the simulation the example drives.
- Physics
- A physics world, its event plumbing and the contacts its last step found.
- Physics
Config - How the physics world is set up before its first step.
- Physics
Contacts - The contacts rapier reported on the last step.
- Physics
Events 🔒 - The event plumbing a physics world carries between steps.
- Physics
World - A convenience wrapper that bundles all the Rapier physics state into a single struct.
- Rigid
Body Handle - The unique handle of a rigid body added to a
RigidBodySet.
Enums§
- Body
Shape - The collider shape a dynamic body carries.
Constants§
- PHYSICS_
HZ - The simulation’s default step rate, in hertz.
Functions§
- body_
pair 🔒 - The bodies a collider pair belongs to, or nothing when either side is parentless.
- contact_
speed 🔒 - The speed two colliders close at along their contact normal, from the velocities sampled before the step that reported the contact.
- despawn_
body - Remove a body and its colliders from the physics world.
- init_
physics_ world - Create the physics world and its event plumbing in
world, withconfigapplied. - physics_
contacts 🔒 - The contact buffer a physics world carries, if it has one.
- physics_
events 🔒 - The event plumbing a physics world carries, if it has any.
- physics_
world 🔒 - The physics world as a mutable guard, for jobs that build bodies.
- spawn_
body - Spawn a dynamic body with a collision-event collider, returning it.
- spawn_
fixed_ cuboid - Spawn a fixed cuboid: a floor, a wall, whatever gameplay needs.
- spawn_
physics_ world_ with - Spawn the physics world driven by
R: on its own thread (Threaded), or stepped by the host (Stepped). - step_
once - Step the rapier world once, draining its contacts into
PhysicsContacts.