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.

65 lines
2.0 KiB

4 years ago
3 years ago
4 years ago
3 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
3 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
3 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
  1. package wow.doge.mygame
  2. import scala.concurrent.duration._
  3. import _root_.monix.bio.BIOApp
  4. import _root_.monix.bio.Task
  5. import _root_.monix.bio.UIO
  6. import _root_.monix.execution.Scheduler
  7. import akka.util.Timeout
  8. import cats.effect.ExitCode
  9. import cats.effect.Resource
  10. import cats.implicits._
  11. import io.odin._
  12. import io.odin.json.Formatter
  13. import io.odin.syntax._
  14. import scalafx.scene.control.TextArea
  15. import wow.doge.mygame.ActorSystemResource
  16. import wow.doge.mygame.executors.ExecutorsModule
  17. import wow.doge.mygame.types.AkkaScheduler
  18. import wow.doge.mygame.utils.GenericConsoleStream
  19. object Main extends BIOApp with ExecutorsModule {
  20. import java.util.logging.{Logger => JLogger, Level}
  21. JLogger.getLogger("").setLevel(Level.SEVERE)
  22. implicit val timeout = Timeout(1.second)
  23. override def scheduler: Scheduler = schedulers.async.value
  24. def appResource(consoleStream: GenericConsoleStream[TextArea]) =
  25. for {
  26. logger <-
  27. consoleLogger().withAsync(
  28. timeWindow = 1.milliseconds,
  29. maxBufferSize = Some(100)
  30. ) |+|
  31. fileLogger(
  32. "application-log-1.log",
  33. Formatter.json
  34. ).withAsync(timeWindow = 1.milliseconds, maxBufferSize = Some(2000))
  35. jmeScheduler <- jmeSchedulerResource
  36. // backend <- Resource.make(toIO(HttpClientMonixBackend()))(backend =>
  37. // toIO(backend.close())
  38. // )
  39. actorSystem <- new ActorSystemResource(logger, schedulers.async).get
  40. _ <- Resource.liftF(
  41. new MainApp(
  42. logger,
  43. jmeScheduler,
  44. schedulers,
  45. consoleStream
  46. )(actorSystem, timeout, AkkaScheduler(actorSystem.scheduler)).program
  47. )
  48. } yield ()
  49. def run(args: List[String]): UIO[ExitCode] = {
  50. val consoleStream = GenericConsoleStream.textAreaStream()
  51. Console.withOut(consoleStream)(
  52. appResource(consoleStream)
  53. .use(_ => Task.unit)
  54. .flatMap(_ => Task(consoleStream.close()))
  55. .onErrorHandleWith(ex => UIO(ex.printStackTrace()))
  56. .as(ExitCode.Success)
  57. )
  58. }
  59. }