package wow.doge.mygame import scala.concurrent.duration._ import _root_.monix.bio.Task import akka.util.Timeout import cats.effect.ExitCode import cats.implicits._ import com.softwaremill.macwire._ import io.odin._ import io.odin.json.Formatter import io.odin.syntax._ import wow.doge.mygame.game.GameAppResource import wow.doge.mygame.subsystems.scriptsystem.ScriptSystemResource import _root_.monix.bio.BIOApp import _root_.monix.bio.UIO import cats.effect.Resource object Main extends BIOApp with MainModule { import java.util.logging.{Logger => JLogger, Level} JLogger.getLogger("").setLevel(Level.SEVERE) implicit val timeout = Timeout(1.second) def appResource = for { logger <- consoleLogger().withAsync(timeWindow = 1.milliseconds) |+| fileLogger( "application-log-1.log", Formatter.json ).withAsync(timeWindow = 1.milliseconds) jmeScheduler <- jMESchedulerResource actorSystem <- actorSystemResource2(logger) scriptCacheActor <- new ScriptSystemResource(os.pwd, actorSystem)( timeout, actorSystem.scheduler ).make // akkaScheduler = actorSystemResource2.scheduler // consoleTextArea <- Resource.liftF(Task(new TextArea())) // consoleStream <- wireWith(JFXConsoleStream.textAreaStream _) (gameApp) <- { // new BulletAppState() // bas.setThreadingType(Thr) // gameAppResource(new StatsAppState()) wire[GameAppResource].get2 } _ <- Resource.liftF( new MainApp(logger, gameApp, actorSystem, jmeScheduler)( timeout, actorSystem.scheduler ).gameInit ) // fib <- Resource.liftF( // gameApp // .enqueueL(() => // new MainApp(logger, gameApp, actorSystem, jmeScheduler)( // timeout, // actorSystem.scheduler // ) // ) // .start // ) // _ <- Resource.liftF(fib.join.flatMap(_.gameInit) // app = gameApp // inputManager = gameApp.inputManager // assetManager = gameApp.assetManager // bulletAppState = new BulletAppState() // (playerMovementEventBus, playerCameraEventBus) <- new EventsModule2( // actorSystem // ).resource // b1 = playerMovementEventBus // b2 = playerCameraEventBus // playerPos = ImVector3f.ZERO // playerNode = None.taggedWith[Player] // modelPath = os.rel / "Models" / "Jaime" / "Jaime.j3o".taggedWith[Player] // playerController <- Resource.liftF { // implicit val s = actorSystem.scheduler // wire[PlayerController.Props].create.onErrorHandle(err => // logger.error(err.toString()) // ) // } // gameSystemsInitializerFib <- Resource.make( // logger.info("creating game systems initializer") >> // gameApp // .enqueueL(() => wire[GameSystemsInitializer]) // .start // )(c => logger.info("destroying game systems initializer") >> c.cancel) // _ <- Resource.liftF(gameSystemsInitializerFib.join.flatMap(_.init)) } yield () // def createPlayerController( // playerMovementEventBus: ActorRef[ // EventBus.Command[PlayerMovementEvent] // ], // playerCameraEventBus: ActorRef[EventBus.Command[PlayerCameraEvent]] // ): IO[PlayerController.Error, Unit] = { // val playerPos = ImVector3f.ZERO // val playerNode = None.taggedWith[Player] // val modelPath = os.rel / "Models" / "Jaime" / "Jaime.j3o" // wire[PlayerController.Props].create // } def run(args: List[String]): UIO[ExitCode] = { // Console.withOut( // new JFXConsoleStream( // new scalafx.scene.control.TextArea(), // new ByteArrayOutputStream(35) // ) // )(()) appResource .use(_ => Task.unit) .onErrorHandle(_.printStackTrace()) .as(ExitCode.Success) } }