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.

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