Skip to content

A fast 2D and 3D game engine — TypeScript SDK, C++/WebAssembly core, visual editor. Ship one project to web, desktop, WeChat MiniGames, playable ads, and native Android / iOS.

3.8 KB
Raw Blame
#!/usr/bin/env node
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team
/**
 * @file    check-fixture-scenes.mjs
 * @brief   Every fixture scene must be driven by something.
 * @details A fixture with no criterion behind it is the shape a deleted gate
 *          leaves: coverage looks whole because the scene is still there. The
 *          four ShadowCaster2D scenes sat like that, so 2D shadows had no pixel
 *          criterion at all.
 *
 * Run: node tools/check-fixture-scenes.mjs   (exit 1 on an undriven fixture)
 */
import { readFileSync, readdirSync } from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { listTrackedSources } from './lib/sourceRoots.mjs';

const ROOT = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..');
const SCENES = 'fixtures/scenes';

/**
 * Fixtures kept without a criterion, and why. Empty is the intended state: an
 * entry here is a scene someone drew and nothing looks at.
 */
const UNDRIVEN = {
    // Each of these would prove something about a GLYPH, and a probe on a glyph
    // reads the host's font — it says as much about the machine as the engine.
    // They need a criterion shaped for text, not a point.
    'ui-text-effects.esscene': 'outline and shadow on a glyph',
    'ui-text-zorder.esscene': 'a text drawn over the panel it sits on',
    'ui-textinput.esscene': 'the glyphs and caret inside an SDF input field',
    // Pixel-perfect snapping moves a solid-colour sprite by less than a fifth of
    // a pixel here: the fixture has no texture whose sampling would show it.
    'pixel-perfect.esscene': 'a camera at a fractional position snapped to whole pixels',
    // A scene to measure and not to judge: it is handed to the render host by name when the cost of lit sprites is read
    // (docs/GPU_PERFORMANCE_OPTIONS.md), and a cost is a number for a machine, which no criterion here can hold.
    'sprite-lit-cost.esscene': 'what 32 layers of lit sprites cost a frame on each backend',
};

const drivers = [];
const { files, missing } = listTrackedSources(['tools', 'desktop/scripts', 'bench']);
if (missing.length) {
    console.log(`check-fixture-scenes: no editor checkout — ${missing.join(', ')} not scanned for drivers.`);
}
const SELF = 'tools/check-fixture-scenes.mjs';
for (const f of files) {
    if (!/\.(mjs|js|ts)$/.test(f)) continue;
    // Not this file: it names every undriven scene below, so counting itself
    // would make each of them look driven the moment it entered the index.
    if (f === SELF) continue;
    drivers.push(readFileSync(path.join(ROOT, f), 'utf8'));
}

// The oracle scenes are generated from tools/oracle/ and registered by id, so no source names their file: the generator is the driver.
{
    const { ORACLE } = await import('./oracle/index.mjs');
    for (const o of ORACLE) drivers.push(`${o.id}.esscene`);
}

const scenes = readdirSync(path.join(ROOT, SCENES)).filter((f) => f.endsWith('.esscene'));
const undriven = scenes.filter((s) => !drivers.some((t) => t.includes(s)));
const problems = [];
for (const s of undriven) {
    if (!UNDRIVEN[s]) problems.push(`  ${SCENES}/${s} — nothing drives it`);
}
for (const declared of Object.keys(UNDRIVEN)) {
    if (!undriven.includes(declared)) {
        problems.push(`  UNDRIVEN names ${declared}, which something drives now — drop the entry`);
    }
}

if (problems.length > 0) {
    console.error('Fixture scenes and the criteria that drive them disagree:\n');
    console.error(problems.join('\n'));
    console.error(`\nGive it a criterion (tools/renderScenes.mjs, an editor check) or record it in`
        + ' UNDRIVEN with what it would prove.');
    process.exit(1);
}

console.log(`check-fixture-scenes: ${scenes.length} fixture scene(s), ${scenes.length - undriven.length}`
    + ` driven by a criterion; ${undriven.length} declared undriven.`);