@skidpad/worker
v0.8.0
Published
Worker mode for Skidpad: run a world in a Web Worker (or a Node worker thread) and drive it from the main thread.
Maintainers
Readme
@skidpad/worker
Runs a @skidpad/core world
in a Web Worker (or a Node worker thread) and drives it from the main
thread, with synchronous reads of the last answer.
// sim.worker.ts
import "@skidpad/worker/entry";
// main.ts
import { WorkerWorld } from "@skidpad/worker";
const worker = new Worker(new URL("./sim.worker.ts", import.meta.url), { type: "module" });
const world = await WorkerWorld.create(worker, { capacity: 50 });
const car = await world.addVehicle(def);
// each frame
world.setInput(car, { throttle: 1 });
if (world.stepsInFlight === 0) void world.step(1 / 60);
world.read(car, "PosX"); // last answerA LodController drives it through world.lodTarget. Only built-in-host
vehicles run in a worker; Rapier- and Jolt-hosted cars stay on the thread
that owns their scene.
Guide: worker mode.
License: MIT OR Apache-2.0.
