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.

119 lines
3.9 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
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. package wow.doge.mygame
  2. import scala.concurrent.duration._
  3. import _root_.monix.bio.Task
  4. import akka.util.Timeout
  5. import cats.effect.ExitCode
  6. import cats.implicits._
  7. import com.softwaremill.macwire._
  8. import io.odin._
  9. import io.odin.json.Formatter
  10. import io.odin.syntax._
  11. import wow.doge.mygame.game.GameAppResource
  12. import wow.doge.mygame.subsystems.scriptsystem.ScriptSystemResource
  13. import _root_.monix.bio.BIOApp
  14. import _root_.monix.bio.UIO
  15. import cats.effect.Resource
  16. object Main extends BIOApp with MainModule {
  17. import java.util.logging.{Logger => JLogger, Level}
  18. JLogger.getLogger("").setLevel(Level.SEVERE)
  19. implicit val timeout = Timeout(1.second)
  20. def appResource =
  21. for {
  22. logger <-
  23. consoleLogger().withAsync(timeWindow = 1.milliseconds) |+|
  24. fileLogger(
  25. "application-log-1.log",
  26. Formatter.json
  27. ).withAsync(timeWindow = 1.milliseconds)
  28. jmeScheduler <- jMESchedulerResource
  29. actorSystem <- actorSystemResource2(logger)
  30. scriptCacheActor <- new ScriptSystemResource(os.pwd, actorSystem)(
  31. timeout,
  32. actorSystem.scheduler
  33. ).make
  34. // akkaScheduler = actorSystemResource2.scheduler
  35. // consoleTextArea <- Resource.liftF(Task(new TextArea()))
  36. // consoleStream <- wireWith(JFXConsoleStream.textAreaStream _)
  37. (gameApp) <- {
  38. // new BulletAppState()
  39. // bas.setThreadingType(Thr)
  40. // gameAppResource(new StatsAppState())
  41. wire[GameAppResource].get2
  42. }
  43. _ <- Resource.liftF(
  44. new MainApp(logger, gameApp, actorSystem, jmeScheduler)(
  45. timeout,
  46. actorSystem.scheduler
  47. ).gameInit
  48. )
  49. // fib <- Resource.liftF(
  50. // gameApp
  51. // .enqueueL(() =>
  52. // new MainApp(logger, gameApp, actorSystem, jmeScheduler)(
  53. // timeout,
  54. // actorSystem.scheduler
  55. // )
  56. // )
  57. // .start
  58. // )
  59. // _ <- Resource.liftF(fib.join.flatMap(_.gameInit)
  60. // app = gameApp
  61. // inputManager = gameApp.inputManager
  62. // assetManager = gameApp.assetManager
  63. // bulletAppState = new BulletAppState()
  64. // (playerMovementEventBus, playerCameraEventBus) <- new EventsModule2(
  65. // actorSystem
  66. // ).resource
  67. // b1 = playerMovementEventBus
  68. // b2 = playerCameraEventBus
  69. // playerPos = ImVector3f.ZERO
  70. // playerNode = None.taggedWith[Player]
  71. // modelPath = os.rel / "Models" / "Jaime" / "Jaime.j3o".taggedWith[Player]
  72. // playerController <- Resource.liftF {
  73. // implicit val s = actorSystem.scheduler
  74. // wire[PlayerController.Props].create.onErrorHandle(err =>
  75. // logger.error(err.toString())
  76. // )
  77. // }
  78. // gameSystemsInitializerFib <- Resource.make(
  79. // logger.info("creating game systems initializer") >>
  80. // gameApp
  81. // .enqueueL(() => wire[GameSystemsInitializer])
  82. // .start
  83. // )(c => logger.info("destroying game systems initializer") >> c.cancel)
  84. // _ <- Resource.liftF(gameSystemsInitializerFib.join.flatMap(_.init))
  85. } yield ()
  86. // def createPlayerController(
  87. // playerMovementEventBus: ActorRef[
  88. // EventBus.Command[PlayerMovementEvent]
  89. // ],
  90. // playerCameraEventBus: ActorRef[EventBus.Command[PlayerCameraEvent]]
  91. // ): IO[PlayerController.Error, Unit] = {
  92. // val playerPos = ImVector3f.ZERO
  93. // val playerNode = None.taggedWith[Player]
  94. // val modelPath = os.rel / "Models" / "Jaime" / "Jaime.j3o"
  95. // wire[PlayerController.Props].create
  96. // }
  97. def run(args: List[String]): UIO[ExitCode] = {
  98. // Console.withOut(
  99. // new JFXConsoleStream(
  100. // new scalafx.scene.control.TextArea(),
  101. // new ByteArrayOutputStream(35)
  102. // )
  103. // )(())
  104. appResource
  105. .use(_ => Task.unit)
  106. .onErrorHandle(_.printStackTrace())
  107. .as(ExitCode.Success)
  108. }
  109. }