import { expose } from 'threads/worker' ; import { Container , Inject , Singleton } from 'typescript-ioc' ; import { RendererComponent } from './renderer/renderer.component' ; import { RendererManager } from './renderer/renderer.manager' ; import { WorldManager } from './world/world.manager' ; import { CoreControllerComponent } from './controller/core-controller.component' ; import { CameraManager } from './camera/camera.manager' ; import { KeyEvent } from '../common/controller/controller.model' ; import { TimerManager } from './timer/timer.manager' ; import { EventStatus } from '../common/event.model' ; import { MapComponent } from './map/map.component' ; import { TeleportManager } from './teleport/teleport.manager' ; import { PhysicsManager } from './physics/physics.manager' ; import { GameManager } from "./game/game-manager" ; import { PointerControllerManager } from "./controller/pointer/pointer-controller.manager" ; import { PortalPlacingManager } from "./portal-placing/portal-placing.manager" ; import { PortalWorldPlacingManager } from "./portal-placing/portal-world-placing.manager" ; @ Singleton export class CoreThread { constructor ( @ Inject private readonly renderer , @ Inject private readonly rendererComponent , @ Inject private readonly world , @ Inject private readonly camera , @ Inject private readonly controller , @ Inject private readonly teleport , @ Inject private readonly timer , @ Inject private readonly physics , @ Inject private readonly map , @ Inject private readonly game , @ Inject private readonly pointer , @ Inject private readonly portalPlacing , @ Inject private readonly portalWorldPlacing ) { this . waitForCanvas ( ) ; } private waitForCanvas ( ) { onmessage = ( event ) => { const canvas = event ?. data ?. canvas ; if ( canvas ) { this . init ( canvas ) ; } } ; } setSize ( width , height ) { this . controller . resize ( width , height ) ; } setPointerLock ( status ) { this . controller . setPointerLock ( status ) ; } mouseMove ( x , y ) { this . controller . move ( x , y ) ; } keyEvent ( keyEvent ) { this . controller . keyEvent ( keyEvent ) ; } private init ( canvas ) { this . rendererComponent . init ( canvas ) ; this . setSize ( canvas . width , canvas . height ) ; console . log ( 'Core thread OK' ) ; this . map . load ( ) ; } } const coreThread = Container . get ( CoreThread ) ; expose ( { setSize : coreThread . setSize . bind ( coreThread ) , setPointerLock : coreThread . setPointerLock . bind ( coreThread ) , mouseMove : coreThread . mouseMove . bind ( coreThread ) , keyEvent : coreThread . keyEvent . bind ( coreThread ) , } ) ;