package wow.doge.mygame import cats.effect.Resource import io.odin.syntax._ import cats.effect.ExitCode import cats.implicits._ import com.softwaremill.macwire._ import scala.concurrent.duration._ import monix.bio.BIOApp import monix.bio.UIO import io.odin._ import wow.doge.mygame.game.GameAppResource import io.odin.json.Formatter import wow.doge.mygame.game.GameSystemsInitializer import wow.doge.mygame.subsystems.events.EventsModule2 import wow.doge.mygame.implicits._ import com.jme3.bullet.BulletAppState import akka.util.Timeout import wow.doge.mygame.subsystems.scriptsystem.ScriptSystemResource import ammonite.runtime.tools.time 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, gameAppFib) <- { // new BulletAppState() // bas.setThreadingType(Thr) // gameAppResource(new StatsAppState()) wire[GameAppResource].get } 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()) // ) // } // _ <- Resource.liftF(IO(JMERunner.runner = gameApp)) // _ <- Resource.liftF(IO { // new ActorSystemModule {} // }) // actorSystem <- wireWith(actorSystemResource _) // rootActor <- rootActorResource(logger, gameApp, schedulers, as2) // _ <- Resource.liftF( // gameApp.enqueueT(actorSystem ! RootActor.Start(actorSystem.scheduler)) // ) // gameSystemsInitializer = new GameSystemsInitializer( // actorSystem, // logger, // playerMovementEventBus, // playerCameraEventBus // )(gameApp) 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)) // .runAsync { // case Left(err) => println(err) // case _ => // }(schedulers.async) // _ <- Resource.liftF { // Task { // implicit val sched = actorSystem.scheduler // implicit val timeout = Timeout(2.seconds) // // val module = new EventsModule {} // } // } // actorSystem <- wireWith(actorSystemResource2 _) // (tickEventBus, playerMovementEventBus) <- wireWith(eventBusesResource _) // rootActor <- wireWith(rootActorResource _) // inputSystemHandler <- { // inputHandlerSystemResource( // GameInputHandler.Props(gameApp.inputManager, playerMovementEventBus) // ) // } // gameSystemsInitializer <- // gameSystemsResource(actorSystem, inputSystemHandler) // _ <- Resource.liftF( // gameApp.enqueueT(rootActor ! RootActor.Start(actorSystem.scheduler)) // ) // _ <- Resource.liftF { // IO(gameApp.start()) // .executeOn(jmeScheduler) // } // (_ => IO(gameApp.stop(() => actorSystem ! RootActor.Stop))) } yield (gameAppFib) // 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(_.join) .onErrorHandle(_.printStackTrace()) .as(ExitCode.Success) } }