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.

81 lines
2.4 KiB

3 years ago
  1. package wow.doge.mygame.actor
  2. import akka.actor.typed.ActorRef
  3. import akka.actor.typed.SpawnProtocol
  4. import akka.actor.typed.scaladsl.ActorContext
  5. import akka.actor.typed.scaladsl.Behaviors
  6. import wow.doge.mygame.implicits._
  7. // import wow.doge.mygame.subsystems.events.EventsModule.GameEventBus
  8. // import wow.doge.mygame.subsystems.events.Event
  9. // import scala.reflect.ClassTag
  10. // import akka.actor.typed.LogOptions
  11. // import wow.doge.mygame.subsystems.events.EventBus
  12. // import scala.concurrent.duration._
  13. // import akka.util.Timeout
  14. // import akka.actor.typed.SupervisorStrategy
  15. object GameActorSystem {
  16. sealed trait Command
  17. case class GetSpawnProtocol(
  18. replyTo: ActorRef[ActorRef[SpawnProtocol.Command]]
  19. ) extends Command
  20. class Props() {
  21. def create =
  22. Behaviors.setup[Command] { ctx =>
  23. val systemSpawnProtocol = ctx.spawnN(SpawnProtocol())
  24. new GameActorSystem(ctx, this, systemSpawnProtocol).receive
  25. }
  26. }
  27. }
  28. class GameActorSystem(
  29. ctx: ActorContext[GameActorSystem.Command],
  30. props: GameActorSystem.Props,
  31. sp: ActorRef[SpawnProtocol.Command]
  32. ) {
  33. import GameActorSystem._
  34. def receive =
  35. Behaviors.receiveMessage[Command] {
  36. case GetSpawnProtocol(replyTo) =>
  37. replyTo ! sp
  38. Behaviors.same
  39. }
  40. }
  41. // object EventBusSupervisor {
  42. // sealed trait Command
  43. // case class GetMainEventBus(replyTo: ActorRef[GameEventBus[Event]])
  44. // extends Command
  45. // case class GetEventBus[T](replyTo: ActorRef[GameEventBus[T]])(implicit
  46. // classTag: ClassTag[T]
  47. // ) extends Command {
  48. // def ct = classTag
  49. // }
  50. // class Props(val spawnProtocol: ActorRef[SpawnProtocol.Command]) {
  51. // def create =
  52. // Behaviors.setup[Command] { ctx =>
  53. // new EventBusSupervisor(ctx, this).receive
  54. // }
  55. // }
  56. // }
  57. // class EventBusSupervisor(
  58. // ctx: ActorContext[EventBusSupervisor.Command],
  59. // props: EventBusSupervisor.Props
  60. // ) {
  61. // import EventBusSupervisor._
  62. // implicit val timeout = Timeout(1.second)
  63. // implicit val sp = props.spawnProtocol
  64. // def receive =
  65. // Behaviors.receiveMessage[Command] {
  66. // case g @ GetEventBus(replyTo) =>
  67. // implicit val ct = g.ct
  68. // Behaviors
  69. // .supervise(EventBus())
  70. // .onFailure[Exception](
  71. // SupervisorStrategy.restart.withLimit(2, 100.millis)
  72. // )
  73. // Behaviors.same
  74. // case _ => Behaviors.same
  75. // }
  76. // }