namespace NT { /**
     * The main game engine class.
     * */ export class Engine { private _previousTime : number = 0 ; private _gameWidth : number ; private _gameHeight : number ; private _isFirstUpdate : boolean = true ; private _renderer : Renderer ; private _game : IGame ; param width param height public constructor ( width ? , height ? ) { this . _gameWidth = width ; this . _gameHeight = height ; } param game param elementName public start ( game , elementName ? ) { this . _game = game ; let rendererViewportCreateInfo = new RendererViewportCreateInfo ( ) ; rendererViewportCreateInfo . elementId = elementName ; rendererViewportCreateInfo . projectionType = ViewportProjectionType . PERSPECTIVE ; rendererViewportCreateInfo . width = this . _gameWidth ; rendererViewportCreateInfo . height = this . _gameHeight ; rendererViewportCreateInfo . nearClip = 0.1 ; rendererViewportCreateInfo . farClip = 1000.0 ; rendererViewportCreateInfo . fov = Math . degToRad ( 45.0 ) ; rendererViewportCreateInfo . x = 0 ; rendererViewportCreateInfo . y = 0 ; this . _renderer = new Renderer ( rendererViewportCreateInfo ) ; console . debug ( `GL_VERSION:               ${ gl . getParameter ( gl . VERSION ) }` ) ; console . debug ( `GL_VENDOR:                ${ gl . getParameter ( gl . VENDOR ) }` ) ; console . debug ( `GL_RENDERER:              ${ gl . getParameter ( gl . RENDERER ) }` ) ; console . debug ( `SHADING_LANGUAGE_VERSION: ${ gl . getParameter ( gl . SHADING_LANGUAGE_VERSION ) }` ) ; const debugRendererExtension = gl . getExtension ( 'WEBGL_debug_renderer_info' ) ; if ( debugRendererExtension !== undefined && debugRendererExtension !== null ) { console . debug ( `UNMASKED_VENDOR_WEBGL:    ${ gl . getParameter ( debugRendererExtension . UNMASKED_VENDOR_WEBGL ) }` ) ; console . debug ( `UNMASKED_RENDERER_WEBGL:  ${ gl . getParameter ( debugRendererExtension . UNMASKED_RENDERER_WEBGL ) }` ) ; } AssetManager . Initialize ( ) ; ShaderManager . Initialize ( ) ; InputManager . Initialize ( this . _renderer . windowViewportCanvas ) ; BitmapFontManager . load ( ) ; LevelManager . load ( ) ; MaterialManager . load ( ) ; AudioManager . load ( ) ; this . resize ( ) ; this . preloading ( ) ; } /**
         * Resizes the canvas to fit the window.
         * */ public resize ( ) { if ( this . _renderer ) { this . _renderer . OnResize ( ) ; } } /**
         * The main game loop.
         */ private loop ( ) { if ( this . _isFirstUpdate ) { } let delta = performance . now ( ) - this . _previousTime ; this . update ( delta ) ; this . render ( delta ) ; this . _previousTime = performance . now ( ) ; requestAnimationFrame ( this . loop . bind ( this ) ) ; } private preloading ( ) { MessageBus . update ( 0 ) ; if ( ! BitmapFontManager . isLoaded ) { requestAnimationFrame ( this . preloading . bind ( this ) ) ; return ; } if ( ! MaterialManager . isLoaded ) { requestAnimationFrame ( this . preloading . bind ( this ) ) ; return ; } if ( ! LevelManager . isLoaded ) { requestAnimationFrame ( this . preloading . bind ( this ) ) ; return ; } this . _game . UpdateReady ( ) ; this . loop ( ) ; } private update ( delta ) { MessageBus . update ( delta ) ; if ( LevelManager . isLoaded && LevelManager . activeLevel !== undefined && LevelManager . activeLevel . isLoaded ) { LevelManager . activeLevel . update ( delta ) ; } this . _game . Update ( delta ) ; } private render ( delta ) { this . _renderer . BeginRender ( delta , this . _game ) ; this . _renderer . EndRender ( ) ; } } }