//@ts-nocheck /** * Graphics Backend Types * * Core types for the graphics backend system. */ import { PlayerStateReactive } from '../playerState/playerState' import { ResourcesManagerTransferred } from '../resourcesManager' import { WorldViewWorker } from '../worldView' import { Vec3 } from 'vec3' import { WorldRendererConfig } from './config' // ============================================================================ // Graphics Backend Configuration // ============================================================================ export type MaybePromise = Promise | T export interface SoundSystem { playSound: (position: { x: number, y: number, z: number }, path: string, volume?: number, pitch?: number, timeout?: number) => void destroy: () => void } import type { MenuBackgroundOptions } from '../three/menuBackground/types' import type { RendererStorageOptions } from './rendererDefaultOptions' import type { MenuBackgroundRenderer } from '../three/menuBackground/renderer' import type { PerformanceInstabilityFactors } from '../performanceMonitor' /** Graphics backend configuration */ export interface GraphicsBackendConfig { fpsLimit?: number statsVisible?: number sceneBackground: string timeoutRendering?: boolean /** Default options when `startMenuBackground()` is called without arguments */ menuBackground?: MenuBackgroundOptions } // ============================================================================ // World Renderer Configuration // ============================================================================ // ============================================================================ // State Types // ============================================================================ /** Frame timing event for performance monitoring */ export interface FrameTimingEvent { type: 'frameStart' | 'frameEnd' | 'cameraUpdate' | 'frameDisplay' timestamp: number duration?: number } /** Non-reactive state for performance data */ export interface NonReactiveState { fps: number worstRenderTime: number avgRenderTime: number world: { chunksLoadedCount: number chunksTotalNumber: number chunksFullInfo: string allChunksLoaded?: boolean } renderer: { timeline: { live: FrameTimingEvent[] frozen: FrameTimingEvent[] lastSecond: FrameTimingEvent[] } } } /** Renderer reactive state */ export interface RendererReactiveState { world: { chunksLoaded: Record heightmaps: Record allChunksLoaded: boolean mesherWork: boolean /** Low-FPS / render instability factors (see `performanceMonitor`). */ instabilityFactors: PerformanceInstabilityFactors intersectMedia: any | null } renderer: string preventEscapeMenu: boolean } // ============================================================================ // Player State Types // ============================================================================ // ============================================================================ // Graphics Backend Interfaces // ============================================================================ /** Graphics initialization options */ export interface GraphicsInitOptions { config: GraphicsBackendConfig /** Live app options (e.g. valtio proxy); used for WebGL `gpuPreference` at context creation. */ getRendererOptions?: () => RendererStorageOptions rendererSpecificSettings: S hello?: boolean callbacks: { displayCriticalError: (error: Error) => void setRendererSpecificSettings: (key: string, value: any) => void fireCustomEvent: (eventName: string, ...args: any[]) => void } } /** Display world options for starting world rendering */ export interface DisplayWorldOptions { version: string worldView: WorldViewWorker inWorldRenderingConfig: WorldRendererConfig playerStateReactive: PlayerStateReactive rendererState: RendererReactiveState nonReactiveState: NonReactiveState resourcesManager: ResourcesManagerTransferred } /** Graphics backend interface */ export interface GraphicsBackend { id: string displayName: string startMenuBackground(options?: MenuBackgroundOptions): Promise startWorld(options: DisplayWorldOptions): Promise disconnect(): void setRendering(rendering: boolean): void updateCamera(pos: Vec3 | null, yaw: number, pitch: number): void soundSystem?: any backendMethods?: any getDebugOverlay?(): { entitiesString?: string, left?: Record, right?: Record } /** Active main-menu background, when `currentDisplay === 'menu'`. */ getMenuBackground?(): MenuBackgroundRenderer | undefined } /** Graphics backend loader function type */ export type GraphicsBackendLoader = ((options: GraphicsInitOptions) => MaybePromise) & { id: string displayName?: string description?: string } // ============================================================================ // World View Interface // ============================================================================ /** World view interface for type compatibility */ export interface WorldViewLike { isPlayground?: boolean addWaitTime?: number loadedChunks: Record init(pos: Vec3): Promise setBlockStateId(pos: Vec3, stateId: number): void unloadAllChunks(): void emit(event: string, ...args: any[]): boolean on(event: string, callback: (...args: any[]) => void): void }