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.

105 lines
3.0 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
  1. package wow.doge.mygame
  2. import com.jme3.app.StatsAppState
  3. import monix.bio.Task
  4. import cats.effect.Resource
  5. import io.odin.syntax._
  6. // import io.odin.monix._
  7. import cats.effect.ExitCode
  8. import cats.implicits._
  9. import com.softwaremill.macwire._
  10. import scala.concurrent.duration._
  11. import monix.bio.BIOApp
  12. import monix.bio.UIO
  13. import monix.bio.IO
  14. import io.odin._
  15. import wow.doge.mygame.executors.JMERunner
  16. import com.jme3.bullet.BulletAppState
  17. import wow.doge.mygame.implicits._
  18. // import wow.doge.mygame.implicits._
  19. // object Main extends App {
  20. // import java.util.logging.{Logger, Level}
  21. // Logger.getLogger("").setLevel(Level.SEVERE)
  22. // // runner.runCode("""|println("starting scala script engine")""".stripMargin)
  23. // val gameApp = new GameApp(
  24. // // new EntityDataState(),
  25. // // new TestAppState(),
  26. // // new PlayerMovementState(),
  27. // // new FlyCamAppState(),
  28. // new StatsAppState()
  29. // )
  30. // val settings = new AppSettings(true)
  31. // // settings.setVSync(true)
  32. // settings.setFrameRate(144)
  33. // gameApp.setSettings(settings)
  34. // val actorSystem = ActorSystem(RootActor(gameApp), "rootActor")
  35. // // actorSystem.eventStream
  36. // // gameApp.start()
  37. // println("here 1")
  38. // // actorSystem.terminate()
  39. // // JMEExecutorService.shutdown()
  40. // // println("here 2")
  41. // //FIXME remove this
  42. // // System.exit(0)
  43. // }
  44. object Main extends BIOApp with MainModule {
  45. import java.util.logging.{Logger => JLogger, Level}
  46. JLogger.getLogger("").setLevel(Level.SEVERE)
  47. def run(args: List[String]): UIO[ExitCode] = {
  48. lazy val appResource = for {
  49. logger <-
  50. consoleLogger().withAsync(timeWindow = 1.seconds) |+| fileLogger(
  51. "log.log"
  52. ).withAsync(timeWindow = 1.seconds)
  53. jmeScheduler <- jMESchedulerResource
  54. // consoleTextArea <- Resource.liftF(Task(new TextArea()))
  55. // consoleStream <- wireWith(JFXConsoleStream.textAreaStream _)
  56. gameApp <- {
  57. new BulletAppState()
  58. // bas.setThreadingType(Thr)
  59. gameAppResource(new StatsAppState())
  60. }
  61. _ <- Resource.liftF(IO(JMERunner.runner = gameApp))
  62. actorSystem <- wireWith(actorSystemResource _)
  63. // _ <- Resource.liftF(
  64. // Task(gameApp.start()).asyncBoundary
  65. // .executeOn(Scheduler(JMEExecutorService))
  66. // )
  67. _ <- Resource.liftF(gameApp.enqueueT(actorSystem ! RootActor.Start))
  68. _ <- Resource.liftF {
  69. IO(gameApp.start())
  70. .executeOn(jmeScheduler)
  71. }
  72. // (_ => IO(gameApp.stop(() => actorSystem ! RootActor.Stop)))
  73. } yield ()
  74. // Console.withOut(
  75. // new JFXConsoleStream(
  76. // new scalafx.scene.control.TextArea(),
  77. // new ByteArrayOutputStream(35)
  78. // )
  79. // )(())
  80. appResource
  81. .use(_ =>
  82. // Task(gameApp.start())
  83. // .executeOn(Scheduler(JMEExecutorService))
  84. // .asyncBoundary
  85. // Task.never
  86. Task.unit
  87. // >>
  88. // .executeOn(Scheduler(JMEExecutorService))
  89. )
  90. .onErrorHandle(_.printStackTrace())
  91. .as(ExitCode.Success)
  92. }
  93. }