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

package wow.doge.mygame.game
import akka.actor.typed.scaladsl.Behaviors
import com.jme3.scene.Geometry
import wow.doge.mygame.events.Events
import com.jme3.scene.CameraNode
import com.jme3.scene.Node
import com.jme3.renderer.Camera
import wow.doge.mygame.executors.Schedulers
import com.softwaremill.macwire._
import wow.doge.mygame.implicits._
import akka.actor.typed.SpawnProtocol
import akka.actor.typed.ActorRef
import io.odin.Logger
import monix.bio.Task
import akka.actor.typed.Scheduler
import scala.util.Failure
import scala.util.Success
import com.jme3.app.StatsAppState
object GameAppActor {
import Methods._
sealed trait Command
case object ApplicationStarted extends Command
case class ApplicationStartFailed(reason: String) extends Command
case object Stop extends Command
case class Props(
app: GameApp,
akkaScheduler: Scheduler,
schedulers: Schedulers,
spawnProtocol: ActorRef[SpawnProtocol.Command],
loggerL: Logger[Task]
) {
def create =
Behaviors.setup[Command] { ctx =>
ctx.log.info("Hello from GameAppActor")
// {
// implicit val s = schedulers.async
// val initializer: GameSystemsInitializer = wire[GameSystemsInitializer]
// schedulers.async.execute(() => initializer.init.runAsyncAndForget)
// // ctx.pipeToSelf(application.timed.runToFuture) {
// // case Failure(exception) =>
// // ApplicationStartFailed(exception.getMessage())
// // case Success(value) =>
// // println("here applications started")
// // ApplicationStarted
// // }
// }
Behaviors.receiveMessage { msg =>
msg match {
case Stop =>
ctx.log.info("Received stop")
Behaviors.stopped
case ApplicationStarted =>
ctx.log.info("Application started")
Behaviors.same
case ApplicationStartFailed(reason) =>
ctx.log.error(
s"Failed to start application - $reason"
)
Behaviors.stopped
}
}
}
}
}
object SubscribingActor {
def apply() =
Behaviors.receive[Events.Tick.PhysicsTick.type] { (ctx, msg) =>
ctx.log.debug(s"received event $msg")
Behaviors.same
}
}
object Methods {
def old() = {
// val movementActor =
// ctx.spawn(
// MovementActor(MovementActor.Props(app, geom)),
// "movementActor"
// // DispatcherSelector.fromConfig("jme-dispatcher")
// )
// val movementActorTimer = ctx.spawn(
// MovementActorTimer(movementActor),
// "movementActorTimer"
// )
}
def old2() = {
// ctx.log.info("here")
// {
// implicit val s = schedulers.async
// Task
// .parZip2(
// loggerL.info("Test").executeOn(app.scheduler),
// app
// .enqueueL(() => loggerL.info("here 2").executeOn(app.scheduler))
// .flatten
// )
// .runToFuture
// }
// app
// .getRootNode()
// .depthFirst(s =>
// // s match {
// // case node: Node =>
// // println("node" + s.getName() + " children " + node.getChildren())
// // case g: Geometry => println(s.getName())
// // }
// println(s.getName())
// )
// println("----------------")
// {
// app
// .getRootNode()
// .observableDepthFirst()
// .map(s => s.getName())
// // .takeWhileInclusive(_.getName() != "level")
// .onErrorHandle(e => e.getMessage())
// .foreach(println)(schedulers.async)
// }
// println("----------------")
// {
// app
// .getRootNode()
// .observableBreadthFirst()
// .map(s => s.getName())
// // .takeWhileInclusive(_.getName() != "level")
// .onErrorHandle(e => e.getMessage())
// .foreach(println)(schedulers.async)
// }
// app.start()
// Behaviors.same
}
}
// new PlayerMovementState(
// // movementActor,
// // movementActorTimer,
// imMovementActor,
// // geom,
// // camNode,
// playerNode
// // ctx.self
// )