Files
syncer/packages/engine/src/physics-backend.ts
Syncer Deploy 38ac419204
All checks were successful
build / image (push) Successful in 1m39s
add Box3D-powered Bad Movers game
2026-08-31 12:32:39 -04:00

33 lines
1.1 KiB
TypeScript

/** Runtime information a game may expose without coupling itself to an SDK. */
export interface PhysicsBackendMetadata {
readonly name: string;
readonly runtime: string;
readonly version?: string;
}
/**
* A pluggable deterministic physics runtime for a serializable game state.
*
* Native/WASM handles stay inside the backend. The engine only checkpoints the
* plain State value, so a backend must be able to initialize from that value
* and reconcile an existing runtime to a fresh snapshot.
*/
export interface PhysicsBackend<State, StepResult = void> {
readonly metadata: PhysicsBackendMetadata;
initialize(state: State): void;
step(state: State, deltaSeconds: number): StepResult;
reconcile(predicted: State, snapshot: State): void;
reset(state: State): void;
dispose?(state: State): void;
}
/**
* Developer-facing HOF used to define a typed physics plug-in once and retain
* any game-specific methods added by that plug-in.
*/
export function definePhysicsBackend<State, StepResult = void>() {
return <Backend extends PhysicsBackend<State, StepResult>>(
backend: Backend,
): Readonly<Backend> => Object.freeze(backend);
}