Skip to main content

Module physics

Module physics 

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

BodyDesc
A falling, bouncing body: the simulation the example drives.
Physics
A physics world, its event plumbing and the contacts its last step found.
PhysicsConfig
How the physics world is set up before its first step.
PhysicsContacts
The contacts rapier reported on the last step.
PhysicsEvents 🔒
The event plumbing a physics world carries between steps.
PhysicsWorld
A convenience wrapper that bundles all the Rapier physics state into a single struct.
RigidBodyHandle
The unique handle of a rigid body added to a RigidBodySet.

Enums§

BodyShape
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, with config applied.
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.