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.

136 lines
3.3 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
  1. package wow.doge.mygame.game
  2. import akka.actor.typed.ActorRef
  3. import akka.actor.typed.Scheduler
  4. import akka.actor.typed.SpawnProtocol
  5. import akka.actor.typed.scaladsl.Behaviors
  6. import io.odin.Logger
  7. import monix.bio.Task
  8. import wow.doge.mygame.events.Events
  9. import wow.doge.mygame.executors.Schedulers
  10. object GameAppActor {
  11. sealed trait Command
  12. case object ApplicationStarted extends Command
  13. case class ApplicationStartFailed(reason: String) extends Command
  14. case object Stop extends Command
  15. case class Props(
  16. app: GameApp,
  17. akkaScheduler: Scheduler,
  18. schedulers: Schedulers,
  19. spawnProtocol: ActorRef[SpawnProtocol.Command],
  20. loggerL: Logger[Task]
  21. ) {
  22. def create =
  23. Behaviors.setup[Command] { ctx =>
  24. ctx.log.info("Hello from GameAppActor")
  25. Behaviors.receiveMessage { msg =>
  26. msg match {
  27. case Stop =>
  28. ctx.log.info("Received stop")
  29. Behaviors.stopped
  30. case ApplicationStarted =>
  31. ctx.log.info("Application started")
  32. Behaviors.same
  33. case ApplicationStartFailed(reason) =>
  34. ctx.log.error(
  35. s"Failed to start application - $reason"
  36. )
  37. Behaviors.stopped
  38. }
  39. }
  40. }
  41. }
  42. }
  43. object SubscribingActor {
  44. def apply() =
  45. Behaviors.receive[Events.Tick.PhysicsTick.type] { (ctx, msg) =>
  46. ctx.log.debug(s"received event $msg")
  47. Behaviors.same
  48. }
  49. }
  50. object Methods {
  51. def old() = {
  52. // val movementActor =
  53. // ctx.spawn(
  54. // MovementActor(MovementActor.Props(app, geom)),
  55. // "movementActor"
  56. // // DispatcherSelector.fromConfig("jme-dispatcher")
  57. // )
  58. // val movementActorTimer = ctx.spawn(
  59. // MovementActorTimer(movementActor),
  60. // "movementActorTimer"
  61. // )
  62. }
  63. def old2() = {
  64. // ctx.log.info("here")
  65. // {
  66. // implicit val s = schedulers.async
  67. // Task
  68. // .parZip2(
  69. // loggerL.info("Test").executeOn(app.scheduler),
  70. // app
  71. // .enqueueL(() => loggerL.info("here 2").executeOn(app.scheduler))
  72. // .flatten
  73. // )
  74. // .runToFuture
  75. // }
  76. // app
  77. // .getRootNode()
  78. // .depthFirst(s =>
  79. // // s match {
  80. // // case node: Node =>
  81. // // println("node" + s.getName() + " children " + node.getChildren())
  82. // // case g: Geometry => println(s.getName())
  83. // // }
  84. // println(s.getName())
  85. // )
  86. // println("----------------")
  87. // {
  88. // app
  89. // .getRootNode()
  90. // .observableDepthFirst()
  91. // .map(s => s.getName())
  92. // // .takeWhileInclusive(_.getName() != "level")
  93. // .onErrorHandle(e => e.getMessage())
  94. // .foreach(println)(schedulers.async)
  95. // }
  96. // println("----------------")
  97. // {
  98. // app
  99. // .getRootNode()
  100. // .observableBreadthFirst()
  101. // .map(s => s.getName())
  102. // // .takeWhileInclusive(_.getName() != "level")
  103. // .onErrorHandle(e => e.getMessage())
  104. // .foreach(println)(schedulers.async)
  105. // }
  106. // app.start()
  107. // Behaviors.same
  108. }
  109. }
  110. // new PlayerMovementState(
  111. // // movementActor,
  112. // // movementActorTimer,
  113. // imMovementActor,
  114. // // geom,
  115. // // camNode,
  116. // playerNode
  117. // // ctx.self
  118. // )