import { AbstractEngine, HavokPlugin } from '@babylonjs/core'; import { GameCanvas } from "../interfaces/game.d.ts"; import { Disposable } from "../interfaces/lifecycle.d.ts"; import { SceneEngine } from "../engines/scene.d.ts"; import { AudioEngine } from "../engines/audio.d.ts"; import { AssetManager } from "../managers/asset.d.ts"; import { BindingManager } from "../managers/binding.d.ts"; import { ColliderDebugManager } from "../managers/colliderDebug.d.ts"; import { DebugConsole } from "./debugConsole.d.ts"; import { GameManager } from "../managers/game.d.ts"; import { GameEntityManager } from "../managers/entity.d.ts"; import { LevelManager } from "../managers/level.d.ts"; import { SaveManager } from "../managers/save.d.ts"; import { UserInputManager } from "../managers/input.d.ts"; import { AudioManager } from "../managers/audio.d.ts"; import { GameEvent, GameEventBus, GameEventCallback, Unsubscribe } from "./eventBus.d.ts"; import { ActionPayload, LibraryEventPayloadMap } from "../events/payloads.d.ts"; import { WildcardPattern } from "../events/types.d.ts"; import { LoggingUtility } from "../utils/logger.d.ts"; import { RaycastHelper } from "../utils/raycast.d.ts"; import { GameTimer } from "../utils/timer.d.ts"; /** * Type definition for game lifecycle hook functions */ export type GameHook = (gameEngine: GameEngine) => Promise; /** * Interface representing the engines used in the game. * All engines must implement Disposable for proper cleanup. */ interface Engines extends Record { sceneEngine: SceneEngine; audioEngine?: AudioEngine; } /** * Interface representing the managers used in the game. * All managers must implement Disposable for proper cleanup. */ interface Managers extends Record { assetManager: AssetManager; bindingManager: BindingManager; gameManager: GameManager; entityManager: GameEntityManager; inputManager: UserInputManager; levelManager: LevelManager; saveManager: SaveManager; audioManager?: AudioManager; } /** * Interface representing the debug tools available on the engine. */ interface DebugTools { colliders: ColliderDebugManager; console: DebugConsole | null; expose(name: string, value: unknown): void; } /** * Central hub that owns the render loop, physics, event bus, and all managers. * Created via `createGameEngine()` in sage.ts. */ export declare class GameEngine { canvas: GameCanvas; renderEngine: AbstractEngine; physics: HavokPlugin; managers: Managers; engines: Engines; eventBus: GameEventBus; logger: LoggingUtility; raycast: RaycastHelper; timer: GameTimer; debug: DebugTools; largeWorldRendering: boolean; started: boolean; private _log; private _beforeStartHook; private _onStartHook; private _onTeardownHook; /** * Creates an instance of GameEngine. * @param canvas * @param renderEngine * @param physics * @param eventBus * @param logger * @param engines * @param managers */ constructor(canvas: GameCanvas, renderEngine: AbstractEngine, physics: HavokPlugin, eventBus: GameEventBus, logger: LoggingUtility, raycast: RaycastHelper, timer: GameTimer, engines: Engines, managers: Managers, largeWorldRendering?: boolean, debug?: DebugTools); /** * Register a function to be called before the game engine starts * @param hook * @throws Error if a hook is already registered */ onBeforeStart(hook: GameHook): void; /** * Register a function to be called after the game engine starts * @param hook * @throws Error if a hook is already registered */ onStart(hook: GameHook): void; /** * Register a function to be called when the game engine stops * @param hook * @throws Error if a hook is already registered */ onTeardown(hook: GameHook): void; /** * Subscribe to an event on the event bus. * * This is a convenience method that forwards to `eventBus.subscribe()`. * * @param eventType - Exact event type string, wildcard pattern (e.g. 'input:*'), or RegExp * @param callback * @returns A function that removes this subscription when called * * @example * // Subscribe to a specific event * const unsub = engine.subscribe('level:complete', (event) => { * console.log('Level complete:', event.payload.levelName); * }); * * // Subscribe to all input events * engine.subscribe('input:*', (event) => { * console.log('Input event:', event.type); * }); */ subscribe(eventType: T | WildcardPattern | RegExp, callback: GameEventCallback): Unsubscribe; /** * Subscribe to an action event with full type safety. * * Action events are fired by the binding system when inputs trigger registered actions. * All action events have the same payload structure (`ActionPayload`), containing: * - `value`: The action value (number for analog, boolean for digital) * - `deviceId`: The ID of the input device that triggered the action * - `context`: The binding context that was active (optional) * * @param actionName - The action name (without the 'action:' prefix) * @param callback * @returns A function that removes this subscription when called * * @example * // Subscribe to a specific action * engine.subscribeAction('jump', (event) => { * console.log('Jump triggered with value:', event.payload.value); * console.log('From device:', event.payload.deviceId); * }); * * // Subscribe to movement action * engine.subscribeAction('moveForward', (event) => { * const velocity = Number(event.payload.value); * player.move(velocity); * }); */ subscribeAction(actionName: string, callback: (event: GameEvent<`action:${string}`, Record<`action:${string}`, ActionPayload>>) => void): Unsubscribe; /** * Start the engine: runs beforeStart hook, starts the game manager, then runs onStart hook. */ start(): Promise; /** * Stop the engine: runs the teardown hook, then tears down all managers and engines in order. */ stop(): Promise; } export {};