import { RegistryData } from "../ecs/batchUtils.js"; import { BufferDisplayMode, RegistryEntryKind, TexturePixelType } from "../debug-protocol.js"; import { DebugRegistry } from "./DebugRegistry.js"; import { DebugTextureRegistry } from "./DebugTextureRegistry.js"; import { BatchCollector } from "./BatchCollector.js"; import { DataTexture, InstancedMesh, Texture } from "three"; import { WebGPURenderer } from "three/webgpu"; //#region src/debug/debug-sink.d.ts /** * Batch source registrations. Each source is a getter that resolves to * the latest `RegistryData` (or null if the host's registry isn't ready * yet). Getters are called by `BatchCollector.captureAllSources` once * per frame; zero work when no consumer is subscribed to `'batches'`. * * Using getters rather than direct `RegistryData` refs means * SpriteGroup / Flatland can register *once* at construction and we * always see the live singleton, even if the host recreates it. */ type BatchSourceFn = () => RegistryData | null; /** * One entry from a mesh batch source. Raw `InstancedMesh` is accepted * for ease of use; the richer object form lets sources decorate each * batch with a `kind` tag (for categorization in the panel) and a * `label` (e.g. `'chunk(0,2)'`) to disambiguate identical-material * batches in the inspector. */ interface MeshBatchEntry { mesh: InstancedMesh; /** See `BatchInfo.kind` in the protocol. */ kind?: string; /** See `BatchInfo.label` in the protocol. */ label?: string; } /** * Alternate batch-source flavour for engine code that manages its own * `InstancedMesh`es outside the ECS (e.g. `TileLayer`'s per-chunk * instanced meshes). Each getter yields either raw `InstancedMesh` * objects (simple / back-compat) or `MeshBatchEntry` records that * carry an explicit kind + label per batch. Returning `null` means * "no meshes right now" — cheaper than handing back an empty array. */ type MeshBatchSourceFn = () => Iterable | null; /** @internal Called by `DevtoolsProvider` — not for app code. */ declare function _setActiveRegistry(registry: DebugRegistry | null): void; /** @internal Called by `DevtoolsProvider` — not for app code. */ declare function _setActiveTextureRegistry(registry: DebugTextureRegistry | null): void; /** * Publish (or re-publish) a named CPU array to the devtools pane. * Holds a *reference*; the host keeps mutating its own buffer. Call * `touchDebugArray(name)` when you mutate in place so the provider * knows to re-send on the next batch. Replacing the buffer (new * `ref`) calls `touchDebugArray` implicitly. * * Safe to call any time — no-op when devtools isn't bundled. */ declare function registerDebugArray(name: string, ref: Float32Array | Uint32Array | Int32Array, kind: RegistryEntryKind, opts?: { label?: string; length?: number; }): void; /** * Signal that a previously-registered array has been mutated in place * and should be re-sampled on the next batch flush. */ declare function touchDebugArray(name: string, length?: number): void; /** Remove a named array. Consumers will see it disappear on the next batch. */ declare function unregisterDebugArray(name: string): void; /** * Publish a debug texture (DataTexture or RenderTarget) to the * devtools pane. Readback is only performed when a consumer has * selected this name for preview — safe to leave registered. * * `source` may be a `DataTexture` (CPU-backed, cheap) or any object * shaped like a `WebGLRenderTarget` / `WebGPURenderTarget` with * `width`, `height`, `texture`. No-op when devtools isn't bundled. */ declare function registerDebugTexture(name: string, source: DataTexture | { width: number; height: number; texture: Texture; }, pixelType?: TexturePixelType, opts?: { label?: string; display?: BufferDisplayMode; }): void; /** Signal that a registered texture's content has changed. */ declare function touchDebugTexture(name: string): void; /** Remove a named texture. */ declare function unregisterDebugTexture(name: string): void; /** @internal Called by `DevtoolsProvider` — not for app code. */ declare function _setActiveBatchCollector(bc: BatchCollector | null): void; /** * `true` when a consumer is currently subscribed to the `'batches'` * feature. Gate any work that builds pass labels or looks at renderer * state behind this — `beginDebugPass` / `endDebugPass` are already * self-gating but the check is cheaper than an unused `label` literal * slot in the callsite's scope. */ declare function isBatchCapturing(): boolean; /** * Record the start of a render pass. Label must be a stable string * constant — never concatenated per-frame. Paired with `endDebugPass`. * No-op when devtools isn't bundled or no consumer is subscribed. */ declare function beginDebugPass(label: string, renderer: WebGPURenderer): void; declare function endDebugPass(renderer: WebGPURenderer): void; /** * Register a source of `RegistryData` so the batch collector can pull * the active-batches snapshot at end-of-frame. Called by engine / * framework code (Flatland, `SpriteGroup`) once per owned world. * * No-op when devtools isn't bundled. The set is keyed by reference; * pass the same function to `_unregisterBatchSource` on dispose. */ declare function _registerBatchSource(source: BatchSourceFn): void; declare function _unregisterBatchSource(source: BatchSourceFn): void; /** @internal Used by `DevtoolsProvider.endFrame`. */ declare function _getBatchSources(): ReadonlySet; /** * Register a mesh-based batch source. See `MeshBatchSourceFn` for * semantics. No-op when devtools isn't bundled. Pair each register * with an unregister on the same function reference at dispose. */ declare function _registerMeshBatchSource(source: MeshBatchSourceFn): void; declare function _unregisterMeshBatchSource(source: MeshBatchSourceFn): void; /** @internal Used by `DevtoolsProvider.endFrame`. */ declare function _getMeshBatchSources(): ReadonlySet; //#endregion export { BatchSourceFn, MeshBatchEntry, MeshBatchSourceFn, _getBatchSources, _getMeshBatchSources, _registerBatchSource, _registerMeshBatchSource, _setActiveBatchCollector, _setActiveRegistry, _setActiveTextureRegistry, _unregisterBatchSource, _unregisterMeshBatchSource, beginDebugPass, endDebugPass, isBatchCapturing, registerDebugArray, registerDebugTexture, touchDebugArray, touchDebugTexture, unregisterDebugArray, unregisterDebugTexture }; //# sourceMappingURL=debug-sink.d.ts.map