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.
106 lines
3.4 KiB
106 lines
3.4 KiB
package wow.doge.mygame.game
|
|
|
|
import scala.concurrent.duration._
|
|
|
|
import akka.actor.typed.ActorRef
|
|
import akka.actor.typed.ActorSystem
|
|
import akka.actor.typed.Scheduler
|
|
import akka.actor.typed.SpawnProtocol
|
|
import akka.util.Timeout
|
|
import cats.effect.concurrent.Ref
|
|
import com.jme3.app.state.AppStateManager
|
|
import com.jme3.asset.AssetManager
|
|
import com.jme3.asset.plugins.ZipLocator
|
|
import com.jme3.bullet.BulletAppState
|
|
import com.jme3.input.InputManager
|
|
import com.jme3.renderer.Camera
|
|
import com.jme3.scene.Node
|
|
import com.softwaremill.macwire._
|
|
import com.softwaremill.tagging._
|
|
import io.odin.Logger
|
|
import monix.bio.IO
|
|
import monix.bio.Task
|
|
import monix.reactive.Consumer
|
|
import wow.doge.mygame.events.EventBus
|
|
import wow.doge.mygame.game.nodes.PlayerTag
|
|
import wow.doge.mygame.game.nodes.PlayerController
|
|
import wow.doge.mygame.game.subsystems.input.GameInputHandler
|
|
import wow.doge.mygame.implicits._
|
|
import wow.doge.mygame.math.ImVector3f
|
|
import wow.doge.mygame.subsystems.events.EntityMovementEvent
|
|
import wow.doge.mygame.subsystems.events.PlayerCameraEvent
|
|
import wow.doge.mygame.subsystems.movement.ImMovementActor
|
|
import wow.doge.mygame.utils.IOUtils
|
|
|
|
class GameSystemsInitializer(
|
|
spawnProtocol: ActorSystem[SpawnProtocol.Command],
|
|
loggerL: Logger[Task],
|
|
// eventBuses: EventsModule2
|
|
playerMovementEventBus: ActorRef[
|
|
EventBus.Command[EntityMovementEvent.PlayerMovementEvent]
|
|
],
|
|
playerCameraEventBus: ActorRef[EventBus.Command[PlayerCameraEvent]],
|
|
inputManager: InputManager,
|
|
assetManager: AssetManager,
|
|
stateManager: AppStateManager,
|
|
camera: Camera,
|
|
enqueueR: Function1[() => Unit, Unit],
|
|
appScheduler: monix.execution.Scheduler,
|
|
rootNode: Ref[Task, Node]
|
|
) {
|
|
implicit val timeout: Timeout = Timeout(1.second)
|
|
|
|
import GameSystemsInitializer._
|
|
|
|
implicit val akkaScheduler: Scheduler = spawnProtocol.scheduler
|
|
// lazy val inputManager = app.inputManager
|
|
// lazy val assetManager = app.assetManager
|
|
lazy val bulletAppState = new BulletAppState()
|
|
// lazy val playerMovementEventBus = eventBuses.playerMovementEventBusTask
|
|
|
|
val init =
|
|
for {
|
|
_ <- loggerL.info("Initializing Systems")
|
|
// playerMovementEventBus <- playerMovementEventBusTask
|
|
_ <- Task(stateManager.attach(bulletAppState))
|
|
_ <- Task(
|
|
assetManager.registerLocator(
|
|
// "src/main/resources/assets/town.zip",
|
|
(os.rel / "assets" / "town.zip"),
|
|
classOf[ZipLocator]
|
|
)
|
|
)
|
|
|
|
// _ <- app.enqueueL(() => DefaultGameLevel(app, bulletAppState))
|
|
_ <- wireWith(createPlayerController _).startAndForget
|
|
_ <- wire[GameInputHandler.Props].begin
|
|
|
|
} yield ()
|
|
|
|
def createPlayerController(
|
|
// playerMovementEventBus: ActorRef[
|
|
// EventBus.Command[PlayerMovementEvent]
|
|
// ],
|
|
// playerCameraEventBus: ActorRef[EventBus.Command[PlayerCameraEvent]]
|
|
): IO[PlayerController.Error, Unit] = {
|
|
@annotation.unused
|
|
val playerPos = ImVector3f.ZERO
|
|
@annotation.unused
|
|
val playerNode = None.taggedWith[PlayerTag]
|
|
@annotation.unused
|
|
val modelPath = os.rel / "Models" / "Jaime" / "Jaime.j3o"
|
|
wire[PlayerController.Props].create
|
|
}
|
|
}
|
|
|
|
object GameSystemsInitializer {
|
|
|
|
def playerMovementActorTickConsumer(
|
|
playerMovementActor: ActorRef[ImMovementActor.Command]
|
|
) =
|
|
Consumer
|
|
.foreachTask[Float](tpf =>
|
|
IOUtils.toTask(playerMovementActor !! ImMovementActor.Tick)
|
|
)
|
|
// .mapTask()
|
|
}
|