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.
TypeScript 2d-game-engine3d3d-game-engineandroidcppecsgame-editorgame-enginegamedeviostypescriptwebassemblywebglwebgpuwechat-minigame
fix(native): a packaged game's colour space, output transform, MSAA, quality, layers and camera fit reach a native host, so a linear project is no longer far too dark
yhh2ef54a58c817
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex e635d247a..35171275d 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -23,6 +23,7 @@ published separately; it ships inside the editor.### Fixed+- **A linear project on a native build is no longer far too dark.** A native host read only half of the packaged config. The colour space, output transform, MSAA, quality, y-sort and depth layers and camera fit never reached it, with no error. A linear game ran as gamma and showed its linear values with no encode: a grey of 0.2 read 51 instead of 124, on Android, Windows and every other native build. Web and native now apply these through one function, and the colour space is read before the first shader compiles. A native build matches the web to about one level in the test room. Linear costs a phone 2.7 ms a frame at 2670x1200 with nothing else on. A project that declares a quality level now gets it on a device, including what that level costs: `high` measured 50 ms a frame on a Snapdragon 8 Elite, unexplained so far, against 7 ms for `medium`.- **Voxel GI no longer changes with the size of the picture.** It took the same one pixel in four for its cache every frame, so a face a few rows tall (the top of a block seen nearly edge on) landed in it at one row or two according to the window's size, and the light around it moved: a wall read 18% apart across sizes, up to 11% for a window one pixel taller. The pixel now changes each frame. Across eight of nine sizes the same wall is within 7%, one size with an odd width and height still reads higher, and the light against Cycles and the frame-to-frame stability are unchanged.- **Voxel GI costs a third of what it did.** Every cell a ray crossed took two integer divisions, a hash, and a read in the 32 MB grid, which is a cache miss, for a cell that is nearly always empty. Wrapping is now a mask, the hash check is gone (the cache re-tags every slot each frame, so it could not fail), and the tags hold a mark saying whether a slot has anything, read before the grid is. On an RTX 3060 at 720p the default settings went from 17.3 to about 5.4 ms a frame, and the picture is the same: held against the old kernels, the difference is no larger than between two runs of one build.- **Writing an entity list on the web replaces it.** A `SpringBone.colliders` or `MeshSkin.joints` written to a component that already had one was added to what was there, so a `[a, b]` written twice read `[a, b, a, b]`, a `Mut` row grew it on every write-back (72 entries in a few frames) and writing `[]` cleared nothing. Number lists and native builds were right.diff --git a/native/host/Host.cpp b/native/host/Host.cppindex 2e80ccc9a..c48a6a596 100644--- a/native/host/Host.cpp+++ b/native/host/Host.cpp@@ -22,6 +22,7 @@#include "esengine/bindings/ActiveContext.hpp" // g_activeContext — the context the generated bindings act on#include "Bench.hpp"+#include "PackagedConfig.hpp"#include "Shot.hpp"#if defined(ESTELLA_DESKTOP)#include "steam/SteamApi.hpp"@@ -31,6 +32,7 @@#include "esengine/ecs/TransformSystem.hpp"#include "esengine/renderer/frame/RenderContext.hpp"#include "esengine/renderer/frame/RenderFrame.hpp"+#include "esengine/resource/ShaderParser.hpp"#include <glm/gtc/matrix_transform.hpp>@@ -269,6 +271,12 @@ bool boot(Platform& platform) {context.state().viewport_width = (i32)h.w;context.state().viewport_height = (i32)h.h;bootPhase("engine context");+ // Before the first shader compiles, as the web declares it before its renderer starts (PackagedConfig.hpp).+ {+ const std::vector<u8> config = platform.readAsset("game.config.json");+ resource::ShaderParser::setLinearColorSpace(packagedConfigIsLinear(+ std::string_view(reinterpret_cast<const char*>(config.data()), config.size())));+ }if (!context.init(std::move(device))) { ESHOST_LOGE("context.init failed"); return false; }static ecs::Registry registry;diff --git a/native/host/PackagedConfig.hpp b/native/host/PackagedConfig.hppnew file mode 100644index 000000000..9dde83175--- /dev/null+++ b/native/host/PackagedConfig.hpp@@ -0,0 +1,37 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file PackagedConfig.hpp+ * @brief The one thing a host must know of game.config.json before JS runs.+ *+ * @details Every other field reaches the engine from the SDK (renderOptions.ts). The colour space cannot: shaders compile against it, a+ * host compiles its first ones to paint the boot frame, and the JS engine comes up after that. The web declares it before its+ * renderer starts; this is the native road to the same moment. A host has no JSON parser and no other reason to grow one, and+ * the export writes this key only for a linear project, so a scan for that key and value is all it takes.+ */+#pragma once++#include <cctype>+#include <cstddef>+#include <string_view>++namespace eshost {++/** Whether a game.config.json declares `"colorSpace": "linear"`. Absent, malformed or anything else is gamma, as the SDK reads it. */+inline bool packagedConfigIsLinear(std::string_view json) {+ constexpr std::string_view key = "\"colorSpace\"";+ constexpr std::string_view value = "\"linear\"";+ const auto space = [&](size_t at) {+ while (at < json.size() && std::isspace(static_cast<unsigned char>(json[at]))) ++at;+ return at;+ };+ for (size_t at = json.find(key); at != std::string_view::npos; at = json.find(key, at + key.size())) {+ size_t next = space(at + key.size());+ if (next >= json.size() || json[next] != ':') continue;+ next = space(next + 1);+ if (json.compare(next, value.size(), value) == 0) return true;+ }+ return false;+}++} // namespace eshostdiff --git a/sdk/etc/index.native.api.md b/sdk/etc/index.native.api.mdindex c5539cc0a..7011b7326 100644--- a/sdk/etc/index.native.api.md+++ b/sdk/etc/index.native.api.md@@ -14653,7 +14653,7 @@ Plugin## createNativeApp — function @experimental```-(bridge: NativeBridge, scope?: Record<string, unknown>): App+(bridge: NativeBridge, scope?: Record<string, unknown>, options?: RenderOptions): App```## createNativeRegistry — function @experimentaldiff --git a/sdk/src/app/app.ts b/sdk/src/app/app.tsindex e8f571612..86680f1a8 100644--- a/sdk/src/app/app.ts+++ b/sdk/src/app/app.ts@@ -7,7 +7,7 @@import { World } from '../ecs/world';-import { installQuality } from '../render/qualityRuntime';+import { applyAppOptions, applyColorSpace, applyFrameOptions } from './renderOptions';import type { QualityConfig } from '../render/quality';import { Schedule, SystemDef, SystemRunner, SystemSet, mergeOrderingEdges, rescopeSystem, type RunCondition } from '../ecs/system';import { builtinResource, declaredResource, ResourceStorage, Time, TimeData, type ResourceDef } from '../ecs/resource';@@ -19,7 +19,7 @@ import type { AotManifest } from '../ecs/aot/AotSystems';import type { AotRuntime } from '../ecs/aot/AotRuntime';import { EventRegistry, eventNamed, type EventDef } from '../ecs/event';import type { ESEngineModule, CppRegistry } from '../wasm';-import { outputTransformCode, type OutputTransform } from '../postprocess';+import type { OutputTransform } from '../postprocess';import type { BridgeConnectOptions } from '../ecs/bridge/BuiltinBridge';import { UICameraInfo } from '../ui/core/ui-camera-info';import { ScreenLayout } from '../ui/core/screen-layout';@@ -44,11 +44,9 @@ import type { SceneConfig } from '../scene/sceneManager';import { SceneManager } from '../scene/sceneManager';import { sceneManagerPlugin } from '../scene/scenePlugin';import { getDefaultContext } from '../ecs/context';-import { setLinearColorSpace } from '../ecs/env';import { seedEngineComponents, type AnyComponentDef } from '../ecs/component';import { cameraPlugin } from '../camera/CameraPlugin';-import { ScreenScaling, SCREEN_FIT_OFF, type ScreenScalingData } from '../camera/ScreenScaling';-import { RenderResolution } from '../camera/presentPlan';+import type { ScreenScalingData } from '../camera/ScreenScaling';import { Physics2DRuntime } from '../physics/Physics2DRuntime';import { SubsystemRegistry } from './subsystems';import { DOMAIN_SCRIPTS, DOMAIN_UNATTRIBUTED, type ScopeCost, type ScopeRemainder, type SystemCost } from './frameProfile';@@ -2159,9 +2157,7 @@ export function createWebApp(module: ESEngineModule, options?: WebAppOptions): Aapp.connectCpp(cppRegistry, module, { strict: true, ownedRegistry: true });// BEFORE renderer init: shader compilation reads the color-space global.- // Always applied (realm reloads must reset a prior session's mode too).- setLinearColorSpace(options?.colorSpace === 'linear');- module.renderer_setColorSpace?.(options?.colorSpace === 'linear' ? 1 : 0);+ applyColorSpace(module, options);if (options?.randomSeed !== undefined) module.engine_setRandomSeed?.(options.randomSeed >>> 0);const surface: RenderSurfaceSource = options?.renderSurface ?? { kind: 'default' };@@ -2195,15 +2191,7 @@ export function createWebApp(module: ESEngineModule, options?: WebAppOptions): Abreak;}surfaces.set(app, { graphics: graphicsPathFor(surface), size: options?.getViewportSize ?? null });- // Always applied (not only when set): the renderer outlives the App on realm- // reloads, so a fresh App must reset a prior session's y-sort state too.- module.renderer_setYSortLayers?.((options?.ySortLayers ?? 0) >>> 0);- module.renderer_setDepthLayers?.((options?.depthLayers ?? 0) >>> 0);- // After the renderer, not with the colour space above it: the post-process- // pipeline is created by the renderer, and a curve declared before it exists- // reaches nothing.- module.postprocess_setOutputTransform?.(outputTransformCode(options?.outputTransform));- module.postprocess_setMsaaSamples?.((options?.msaaSamples ?? 4) >>> 0);+ applyFrameOptions(module, options);app.addPlugin(corePlugin);app.setPipeline(new RenderPipeline());@@ -2219,19 +2207,7 @@ export function createWebApp(module: ESEngineModule, options?: WebAppOptions): Aapp.addPlugins(options.plugins);}- // Project camera fit: only install the resource when the project opts in (a real- // scaleMode). Absent ⇒ CameraPlugin.resolveFitSource sees no resource and keeps- // the legacy Canvas-or-raw fit, so an unconfigured game is byte-for-byte unchanged.- // Either opt-in installs it. The render policy does not need a camera fit —- // it takes the camera's world height whatever produced it — and gating one on- // the other made a project that wanted only the policy get neither.- if (options?.screenFit- && (options.screenFit.scaleMode > SCREEN_FIT_OFF- || (options.screenFit.renderPolicy ?? RenderResolution.Surface) !== RenderResolution.Surface)) {- app.insertResource(ScreenScaling, { ...options.screenFit });- }-- if (options?.quality) installQuality(app, options.quality, options.msaaSamples ?? 4);+ applyAppOptions(app, options);return app;} catch (error) {try { app.quit({ keepRenderer: true }); }diff --git a/sdk/src/app/renderOptions.ts b/sdk/src/app/renderOptions.tsnew file mode 100644index 000000000..4eae28a07--- /dev/null+++ b/sdk/src/app/renderOptions.ts@@ -0,0 +1,69 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file renderOptions.ts+ * @brief What a project declares about its frame, handed to whichever core runs it.+ *+ * One function per moment and one caller per core, so the web and native apps cannot drift. They did: the native road read only+ * packagedRuntimeInit, so every field of packagedAppOptions was dropped on a device with no error. A linear project showed its+ * linear values unencoded, far too dark, and its output transform, MSAA, quality and layer sorting never arrived either.+ */+import { setLinearColorSpace } from '../ecs/env';+import { outputTransformCode, type OutputTransform } from '../postprocess';+import { installQuality } from '../render/qualityRuntime';+import { ScreenScaling, SCREEN_FIT_OFF, type ScreenScalingData } from '../camera/ScreenScaling';+import { RenderResolution } from '../camera/presentPlan';+import type { QualityConfig } from '../render/quality';+import type { App } from './app';++/** The engine entry points these reach, by the names the wasm module and the native host's API share. */+export interface RenderOptionsApi {+ renderer_setColorSpace?(linear: number): void;+ renderer_setYSortLayers?(layers: number): void;+ renderer_setDepthLayers?(layers: number): void;+ postprocess_setOutputTransform?(code: number): void;+ postprocess_setMsaaSamples?(samples: number): void;+}++export interface RenderOptions {+ colorSpace?: 'gamma' | 'linear';+ ySortLayers?: number;+ depthLayers?: number;+ outputTransform?: OutputTransform;+ msaaSamples?: number;+ screenFit?: ScreenScalingData;+ quality?: QualityConfig;+}++/**+ * Before any shader compiles: they compile against it. Always applied, not only when set, since the renderer outlives an App across a+ * realm reload and a fresh App must reset a prior session's mode.+ */+export function applyColorSpace(api: RenderOptionsApi, options: RenderOptions | undefined): void {+ setLinearColorSpace(options?.colorSpace === 'linear');+ api.renderer_setColorSpace?.(options?.colorSpace === 'linear' ? 1 : 0);+}++/**+ * Once the renderer exists: the post-process pipeline is created by it, and a curve declared before it exists reaches nothing. Always+ * applied, for the same reason as the colour space.+ */+export function applyFrameOptions(api: RenderOptionsApi, options: RenderOptions | undefined): void {+ api.renderer_setYSortLayers?.((options?.ySortLayers ?? 0) >>> 0);+ api.renderer_setDepthLayers?.((options?.depthLayers ?? 0) >>> 0);+ api.postprocess_setOutputTransform?.(outputTransformCode(options?.outputTransform));+ api.postprocess_setMsaaSamples?.((options?.msaaSamples ?? 4) >>> 0);+}++/** Once the App's plugins are in: what the options install as resources on it. */+export function applyAppOptions(app: App, options: RenderOptions | undefined): void {+ // Project camera fit: only install the resource when the project opts in (a real scaleMode). Absent, CameraPlugin.resolveFitSource+ // sees no resource and keeps the legacy Canvas-or-raw fit, so an unconfigured game is unchanged. Either opt-in installs it: the+ // render policy needs no camera fit, it takes the camera's world height whatever produced it.+ if (options?.screenFit+ && (options.screenFit.scaleMode > SCREEN_FIT_OFF+ || (options.screenFit.renderPolicy ?? RenderResolution.Surface) !== RenderResolution.Surface)) {+ app.insertResource(ScreenScaling, { ...options.screenFit });+ }+ if (options?.quality) installQuality(app, options.quality, options.msaaSamples ?? 4);+}diff --git a/sdk/src/ecs/bridge/nativeRuntime.ts b/sdk/src/ecs/bridge/nativeRuntime.tsindex 74ad6bdc9..2569f9182 100644--- a/sdk/src/ecs/bridge/nativeRuntime.ts+++ b/sdk/src/ecs/bridge/nativeRuntime.ts@@ -40,6 +40,7 @@ import { log } from '../../util/logger';import { setRendererBackend } from '../../render/renderer';import { RenderPipeline } from '../../render/renderPipeline';import { cameraPlugin } from '../../camera/CameraPlugin';+import { applyAppOptions, applyColorSpace, applyFrameOptions, type RenderOptions } from '../../app/renderOptions';import { UICameraInfo } from '../../ui/core/ui-camera-info';import { ScreenLayout } from '../../ui/core/screen-layout';import { ScreenOverlay, defaultScreenOverlay } from '../../ui/core/screen-overlay';@@ -118,6 +119,7 @@ export function createNativeWorld(export function createNativeApp(bridge: NativeBridge,scope: Record<string, unknown> = globalThis as unknown as Record<string, unknown>,+ options?: RenderOptions,): App {ensureBuiltinComponentsRegistered();// Route the SDK platform to the host before any plugin builds (inputPlugin binds@@ -139,7 +141,11 @@ export function createNativeApp(// builds the equivalent over the native ResourceManager; prefabs and scene// loading declare Assets as a required resource, so it precedes them.installNativeEngine(scope);+ // What the project declares about its frame, at the same moments the web app applies it (renderOptions.ts).+ const api = engineApi(app);+ if (api) applyColorSpace(api, options);installNativeRenderer(app, scope);+ if (api) applyFrameOptions(api, options);installNativeAssets(app, scope);installNativeUI(app, scope);app.addPlugin(inputPlugin);@@ -157,6 +163,7 @@ export function createNativeApp(// optional subsystem reaches an App through `entryPlugins`, and a factory// that names a couple of them by hand ships a device the rest never reach.app.addPlugins(inBuildOrder([...presentationBasePlugins(), ...entryPlugins()]));+ applyAppOptions(app, options);return app;}diff --git a/sdk/src/runtime/nativeGameRuntime.ts b/sdk/src/runtime/nativeGameRuntime.tsindex a6e809549..662d83915 100644--- a/sdk/src/runtime/nativeGameRuntime.ts+++ b/sdk/src/runtime/nativeGameRuntime.ts@@ -19,9 +19,9 @@ import { startDebugChannel } from './debugChannelHook';import type { App } from '../app/app';import { initRuntime } from './runtimeLoader';import { createNativeApp } from '../ecs/bridge/nativeRuntime';-import type { NativeBridge } from '../platform/native';+import { installNativePlatform, type NativeBridge } from '../platform/native';import { platformReadTextFile } from '../platform';-import { loadPackagedAssetIndex, createPackagedAssetSource, applyAssetRefResolvers, packagedRuntimeInit, type PackagedGameConfig } from './packagedRuntime';+import { loadPackagedAssetIndex, createPackagedAssetSource, applyAssetRefResolvers, packagedAppOptions, packagedRuntimeInit, type PackagedGameConfig } from './packagedRuntime';import type { SceneData } from '../scene/scene';import { log } from '../util/logger';@@ -48,11 +48,13 @@ export interface NativeGame {*/export async function initNativeGame(options: NativeGameOptions): Promise<NativeGame> {const { bridge, scope, width, height } = options;- const app = createNativeApp(bridge, scope);-+ // Read before the app is made, as a web host does: shaders compile against what it declares. The file comes through the platform, so+ // that goes in first.+ installNativePlatform(bridge);const config = JSON.parse(await platformReadTextFile(options.configPath ?? 'game.config.json'),) as PackagedGameConfig;+ const app = createNativeApp(bridge, scope, packagedAppOptions(config));if (config.debugChannel) startDebugChannel(config.debugChannel);const index = await loadPackagedAssetIndex();diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txtindex a42c07e2d..b0d7867be 100644--- a/tests/CMakeLists.txt+++ b/tests/CMakeLists.txt@@ -114,6 +114,13 @@ add_executable(test_frame_pacertarget_include_directories(test_frame_pacer PRIVATE ${CMAKE_SOURCE_DIR}/native/host)add_test(NAME test_frame_pacer COMMAND test_frame_pacer)+# What a native host reads of game.config.json before any shader compiles.+add_executable(test_packaged_config+ input/test_packaged_config.cpp+)+target_include_directories(test_packaged_config PRIVATE ${CMAKE_SOURCE_DIR}/native/host)+add_test(NAME test_packaged_config COMMAND test_packaged_config)+# The read-only mapping the native glyph rasterizer opens fonts through# (native/host/media/mapped_file.hpp): header-only, so no host is needed.add_executable(test_mapped_filediff --git a/tests/input/test_packaged_config.cpp b/tests/input/test_packaged_config.cppnew file mode 100644index 000000000..5c2785133--- /dev/null+++ b/tests/input/test_packaged_config.cpp@@ -0,0 +1,38 @@+// SPDX-License-Identifier: Apache-2.0+// SPDX-FileCopyrightText: Copyright (c) 2024-present ESEngine Team+/**+ * @file What a native host reads of game.config.json before any shader compiles+ * (native/host/PackagedConfig.hpp). Too late, and a linear project shows+ * its linear values with no encode: far too dark, with no error.+ */+#define DOCTEST_CONFIG_IMPLEMENT_WITH_MAIN+#include "doctest.h"++#include "PackagedConfig.hpp"++using eshost::packagedConfigIsLinear;++TEST_CASE("a linear project is found however the file is spaced") {+ CHECK(packagedConfigIsLinear(R"({"colorSpace":"linear"})"));+ CHECK(packagedConfigIsLinear("{\n \"entryScene\": \"a\",\n \"colorSpace\": \"linear\",\n \"x\": 1\n}"));+ CHECK(packagedConfigIsLinear("{ \"colorSpace\" \t:\r\n \"linear\" }"));+}++TEST_CASE("anything else is gamma, as the SDK reads it") {+ CHECK_FALSE(packagedConfigIsLinear(""));+ CHECK_FALSE(packagedConfigIsLinear("{}"));+ CHECK_FALSE(packagedConfigIsLinear(R"({"colorSpace":"gamma"})"));+ CHECK_FALSE(packagedConfigIsLinear(R"({"colorSpace":"linearish"})"));+ CHECK_FALSE(packagedConfigIsLinear(R"({"name":"colorSpace","other":"linear"})"));+}++TEST_CASE("a truncated file does not read past its end") {+ CHECK_FALSE(packagedConfigIsLinear(R"("colorSpace")"));+ CHECK_FALSE(packagedConfigIsLinear(R"("colorSpace":)"));+ CHECK_FALSE(packagedConfigIsLinear(R"("colorSpace": "lin)"));+}++TEST_CASE("a value that is not the key's is not taken for it") {+ CHECK_FALSE(packagedConfigIsLinear(R"({"colorSpace":"gamma","mode":"linear"})"));+ CHECK(packagedConfigIsLinear(R"({"note":"colorSpace","colorSpace":"linear"})"));+}diff --git a/tools/releaseNotes.mjs b/tools/releaseNotes.mjsindex 087b43f70..92135a1e7 100644--- a/tools/releaseNotes.mjs+++ b/tools/releaseNotes.mjs@@ -3854,4 +3854,6 @@ export const NOTED = {{"note":"Voxel GI costs a third of what it did."},"fix(render): Voxel GI's screen samples take a different pixel of four each frame, so a thin face no longer makes a wall's bounce change with the size of the picture":{"note":"Voxel GI no longer changes with the size of the picture."},+ "fix(native): a packaged game's colour space, output transform, MSAA, quality, layers and camera fit reach a native host, so a linear project is no longer far too dark":+ {"note":"A linear project on a native build is no longer far too dark."},};diff --git a/tools/verify-desktop-render.mjs b/tools/verify-desktop-render.mjsindex 07e652c78..7c29fc05b 100644--- a/tools/verify-desktop-render.mjs+++ b/tools/verify-desktop-render.mjs@@ -23,7 +23,7 @@* and the release is the run that builds the template it is given.*/import { execFileSync, spawnSync } from 'node:child_process';-import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync } from 'node:fs';+import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';import { tmpdir } from 'node:os';import path from 'node:path';import { fileURLToPath } from 'node:url';@@ -124,6 +124,42 @@ function desktopPixelsFor(id) {}}+/**+ * A linear project's colours on the packaged host: a grey of 0.2 in linear light must reach the screen encoded, 124, and not as 51. The+ * host knew nothing of the project's colour space, and every linear game showed its linear values, far too dark, for as long as there+ * was a native road. No project could say so: the frames drew, and the probes compare against what each one looked like.+ */+function linearColourReachesTheScreen(templateDir, work) {+ const project = path.join(work, 'linear-colour-project');+ mkdirSync(path.join(project, 'assets', 'scenes'), { recursive: true });+ writeFileSync(path.join(project, 'project.esproject'), JSON.stringify({+ formatVersion: '1', name: 'LinearColour', version: '1.0.0', tag: '3D', defaultScene: 'assets/scenes/main.esscene',+ designResolution: { width: 640, height: 360 }, spineVersion: 'none',+ features: { rendering: { colorSpace: 'linear' } },+ }));+ writeFileSync(path.join(project, 'assets', 'scenes', 'main.esscene'), JSON.stringify({+ version: 4, name: 'Main', entities: [+ { id: 0, name: 'Camera', parent: null, children: [], visible: true, components: [+ { type: 'Transform', data: { position: { x: 0, y: 0, z: 500 } } },+ { type: 'Camera', data: { projectionType: 0, fov: 60, nearPlane: 1, farPlane: 2000, isActive: true, priority: 0, clearFlags: 3 } },+ ] },+ { id: 1, name: 'Grey', parent: null, children: [], visible: true, components: [+ { type: 'Transform', data: { scale: { x: 20, y: 20, z: 1 } } },+ { type: 'MeshRenderer', data: { mesh: 'builtin:cube', lit: false, opaque: true, color: { r: 0.2, g: 0.2, b: 0.2, a: 1 } } },+ ] },+ ],+ }));+ execFileSync(process.execPath, [path.join(ROOT, 'tools', 'asset-meta.js'), path.join(project, 'assets')], { stdio: 'pipe' });+ const { verdict, raw } = packageAndRun(project, templateDir, work);+ // The block fills the frame, so `rendered`, which asks for more than one colour, is not the question here.+ if (!verdict) return 'no frame was captured';+ const pixels = readFileSync(raw);+ const at = (Math.floor(verdict.h / 2) * verdict.w + Math.floor(verdict.w / 2)) * 4;+ const grey = pixels[at];+ return Math.abs(grey - 124) <= 6 ? null : `a linear grey of 0.2 reached the screen as ${grey}, not 124`+ + (Math.abs(grey - 51) <= 6 ? ': that is the value with no encode, so the host ignored the colour space of the project' : '');+}+const opts = parseArgs(process.argv.slice(2));const templateDir = opts.template ?? installedTemplateDir(JSON.parse(readFileSync(path.join(ROOT, 'package.json'), 'utf8')).version, HOST_OS);@@ -204,6 +240,13 @@ try {}}}+ const wrong = linearColourReachesTheScreen(templateDir, work);+ if (wrong) {+ console.error(`✗ linear colour: ${wrong}`);+ failed += 1;+ } else {+ console.log('✓ linear colour: a linear project is encoded on the way to the screen');+ }} finally {rmSync(work, { recursive: true, force: true, maxRetries: 10, retryDelay: 50 });}