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.

109 lines
3.1 KiB

4 years ago
  1. package wow.doge.mygame.game
  2. import com.jme3.app.SimpleApplication
  3. import com.jme3.app.state.AppState
  4. import akka.actor.typed.ActorRef
  5. import akka.actor.typed.Behavior
  6. import akka.actor.typed.scaladsl.Behaviors
  7. object Greeter {
  8. final case class Greet(whom: String, replyTo: ActorRef[Greeted])
  9. final case class Greeted(whom: String, from: ActorRef[Greet])
  10. def apply(): Behavior[Greet] =
  11. Behaviors.receive { (context, message) =>
  12. // context.log.info("Hello {}!", message.whom)
  13. //#greeter-send-messages
  14. message.replyTo ! Greeted(message.whom, context.self)
  15. //#greeter-send-messages
  16. Behaviors.same
  17. }
  18. }
  19. class GameApp(
  20. // actorSystem: ActorSystem[SpawnProtocol.Command],
  21. appStates: AppState*
  22. ) extends SimpleApplication(appStates: _*) {
  23. // implicit val timeout = Timeout(10.seconds)
  24. // implicit val scheduler = actorSystem.scheduler
  25. override def simpleInitApp(): Unit = {
  26. // val ship = ed.createEntity()
  27. // val mbState = stateManager().state[EntityDataState]().map(_.getEntityData())
  28. // val mbState = Try(
  29. // stateManager()
  30. // .state[TestAppState]()
  31. // .entity
  32. // ).toOption.flatten.toRight(println("empty"))
  33. // // .flatMap(_.entity)
  34. // val x = mbState.flatMap(
  35. // _.query
  36. // .filter[TestComponent]("name", new Object())
  37. // // .filterOr[TestEntity](
  38. // // Filters
  39. // // .fieldEquals(classOf[TestEntity], "", null)
  40. // // )
  41. // .component[Tag]()
  42. // .component[TestComponent]()
  43. // .result
  44. // .toRight(println("failed"))
  45. // )
  46. // rootNode
  47. // .child(geom)
  48. // .child(geom)
  49. // .child(geom)
  50. // .child(geom)
  51. // .child(geom)
  52. // .child(geom)
  53. // .child(geom)
  54. // .child(geom)
  55. // Future(println("hello"))(jmeEC(this))
  56. // val wbActor: Future[ActorRef[Greeter.Greet]] = actorSystem.ask(
  57. // SpawnProtocol.Spawn(
  58. // behavior = Greeter(),
  59. // name = "listener",
  60. // DispatcherSelector.fromConfig("jme-dispatcher"),
  61. // _
  62. // )
  63. // )
  64. // wbActor.map(a => a.ask(Greeter.Greet("hello", _)).map(println))
  65. }
  66. override def simpleUpdate(tpf: Float): Unit = {
  67. // val rot2 = rot.fromAngleAxis(FastMath.PI, new Vector3f(0, 0, 1))
  68. // val rotation = geom.getLocalRotation()
  69. // rotation.add(rot2)
  70. // geom.rotate(rot2)
  71. // geom.updateModelBound()
  72. // geom.updateGeometricState()
  73. }
  74. // override def stop(): Unit = {
  75. // actorSystem.terminate()
  76. // super.stop()
  77. // }
  78. }
  79. object GameApp {
  80. // def myExec(app: SimpleApplication, command: Runnable) = {
  81. // app.enqueue(command)
  82. // }
  83. // val javaFxExecutionContext: ExecutionContext =
  84. // ExecutionContext.fromExecutor(new Executor {
  85. // def execute(command: Runnable): Unit = {
  86. // Platform.runLater(command)
  87. // }
  88. // })
  89. // def jmeEC(app: SimpleApplication): ExecutionContext =
  90. // ExecutionContext.fromExecutor(new Executor {
  91. // override def execute(command: Runnable): Unit = app.enqueue(command)
  92. // })
  93. // def jmeScheduler(app: SimpleApplication) = Sch
  94. }