Testing out JmonkeyEngine to make a game in Scala with Akka Actors within a pure FP layer
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

152 lines
5.2 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package wow.doge.mygame
  2. import cats.effect.Resource
  3. import io.odin.syntax._
  4. import cats.effect.ExitCode
  5. import cats.implicits._
  6. import com.softwaremill.macwire._
  7. import scala.concurrent.duration._
  8. import monix.bio.BIOApp
  9. import monix.bio.UIO
  10. import io.odin._
  11. import wow.doge.mygame.game.GameAppResource
  12. import io.odin.json.Formatter
  13. import wow.doge.mygame.game.GameSystemsInitializer
  14. import wow.doge.mygame.subsystems.events.EventsModule2
  15. import wow.doge.mygame.implicits._
  16. import com.jme3.bullet.BulletAppState
  17. import akka.util.Timeout
  18. import wow.doge.mygame.subsystems.scriptsystem.ScriptSystemResource
  19. import ammonite.runtime.tools.time
  20. object Main extends BIOApp with MainModule {
  21. import java.util.logging.{Logger => JLogger, Level}
  22. JLogger.getLogger("").setLevel(Level.SEVERE)
  23. implicit val timeout = Timeout(1.second)
  24. def appResource =
  25. for {
  26. logger <-
  27. consoleLogger().withAsync(timeWindow = 1.milliseconds) |+|
  28. fileLogger(
  29. "application-log-1.log",
  30. Formatter.json
  31. ).withAsync(timeWindow = 1.milliseconds)
  32. jmeScheduler <- jMESchedulerResource
  33. actorSystem <- actorSystemResource2(logger)
  34. scriptCacheActor <- new ScriptSystemResource(os.pwd, actorSystem)(
  35. timeout,
  36. actorSystem.scheduler
  37. ).make
  38. // akkaScheduler = actorSystemResource2.scheduler
  39. // consoleTextArea <- Resource.liftF(Task(new TextArea()))
  40. // consoleStream <- wireWith(JFXConsoleStream.textAreaStream _)
  41. (gameApp, gameAppFib) <- {
  42. // new BulletAppState()
  43. // bas.setThreadingType(Thr)
  44. // gameAppResource(new StatsAppState())
  45. wire[GameAppResource].get
  46. }
  47. app = gameApp
  48. inputManager = gameApp.inputManager
  49. assetManager = gameApp.assetManager
  50. bulletAppState = new BulletAppState()
  51. (playerMovementEventBus, playerCameraEventBus) <- new EventsModule2(
  52. actorSystem
  53. ).resource
  54. // b1 = playerMovementEventBus
  55. // b2 = playerCameraEventBus
  56. // playerPos = ImVector3f.ZERO
  57. // playerNode = None.taggedWith[Player]
  58. // modelPath = os.rel / "Models" / "Jaime" / "Jaime.j3o".taggedWith[Player]
  59. // playerController <- Resource.liftF {
  60. // implicit val s = actorSystem.scheduler
  61. // wire[PlayerController.Props].create.onErrorHandle(err =>
  62. // logger.error(err.toString())
  63. // )
  64. // }
  65. // _ <- Resource.liftF(IO(JMERunner.runner = gameApp))
  66. // _ <- Resource.liftF(IO {
  67. // new ActorSystemModule {}
  68. // })
  69. // actorSystem <- wireWith(actorSystemResource _)
  70. // rootActor <- rootActorResource(logger, gameApp, schedulers, as2)
  71. // _ <- Resource.liftF(
  72. // gameApp.enqueueT(actorSystem ! RootActor.Start(actorSystem.scheduler))
  73. // )
  74. // gameSystemsInitializer = new GameSystemsInitializer(
  75. // actorSystem,
  76. // logger,
  77. // playerMovementEventBus,
  78. // playerCameraEventBus
  79. // )(gameApp)
  80. gameSystemsInitializerFib <- Resource.make(
  81. logger.info("creating game systems initializer") >>
  82. gameApp
  83. .enqueueL(() => wire[GameSystemsInitializer])
  84. .start
  85. )(c => logger.info("destroying game systems initializer") >> c.cancel)
  86. _ <- Resource.liftF(gameSystemsInitializerFib.join.flatMap(_.init))
  87. // .runAsync {
  88. // case Left(err) => println(err)
  89. // case _ =>
  90. // }(schedulers.async)
  91. // _ <- Resource.liftF {
  92. // Task {
  93. // implicit val sched = actorSystem.scheduler
  94. // implicit val timeout = Timeout(2.seconds)
  95. // // val module = new EventsModule {}
  96. // }
  97. // }
  98. // actorSystem <- wireWith(actorSystemResource2 _)
  99. // (tickEventBus, playerMovementEventBus) <- wireWith(eventBusesResource _)
  100. // rootActor <- wireWith(rootActorResource _)
  101. // inputSystemHandler <- {
  102. // inputHandlerSystemResource(
  103. // GameInputHandler.Props(gameApp.inputManager, playerMovementEventBus)
  104. // )
  105. // }
  106. // gameSystemsInitializer <-
  107. // gameSystemsResource(actorSystem, inputSystemHandler)
  108. // _ <- Resource.liftF(
  109. // gameApp.enqueueT(rootActor ! RootActor.Start(actorSystem.scheduler))
  110. // )
  111. // _ <- Resource.liftF {
  112. // IO(gameApp.start())
  113. // .executeOn(jmeScheduler)
  114. // }
  115. // (_ => IO(gameApp.stop(() => actorSystem ! RootActor.Stop)))
  116. } yield (gameAppFib)
  117. // def createPlayerController(
  118. // playerMovementEventBus: ActorRef[
  119. // EventBus.Command[PlayerMovementEvent]
  120. // ],
  121. // playerCameraEventBus: ActorRef[EventBus.Command[PlayerCameraEvent]]
  122. // ): IO[PlayerController.Error, Unit] = {
  123. // val playerPos = ImVector3f.ZERO
  124. // val playerNode = None.taggedWith[Player]
  125. // val modelPath = os.rel / "Models" / "Jaime" / "Jaime.j3o"
  126. // wire[PlayerController.Props].create
  127. // }
  128. def run(args: List[String]): UIO[ExitCode] = {
  129. // Console.withOut(
  130. // new JFXConsoleStream(
  131. // new scalafx.scene.control.TextArea(),
  132. // new ByteArrayOutputStream(35)
  133. // )
  134. // )(())
  135. appResource
  136. .use(_.join)
  137. .onErrorHandle(_.printStackTrace())
  138. .as(ExitCode.Success)
  139. }
  140. }