Examples

Current examples for defineGame and V0.2/V0.3 performance-mode authoring.

Minimal Ball/Pong Slice

This is the smallest shape to copy for schema-backed performance mode: schema tables, class-bound world facade, deterministic step(ctx), and mirror-only rendering.

import { schemaScalar, schemaRecord, schemaTable } from '../experimental/performance-mode/state-backend.js';

class Ball { static table = 'balls'; }
class Paddle { static table = 'paddles'; }

export const SCHEMA = {
    balls: schemaTable(schemaRecord({
        x: schemaScalar('number'),
        y: schemaScalar('number'),
        vx: schemaScalar('number'),
        vy: schemaScalar('number')
    }), { id: 'string', order: 'id' }),
    paddles: schemaTable(schemaRecord({
        y: schemaScalar('number'),
        score: schemaScalar('number')
    }), { id: 'string', order: 'id' })
};

export function createInitialState() {
    return {
        balls: { __emRows: { 'ball:main': { x: 50, y: 50, vx: 1, vy: 1 } } },
        paddles: { __emRows: {} }
    };
}

export function step(ctx) {
    const world = ctx.world();
    world.discoverParticipants(() => true, 2);

    for (const playerId of world.participants()) {
        const input = world.input(playerId) || {};
        let paddle = world.get(Paddle, `paddle:${playerId}`);
        if (!paddle) paddle = world.spawn(Paddle, `paddle:${playerId}`, { y: 50, score: 0 });
        paddle.s.y = Math.max(0, Math.min(100, paddle.s.y + (input.dy || 0) * world.dt));
    }

    const ball = world.get(Ball, 'ball:main');
    if (!ball) return;
    ball.s.x += ball.s.vx * world.dt;
    ball.s.y += ball.s.vy * world.dt;
}

Pac-Man V0.2 Local Performance Demo

Open the local V0.2 demo

Source: examples/performance-mode-pacman-v02/main.js. This demo runs the schema backend, bus manager, render source selector, and mirror renderer in one browser page. It is useful for understanding the runtime infrastructure without real P2P timing.

Pac-Man V0.2 Trystero Demo

Open the V0.2 Trystero demo

Source: examples/performance-mode-pacman-trystero/main.js. This is the real SimulationEngine plus BusRuntimeAdapter path over TrysteroTransport. It proves inputs travel through the engine transport path, not a custom browser input map.

Pac-Man V0.2/V0.3 World-Facade Trystero Demo

Open the world-facade Trystero demo

Source: examples/performance-mode-pacman-world-trystero/main.js. Game logic lives in experimental/performance-mode/games/pacman-world.js and uses ctx.world(). This is the release-facing Pac-Man direction.

Deployed smoke URL: https://libs.letsinspire.com/em-pacman-v02-world-trystero/.

Advanced Diagnostics: V0.3 Worker Pac-Man

Live worker proof URL: https://libs.letsinspire.com/em-pacman-v03-worker-trystero/.

This V0.3 worker Pac-Man page is for advanced diagnostics of the worker/time-sliced runtime path. It is not the main getting-started flow and should not replace the world-facade demo as tutorial material.

Authoring vs Runtime

The authoring API is defineGame for host-agnostic modules and ctx.world() for schema-backed performance-mode steps. V0.3 buses, workers, schedulers, BusRuntimeAdapter, BusManager, and WorkerRenderHost are runtime infrastructure. They move inputs, snapshots, patches, and render mirrors; they are not a second way to write gameplay.

Older Compatibility Examples

Simple Pac-Man and Graph Pac-Man remain useful compatibility references for the historical EasyMultiplayer callback facade, but new developers should not start there.