import { Container, Rectangle, Texture } from 'pixi.js'; import { Disposable } from '../utils/Disposable.js'; import { ReelSymbol } from '../symbols/ReelSymbol.js'; /** * The slice of a PixiJS renderer the cache needs. `Renderer` (WebGL or * WebGPU) satisfies it structurally; tests can pass a stub. */ export interface SnapshotRenderer { generateTexture(options: { target: Container; frame?: Rectangle; resolution?: number; antialias?: boolean; }): Texture; } /** Tuning for the baked motion-blur variant of a snapshot. */ export interface MotionBlurOptions { /** * Smear axis — the reel's travel direction. `'y'` (default) for normal * vertical reels; `'x'` for a `HorizontalReel` strip. The other axis is * never blurred. */ axis?: 'y' | 'x'; /** * Blur strength in pixels along the axis. Default: 20% of the cell's * span on that axis (`cellHeight * 0.2` for `'y'`, `cellWidth * 0.2` * for `'x'`). */ strength?: number; /** BlurFilter quality (number of passes). Default: 4. */ quality?: number; /** * Extra transparent pixels added on both sides of the cell along the * axis so the smear isn't clipped at the texture edge. * Default: `ceil(strength)`. */ padding?: number; } export interface SpinTextureCacheOptions { /** The renderer used to generate snapshot textures (`app.renderer`). */ renderer: SnapshotRenderer; /** Resolution for generated textures. Default: the renderer's default. */ resolution?: number; /** Default motion-blur tuning for `captureBlurred`. */ blur?: MotionBlurOptions; } /** * Per-symbolId cache of "spin textures". flat snapshots a reel shows * instead of the live symbol (Spine skeleton, animated sprite, ...) while * it spins. * * Two flavors per symbolId: * * - **static**. the symbol rendered once into a RenderTexture at cell size. * - **blurred**. the static snapshot smeared vertically through a one-time * BlurFilter pass into a taller, padded RenderTexture. At spin time it's * an ordinary sprite texture: zero filters per frame. * * Textures come from two sources, user-provided always winning: * * - `setStatic(id, tex)` / `setBlurred(id, tex)`. hand-authored art from * your atlas. Never destroyed by the cache. * - `captureStatic` / `captureBlurred`. generated on demand from a live * symbol view. Owned by the cache and destroyed on `invalidate` / * `clear` / `destroy`. * * Captures are keyed by symbolId and remembered together with the cell size * they were taken at; capturing again at a different size regenerates. * Share ONE cache across all reels/symbols of a reel set. that's the point. */ export declare class SpinTextureCache implements Disposable { private _renderer; private _resolution; private _blurDefaults; private _static; private _blurred; private _isDestroyed; constructor(options: SpinTextureCacheOptions); /** Provide a hand-authored static spin texture. Wins over captures. */ setStatic(symbolId: string, texture: Texture): void; /** Provide a hand-authored motion-blur texture. Wins over captures. */ setBlurred(symbolId: string, texture: Texture): void; getStatic(symbolId: string): Texture | null; getBlurred(symbolId: string): Texture | null; hasStatic(symbolId: string): boolean; hasBlurred(symbolId: string): boolean; /** * Snapshot `source` (a symbol's `view`, already activated and resized to * the cell) into a `width`x`height` texture and cache it under `symbolId`. * Returns the cached texture if one already exists at this size; a * user-provided texture always short-circuits. */ captureStatic(symbolId: string, source: Container, width: number, height: number): Texture; /** * Bake a motion-blurred variant of the static snapshot for `symbolId` * (which must exist. call `captureStatic` or `setStatic` first) and * cache it. The smear runs along `blur.axis` — the reel's travel * direction (`'y'` default; `'x'` for a `HorizontalReel`) — and the * result is `2 * padding` larger than the cell on that axis only. Draw * it center-anchored at the cell center and the smear extends evenly * past the cell on both sides. */ captureBlurred(symbolId: string, width: number, height: number, blur?: MotionBlurOptions): Texture; /** Drop (and destroy, if cache-generated) both textures for one symbolId. */ invalidate(symbolId: string): void; /** Drop everything. Call when the cell size changes (responsive relayout). */ clear(): void; destroy(): void; get isDestroyed(): boolean; private _put; private _drop; } export interface PrewarmSpinTexturesOptions { /** The shared cache to fill. */ cache: SpinTextureCache; /** Every symbolId to bake. */ ids: string[]; /** * Factory for a scratch symbol used as the render source. Typically the * same factory you registered (e.g. `() => new SpineReelSymbol(opts)`). * It is activated per id, snapshotted, and destroyed at the end. */ createSymbol: () => ReelSymbol; /** Cell width the reels will use. */ width: number; /** Cell height the reels will use. */ height: number; /** Also bake the motion-blur variants. Default: true. */ blurred?: boolean; /** Motion-blur tuning override (defaults to the cache's). */ blur?: MotionBlurOptions; } /** * Bake spin textures for every symbolId up front (at load or between * rounds) so the first spin never pays a capture hitch. Ids that already * have a user-provided or captured texture are skipped by the cache. * * ```ts * prewarmSpinTextures({ * cache, * ids: ['cherry', 'lemon', 'seven'], * createSymbol: () => new SpineReelSymbol(spineOpts), * width: 150, * height: 150, * }); * ``` */ export declare function prewarmSpinTextures(options: PrewarmSpinTexturesOptions): void; //# sourceMappingURL=SpinTextureCache.d.ts.map