Skip to content

2D physics test harness types

Read as Markdown

Import these contracts with type from @pibbl/core/physics/2d/testing.

interface PibblPhysicsTestHarness2D<Observation> {
readonly pendingFrames: number;
flush(): boolean;
advanceFrames(count: number, milliseconds?: number): number;
act<Result>(callback: () => Result): Result;
observe(): Observation;
reset(): void;
dispose(): void;
}

flush() runs one requested host frame. advanceFrames() returns host frames run, rather than promising an equal number of fixed physics ticks. act() flushes a state action without moving host time. reset() remounts with monotonic time; dispose() is idempotent and restores the scheduler driver.

Use createPhysicsTestHarness2D from the test-harness function page and consult the 2D physics guide for public world and handle composition.

interface PibblPhysicsTestHarness2DOptions<Observation> {
readonly canvas: HTMLCanvasElement;
readonly root: () => PibblNode;
readonly observe: () => Observation;
}

The caller owns canvas; harness disposal never removes it. root() creates the initial and reset composition. observe() reads public application state. External fixtures stay under the test’s ownership and are not reset.

Caller-owned canvas, root factory, and observation callback for deterministic physics testing.

interface PibblPhysicsTestHarness2DOptions<Observation>

Related API: PibblPhysicsTestHarness2DOptions.

PibblNode

createPhysicsTestHarness2D

View source — packages/core/src/features/physics/2d-testing.ts:21

canvas
readonly canvas: HTMLCanvasElement

The caller owns this canvas; disposing the harness never removes it.

View source — packages/core/src/features/physics/2d-testing.ts:23

root
readonly root: () => PibblNode

Related API: PibblNode.

Creates a new public Pibbl root for the initial mount and each reset.

The Pibbl root tree mounted by the test harness. See PibblNode.

View source — packages/core/src/features/physics/2d-testing.ts:28

observe
readonly observe: () => Observation

Reads application state after a frame or action.

The semantic state to expose through the harness’s observe method.

View source — packages/core/src/features/physics/2d-testing.ts:33

A disposable test mount with explicit host-frame advancement and public-state observations.

interface PibblPhysicsTestHarness2D<Observation>

Related API: PibblPhysicsTestHarness2D.

createPhysicsTestHarness2D

View source — packages/core/src/features/physics/2d-testing.ts:41

pendingFrames
readonly pendingFrames: number

Number of host callbacks currently requested by Pibbl (zero or one).

View source — packages/core/src/features/physics/2d-testing.ts:43

flush
flush: () => boolean

Delivers one already-requested host frame at the current host time.

Whether a pending frame was flushed.

View source — packages/core/src/features/physics/2d-testing.ts:48

advanceFrames
advanceFrames: (count: number, milliseconds?: number) => number

Advances up to count requested host frames by milliseconds each. This advances the host clock, not a guaranteed count of physics fixed ticks.

  • count — Number of frames to advance.

  • milliseconds — Duration of each frame in milliseconds.

The number of frames advanced.

View source — packages/core/src/features/physics/2d-testing.ts:56

act
act: <Result>(callback: () => Result) => Result

Runs an application action and delivers one resulting frame at the current time.

  • callback — Action to run within the harness’s deterministic scheduling context.

The action’s return value.

View source — packages/core/src/features/physics/2d-testing.ts:62

observe
observe: () => Observation

Reads the caller-provided public observation without scheduling work.

The current observation from the configured observer.

View source — packages/core/src/features/physics/2d-testing.ts:67

reset
reset: () => void

Disposes the mounted root and mounts a new one without moving host time backward.

View source — packages/core/src/features/physics/2d-testing.ts:69

dispose
dispose: () => void

Disposes the root and restores the previous realm scheduler driver.

View source — packages/core/src/features/physics/2d-testing.ts:71

Read the Physics and geometry companion for ownership, adaptation, failure modes, and verification. Agent start provides the version-selection workflow.

Documentation built with @pibbl/core 0.0.2, revision 2dccb19. ALPHA — NOT FOR PRODUCTION USE.