PhysicsBoxState

@Stable
class PhysicsBoxState

Mutable controller for a physics world hosted by dev.zinchenko.physicsbox.layout.PhysicsBox.

This state is intended to be the primary API surface for:

The state keeps a queue of PhysicsCommand objects. The runtime drains it and applies changes to the underlying physics engine. UI code should treat command helpers as fire-and-forget.

Notes:

  • This class is Stable to avoid unnecessary recompositions when only internal bookkeeping changes.

  • Values such as gravity and stepConfig are exposed as Compose state (mutable) and will trigger recomposition when changed. Per-body transforms are intentionally not mirrored here.

Properties

Link copied to clipboard

Current world gravity vector.

Link copied to clipboard

Whether the simulation is paused.

Link copied to clipboard

Monotonic marker that changes when the command queue receives new commands.

Link copied to clipboard

Convenience view over solver iteration counts derived from stepConfig.

Link copied to clipboard

Current step configuration (timestep/iterations/etc.).

Functions

Link copied to clipboard

Generic command extension point for advanced integrations.

Link copied to clipboard
fun enqueueImpulse(key: Any, impulseX: Float, impulseY: Float, wake: Boolean = true)

Queues a linear impulse for the body associated with key.

Link copied to clipboard
fun enqueueVelocity(key: Any, velocityX: Float, velocityY: Float)

Queues a linear velocity update for the body associated with key.

Link copied to clipboard
fun pause()

Pauses simulation stepping.

Link copied to clipboard
fun reset()

Resets world-level settings and requests runtime world reset.

Link copied to clipboard
fun resume()

Resumes simulation stepping.

Link copied to clipboard
fun setOnStepListener(listener: (StepEvent) -> Unit?)

Registers a world step callback.

Link copied to clipboard
fun setSolverIterations(velocityIterations: Int, positionIterations: Int)

Convenience helper for updating solver iteration counts.

Link copied to clipboard

Sets world gravity and enqueues PhysicsCommand.SetWorldGravity.

Link copied to clipboard

Creates an immutable snapshot of the current world-level configuration.

Link copied to clipboard

Updates gravity and enqueues the change for the runtime.

Link copied to clipboard
fun updateStepConfig(stepConfig: StepConfig)

Replaces current stepConfig.