|
@ -1,5 +1,6 @@ |
|
|
package wow.doge.mygame |
|
|
package wow.doge.mygame |
|
|
|
|
|
|
|
|
|
|
|
import akka.actor.typed.ActorRef |
|
|
import akka.actor.typed.ActorSystem |
|
|
import akka.actor.typed.ActorSystem |
|
|
import akka.actor.typed.Scheduler |
|
|
import akka.actor.typed.Scheduler |
|
|
import akka.actor.typed.SpawnProtocol |
|
|
import akka.actor.typed.SpawnProtocol |
|
@ -8,10 +9,12 @@ import cats.effect.Resource |
|
|
import cats.effect.concurrent.Deferred |
|
|
import cats.effect.concurrent.Deferred |
|
|
import cats.syntax.eq._ |
|
|
import cats.syntax.eq._ |
|
|
import com.jme3.app.state.AppStateManager |
|
|
import com.jme3.app.state.AppStateManager |
|
|
import com.jme3.asset.AssetManager |
|
|
|
|
|
import com.jme3.asset.plugins.ZipLocator |
|
|
import com.jme3.asset.plugins.ZipLocator |
|
|
import com.jme3.bullet.control.BetterCharacterControl |
|
|
import com.jme3.bullet.control.BetterCharacterControl |
|
|
import com.jme3.input.InputManager |
|
|
import com.jme3.input.InputManager |
|
|
|
|
|
import com.jme3.material.Material |
|
|
|
|
|
import com.jme3.material.MaterialDef |
|
|
|
|
|
import com.jme3.math.FastMath |
|
|
import com.jme3.renderer.Camera |
|
|
import com.jme3.renderer.Camera |
|
|
import com.jme3.renderer.RenderManager |
|
|
import com.jme3.renderer.RenderManager |
|
|
import com.jme3.renderer.ViewPort |
|
|
import com.jme3.renderer.ViewPort |
|
@ -23,18 +26,21 @@ import io.odin.Logger |
|
|
import monix.bio.Fiber |
|
|
import monix.bio.Fiber |
|
|
import monix.bio.IO |
|
|
import monix.bio.IO |
|
|
import monix.bio.Task |
|
|
import monix.bio.Task |
|
|
import monix.execution.exceptions.DummyException |
|
|
|
|
|
|
|
|
import monix.bio.UIO |
|
|
import scalafx.scene.control.TextArea |
|
|
import scalafx.scene.control.TextArea |
|
|
import wow.doge.mygame.executors.Schedulers |
|
|
import wow.doge.mygame.executors.Schedulers |
|
|
import wow.doge.mygame.game.GameApp |
|
|
import wow.doge.mygame.game.GameApp |
|
|
import wow.doge.mygame.game.GameAppActor |
|
|
import wow.doge.mygame.game.GameAppActor |
|
|
|
|
|
import wow.doge.mygame.game.GameAppResource |
|
|
import wow.doge.mygame.game.GameAppTags |
|
|
import wow.doge.mygame.game.GameAppTags |
|
|
import wow.doge.mygame.game.entities.EntityIds |
|
|
import wow.doge.mygame.game.entities.EntityIds |
|
|
import wow.doge.mygame.game.entities.NpcActorSupervisor |
|
|
import wow.doge.mygame.game.entities.NpcActorSupervisor |
|
|
import wow.doge.mygame.game.entities.NpcMovementActor |
|
|
import wow.doge.mygame.game.entities.NpcMovementActor |
|
|
|
|
|
import wow.doge.mygame.game.entities.PlayerActorSupervisor |
|
|
import wow.doge.mygame.game.entities.PlayerController |
|
|
import wow.doge.mygame.game.entities.PlayerController |
|
|
import wow.doge.mygame.game.entities.PlayerControllerTags |
|
|
import wow.doge.mygame.game.entities.PlayerControllerTags |
|
|
import wow.doge.mygame.game.subsystems.input.GameInputHandler |
|
|
import wow.doge.mygame.game.subsystems.input.GameInputHandler |
|
|
|
|
|
import wow.doge.mygame.game.subsystems.level.DefaultGameLevel |
|
|
import wow.doge.mygame.implicits._ |
|
|
import wow.doge.mygame.implicits._ |
|
|
import wow.doge.mygame.launcher.Launcher |
|
|
import wow.doge.mygame.launcher.Launcher |
|
|
import wow.doge.mygame.launcher.Launcher.LauncherResult |
|
|
import wow.doge.mygame.launcher.Launcher.LauncherResult |
|
@ -48,8 +54,14 @@ import wow.doge.mygame.subsystems.scriptsystem.ScriptSystemResource |
|
|
import wow.doge.mygame.utils.AkkaUtils |
|
|
import wow.doge.mygame.utils.AkkaUtils |
|
|
import wow.doge.mygame.utils.GenericConsoleStream |
|
|
import wow.doge.mygame.utils.GenericConsoleStream |
|
|
import wow.doge.mygame.utils.wrappers.jme.AppNode |
|
|
import wow.doge.mygame.utils.wrappers.jme.AppNode |
|
|
import wow.doge.mygame.game.subsystems.level.DefaultGameLevel |
|
|
|
|
|
import com.jme3.math.FastMath |
|
|
|
|
|
|
|
|
import wow.doge.mygame.utils.wrappers.jme.AssetManager |
|
|
|
|
|
import wow.doge.mygame.utils.wrappers.jme.PhysicsSpace |
|
|
|
|
|
import wow.doge.mygame.subsystems.events.EventBus.ObservableSubscription |
|
|
|
|
|
import wow.doge.mygame.subsystems.events.PlayerMovementEvent |
|
|
|
|
|
import monix.reactive.Observable |
|
|
|
|
|
import monix.eval.Coeval |
|
|
|
|
|
import wow.doge.mygame.utils.IOUtils |
|
|
|
|
|
import com.jme3.math.ColorRGBA |
|
|
|
|
|
|
|
|
class MainApp( |
|
|
class MainApp( |
|
|
logger: Logger[Task], |
|
|
logger: Logger[Task], |
|
@ -57,37 +69,52 @@ class MainApp( |
|
|
schedulers: Schedulers, |
|
|
schedulers: Schedulers, |
|
|
consoleStream: GenericConsoleStream[TextArea] |
|
|
consoleStream: GenericConsoleStream[TextArea] |
|
|
)(implicit |
|
|
)(implicit |
|
|
spawnProtocol: ActorSystem[SpawnProtocol.Command], |
|
|
|
|
|
@annotation.unused timeout: Timeout, |
|
|
|
|
|
@annotation.unused scheduler: Scheduler |
|
|
|
|
|
|
|
|
spawnProtocol: ActorRef[SpawnProtocol.Command], |
|
|
|
|
|
timeout: Timeout, |
|
|
|
|
|
scheduler: Scheduler |
|
|
) { |
|
|
) { |
|
|
|
|
|
|
|
|
val scriptSystemInit = |
|
|
val scriptSystemInit = |
|
|
new ScriptSystemResource(os.pwd, ScriptInitMode.Eager).init |
|
|
new ScriptSystemResource(os.pwd, ScriptInitMode.Eager).init |
|
|
|
|
|
|
|
|
val eventsModule = new EventsModule(spawnProtocol) |
|
|
|
|
|
|
|
|
val eventsModule = new EventsModule(scheduler, spawnProtocol) |
|
|
|
|
|
|
|
|
|
|
|
class TestClass( |
|
|
|
|
|
playerEventBus: GameEventBus[PlayerEvent], |
|
|
|
|
|
tickEventBus: GameEventBus[TickEvent] |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
def gameInit: Resource[Task, Fiber[Throwable, Unit]] = |
|
|
def gameInit: Resource[Task, Fiber[Throwable, Unit]] = |
|
|
GameApp.resource(logger, jmeThread, schedulers).evalMap { |
|
|
|
|
|
|
|
|
wire[GameAppResource].resource.evalMap { |
|
|
case gameApp -> gameAppFib => |
|
|
case gameApp -> gameAppFib => |
|
|
for { |
|
|
for { |
|
|
playerEventBus <- eventsModule.playerEventBusTask |
|
|
playerEventBus <- eventsModule.playerEventBusTask |
|
|
mainEventBus <- eventsModule.mainEventBusTask |
|
|
mainEventBus <- eventsModule.mainEventBusTask |
|
|
tickEventBus <- eventsModule.tickEventBusTask |
|
|
tickEventBus <- eventsModule.tickEventBusTask |
|
|
gameAppActor <- AkkaUtils.spawnActorL( |
|
|
|
|
|
GameAppActor.Props(tickEventBus).behavior, |
|
|
|
|
|
"gameAppActor" |
|
|
|
|
|
|
|
|
obs <- playerEventBus.askL[Observable[PlayerMovementEvent]]( |
|
|
|
|
|
ObservableSubscription(_) |
|
|
|
|
|
) |
|
|
|
|
|
_ <- IOUtils.toIO( |
|
|
|
|
|
obs |
|
|
|
|
|
.doOnNextF(pme => Coeval(pprint.log(s"Received event $pme")).void) |
|
|
|
|
|
.completedL |
|
|
|
|
|
.startAndForget |
|
|
) |
|
|
) |
|
|
_ <- gameAppActor !! GameAppActor.Start |
|
|
|
|
|
inputManager <- gameApp.inputManager |
|
|
inputManager <- gameApp.inputManager |
|
|
assetManager <- gameApp.assetManager |
|
|
|
|
|
|
|
|
assetManager <- UIO.pure(gameApp.assetManager) |
|
|
stateManager <- gameApp.stateManager |
|
|
stateManager <- gameApp.stateManager |
|
|
camera <- gameApp.camera |
|
|
camera <- gameApp.camera |
|
|
rootNode <- Task.pure(gameApp.rootNode) |
|
|
|
|
|
enqueueR <- Task(gameApp.enqueue _) |
|
|
|
|
|
|
|
|
rootNode <- UIO.pure(gameApp.rootNode) |
|
|
|
|
|
enqueueR <- UIO(gameApp.enqueue _) |
|
|
viewPort <- gameApp.viewPort |
|
|
viewPort <- gameApp.viewPort |
|
|
|
|
|
physicsSpace <- UIO.pure(gameApp.physicsSpace) |
|
|
_ <- logger.info("before") |
|
|
_ <- logger.info("before") |
|
|
// jfxUI <- gameApp.jfxUI |
|
|
// jfxUI <- gameApp.jfxUI |
|
|
|
|
|
gameAppActor <- gameApp.spawnGameActor( |
|
|
|
|
|
GameAppActor.Props(tickEventBus).behavior, |
|
|
|
|
|
"gameAppActor" |
|
|
|
|
|
) |
|
|
|
|
|
_ <- gameAppActor !! GameAppActor.Start |
|
|
consoleTextArea <- Task(new TextArea { |
|
|
consoleTextArea <- Task(new TextArea { |
|
|
text = "hello \n" |
|
|
text = "hello \n" |
|
|
editable = false |
|
|
editable = false |
|
@ -98,9 +125,6 @@ class MainApp( |
|
|
// _ <- Task(consoleStream := consoleTextArea) |
|
|
// _ <- Task(consoleStream := consoleTextArea) |
|
|
// _ <- Task(jfxUI += consoleTextArea) |
|
|
// _ <- Task(jfxUI += consoleTextArea) |
|
|
_ <- logger.info("after") |
|
|
_ <- logger.info("after") |
|
|
// bulletAppState <- Task(new BulletAppState()) |
|
|
|
|
|
// _ <- Task(stateManager.attach(bulletAppState)) |
|
|
|
|
|
// bulletAppState <- Task.pure(gameApp.bulletAppstate) |
|
|
|
|
|
_ <- logger.info("Initializing console stream") |
|
|
_ <- logger.info("Initializing console stream") |
|
|
_ <- |
|
|
_ <- |
|
|
wire[MainAppDelegate] |
|
|
wire[MainAppDelegate] |
|
@ -109,6 +133,13 @@ class MainApp( |
|
|
} yield gameAppFib |
|
|
} yield gameAppFib |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// val x: Task[Unit] = for { |
|
|
|
|
|
// tickEventBus <- eventsModule.tickEventBusTask |
|
|
|
|
|
// playerEventBus <- eventsModule.playerEventBusTask |
|
|
|
|
|
// _ <- UIO(wire[TestClass]) |
|
|
|
|
|
// _ <- gameInit(tickEventBus).use(_.join) |
|
|
|
|
|
// } yield () |
|
|
|
|
|
|
|
|
val program = for { |
|
|
val program = for { |
|
|
scriptSystem <- scriptSystemInit |
|
|
scriptSystem <- scriptSystemInit |
|
|
launchSignal <- Deferred[Task, Launcher.LauncherResult] |
|
|
launchSignal <- Deferred[Task, Launcher.LauncherResult] |
|
@ -125,6 +156,7 @@ class MainApp( |
|
|
*/ |
|
|
*/ |
|
|
else |
|
|
else |
|
|
gameInit.use(_.join) |
|
|
gameInit.use(_.join) |
|
|
|
|
|
|
|
|
} yield () |
|
|
} yield () |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -139,47 +171,44 @@ class MainAppDelegate( |
|
|
inputManager: InputManager, |
|
|
inputManager: InputManager, |
|
|
assetManager: AssetManager, |
|
|
assetManager: AssetManager, |
|
|
stateManager: AppStateManager, |
|
|
stateManager: AppStateManager, |
|
|
|
|
|
physicsSpace: PhysicsSpace[Task], |
|
|
camera: Camera, |
|
|
camera: Camera, |
|
|
viewPort: ViewPort, |
|
|
viewPort: ViewPort, |
|
|
enqueueR: Function1[() => Unit, Unit], |
|
|
enqueueR: Function1[() => Unit, Unit], |
|
|
rootNode: AppNode[Task] @@ GameAppTags.RootNode |
|
|
rootNode: AppNode[Task] @@ GameAppTags.RootNode |
|
|
// bulletAppState: BulletAppState |
|
|
|
|
|
)(implicit |
|
|
)(implicit |
|
|
spawnProtocol: ActorSystem[SpawnProtocol.Command], |
|
|
|
|
|
@annotation.unused timeout: Timeout, |
|
|
|
|
|
@annotation.unused scheduler: Scheduler |
|
|
|
|
|
|
|
|
spawnProtocol: ActorRef[SpawnProtocol.Command], |
|
|
|
|
|
timeout: Timeout, |
|
|
|
|
|
scheduler: Scheduler |
|
|
) { |
|
|
) { |
|
|
// val physicsSpace = bulletAppState.physicsSpace |
|
|
|
|
|
val physicsSpace = gameApp.physicsSpace |
|
|
|
|
|
|
|
|
|
|
|
def init( |
|
|
def init( |
|
|
// appScheduler: monix.execution.Scheduler |
|
|
// appScheduler: monix.execution.Scheduler |
|
|
// consoleStream: GenericConsoleStream[TextArea] |
|
|
// consoleStream: GenericConsoleStream[TextArea] |
|
|
) = |
|
|
) = |
|
|
for { |
|
|
for { |
|
|
_ <- loggerL.info("Initializing Systems") |
|
|
_ <- loggerL.info("Initializing Systems") |
|
|
_ <- loggerL.debug(physicsSpace.toString()) |
|
|
|
|
|
_ <- Task( |
|
|
|
|
|
assetManager.registerLocator( |
|
|
|
|
|
os.rel / "assets" / "town.zip", |
|
|
|
|
|
classOf[ZipLocator] |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
_ <- assetManager.registerLocator( |
|
|
|
|
|
os.rel / "assets" / "town.zip", |
|
|
|
|
|
classOf[ZipLocator] |
|
|
) |
|
|
) |
|
|
_ <- loggerL.info("test") |
|
|
_ <- loggerL.info("test") |
|
|
// _ <- Task(consoleStream.println("text")) |
|
|
// _ <- Task(consoleStream.println("text")) |
|
|
_ <- DefaultGameLevel(assetManager, viewPort) |
|
|
_ <- DefaultGameLevel(assetManager, viewPort) |
|
|
.addToGame(rootNode, physicsSpace) |
|
|
|
|
|
|
|
|
.flatMap(_.addToGame(rootNode, physicsSpace).hideErrors) |
|
|
|
|
|
.onErrorHandleWith(e => loggerL.error(e.toString)) |
|
|
_ <- createPlayerController() |
|
|
_ <- createPlayerController() |
|
|
.absorbWith(e => DummyException(e.toString())) |
|
|
|
|
|
|
|
|
.onErrorHandleWith(e => loggerL.error(e.toString)) |
|
|
// .onErrorRestart(3) |
|
|
// .onErrorRestart(3) |
|
|
_ <- wire[GameInputHandler.Props].begin |
|
|
_ <- wire[GameInputHandler.Props].begin |
|
|
// .onErrorRestart(3) |
|
|
// .onErrorRestart(3) |
|
|
// johnActor <- createTestNpc(appScheduler, "John").executeOn(appScheduler) |
|
|
|
|
|
|
|
|
johnActor <- createTestNpc("John") |
|
|
|
|
|
.onErrorHandleWith(e => IO.raiseError(new Throwable(e.toString))) |
|
|
// _ <- johnActor !! NpcActorSupervisor.Move(ImVector3f(0, 0, 20)) |
|
|
// _ <- johnActor !! NpcActorSupervisor.Move(ImVector3f(0, 0, 20)) |
|
|
|
|
|
|
|
|
// _ <- |
|
|
// _ <- |
|
|
// (johnActor !! NpcActorSupervisor.Move( |
|
|
|
|
|
// ImVector3f(-30, 0, 10) |
|
|
|
|
|
// )).executeAsync |
|
|
|
|
|
|
|
|
// johnActor |
|
|
|
|
|
// .tellL(NpcActorSupervisor.Move(ImVector3f(-30, 0, 10))) |
|
|
// .delayExecution(2.seconds) |
|
|
// .delayExecution(2.seconds) |
|
|
// _ <- |
|
|
// _ <- |
|
|
// IOUtils |
|
|
// IOUtils |
|
@ -195,53 +224,40 @@ class MainAppDelegate( |
|
|
|
|
|
|
|
|
def createPlayerController( |
|
|
def createPlayerController( |
|
|
// appScheduler: monix.execution.Scheduler |
|
|
// appScheduler: monix.execution.Scheduler |
|
|
): IO[PlayerController.Error, Unit] = { |
|
|
|
|
|
|
|
|
): IO[PlayerController.Error, ActorRef[PlayerActorSupervisor.Command]] = { |
|
|
val playerPos = ImVector3f.ZERO |
|
|
val playerPos = ImVector3f.ZERO |
|
|
val modelPath = os.rel / "Models" / "Jaime" / "Jaime.j3o" |
|
|
val modelPath = os.rel / "Models" / "Jaime" / "Jaime.j3o" |
|
|
val playerPhysicsControl = |
|
|
val playerPhysicsControl = |
|
|
PlayerController.Defaults.defaultPlayerPhysicsControl |
|
|
PlayerController.Defaults.defaultPlayerPhysicsControl |
|
|
.taggedWith[PlayerControllerTags.PlayerTag] |
|
|
.taggedWith[PlayerControllerTags.PlayerTag] |
|
|
// lazy val camNode = |
|
|
|
|
|
// PlayerController.Defaults |
|
|
|
|
|
// .defaultCamerNode(camera, playerPos) |
|
|
|
|
|
// .taggedWith[PlayerControllerTags.PlayerCameraNode] |
|
|
|
|
|
val playerModel = assetManager |
|
|
|
|
|
.loadModel(modelPath) |
|
|
|
|
|
.asInstanceOf[Node] |
|
|
|
|
|
.withRotate(0, FastMath.PI, 0) |
|
|
|
|
|
val mbPlayerNode = PlayerController.Defaults |
|
|
|
|
|
.defaultPlayerNode( |
|
|
|
|
|
playerPos, |
|
|
|
|
|
playerModel, |
|
|
|
|
|
playerPhysicsControl |
|
|
|
|
|
) |
|
|
|
|
|
val cameraPivotNode = new Node(EntityIds.CameraPivot.value) |
|
|
|
|
|
.taggedWith[PlayerControllerTags.PlayerCameraPivotNode] |
|
|
|
|
|
|
|
|
|
|
|
for { |
|
|
for { |
|
|
playerNode <- IO.fromEither(mbPlayerNode) |
|
|
|
|
|
_ <- IO(cameraPivotNode.addControl(new FollowControl(playerNode))) |
|
|
|
|
|
.onErrorHandleWith(e => |
|
|
|
|
|
IO.raiseError(PlayerController.GenericError(e.getMessage())) |
|
|
|
|
|
) |
|
|
|
|
|
camNode <- IO( |
|
|
|
|
|
|
|
|
playerModel <- |
|
|
|
|
|
assetManager |
|
|
|
|
|
.loadModelAs[Node](modelPath) |
|
|
|
|
|
.map(_.withRotate(0, FastMath.PI, 0)) |
|
|
|
|
|
.mapError(PlayerController.CouldNotCreatePlayerModel) |
|
|
|
|
|
playerNode <- UIO( |
|
|
PlayerController.Defaults |
|
|
PlayerController.Defaults |
|
|
.defaultCamerNode(camera, cameraPivotNode, playerNode, playerPos) |
|
|
|
|
|
).onErrorHandleWith(e => |
|
|
|
|
|
IO.raiseError(PlayerController.GenericError(e.getMessage())) |
|
|
|
|
|
).map(_.taggedWith[PlayerControllerTags.PlayerCameraNode]) |
|
|
|
|
|
// _ <- Task { |
|
|
|
|
|
// val chaseCam = new ChaseCamera(camera, playerNode, inputManager) |
|
|
|
|
|
// chaseCam.setSmoothMotion(false) |
|
|
|
|
|
// chaseCam.setLookAtOffset(new Vector3f(0, 1.5f, 10)) |
|
|
|
|
|
// chaseCam |
|
|
|
|
|
// } |
|
|
|
|
|
// .onErrorHandleWith(e => |
|
|
|
|
|
// IO.raiseError(PlayerController.GenericError(e.getMessage())) |
|
|
|
|
|
// ) |
|
|
|
|
|
_ <- wire[PlayerController.Props].create |
|
|
|
|
|
} yield () |
|
|
|
|
|
|
|
|
.defaultPlayerNode( |
|
|
|
|
|
playerPos, |
|
|
|
|
|
playerModel, |
|
|
|
|
|
playerPhysicsControl |
|
|
|
|
|
) |
|
|
|
|
|
) |
|
|
|
|
|
cameraPivotNode <- UIO( |
|
|
|
|
|
new Node(EntityIds.CameraPivot.value) |
|
|
|
|
|
.withControl(new FollowControl(playerNode)) |
|
|
|
|
|
.taggedWith[PlayerControllerTags.PlayerCameraPivotNode] |
|
|
|
|
|
) |
|
|
|
|
|
camNode <- UIO( |
|
|
|
|
|
PlayerController.Defaults |
|
|
|
|
|
.defaultCamerNode(camera, playerPos) |
|
|
|
|
|
.taggedWith[PlayerControllerTags.PlayerCameraNode] |
|
|
|
|
|
) |
|
|
|
|
|
playerActor <- wire[PlayerController.Props].create |
|
|
|
|
|
} yield playerActor |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
def createTestNpc( |
|
|
def createTestNpc( |
|
|
// appScheduler: monix.execution.Scheduler, |
|
|
// appScheduler: monix.execution.Scheduler, |
|
|
npcName: String |
|
|
npcName: String |
|
@ -250,12 +266,7 @@ class MainAppDelegate( |
|
|
val npcPhysicsControl = new BetterCharacterControl(1.5f, 6f, 1f) |
|
|
val npcPhysicsControl = new BetterCharacterControl(1.5f, 6f, 1f) |
|
|
// (1f, 2.1f, 10f) |
|
|
// (1f, 2.1f, 10f) |
|
|
.withJumpForce(ImVector3f(0, 5f, 0)) |
|
|
.withJumpForce(ImVector3f(0, 5f, 0)) |
|
|
val mbNpcNode = PlayerController.Defaults.defaultNpcNode( |
|
|
|
|
|
assetManager, |
|
|
|
|
|
initialPos, |
|
|
|
|
|
npcPhysicsControl, |
|
|
|
|
|
npcName |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
val npcActorTask = AkkaUtils.spawnActorL( |
|
|
val npcActorTask = AkkaUtils.spawnActorL( |
|
|
NpcActorSupervisor |
|
|
NpcActorSupervisor |
|
|
.Props( |
|
|
.Props( |
|
@ -263,6 +274,7 @@ class MainAppDelegate( |
|
|
enqueueR, |
|
|
enqueueR, |
|
|
initialPos, |
|
|
initialPos, |
|
|
// tickEventBus, |
|
|
// tickEventBus, |
|
|
|
|
|
npcName, |
|
|
npcPhysicsControl |
|
|
npcPhysicsControl |
|
|
).behavior, |
|
|
).behavior, |
|
|
npcName, |
|
|
npcName, |
|
@ -271,28 +283,35 @@ class MainAppDelegate( |
|
|
.behavior, |
|
|
.behavior, |
|
|
s"${npcName}-npcActorSupervisor" |
|
|
s"${npcName}-npcActorSupervisor" |
|
|
) |
|
|
) |
|
|
// .taggedWith[PlayerControllerTags.PlayerTag] |
|
|
|
|
|
|
|
|
|
|
|
for { |
|
|
for { |
|
|
npcNode <- IO.fromEither(mbNpcNode) |
|
|
|
|
|
npcActor <- npcActorTask |
|
|
|
|
|
// _ <- IO { |
|
|
|
|
|
// physicsSpace += npcPhysicsControl |
|
|
|
|
|
// physicsSpace += npcNode |
|
|
|
|
|
// // rootNode += npcNode |
|
|
|
|
|
// } |
|
|
|
|
|
_ <- physicsSpace += npcPhysicsControl |
|
|
|
|
|
_ <- physicsSpace += npcNode |
|
|
|
|
|
_ <- rootNode += npcNode |
|
|
|
|
|
|
|
|
materialDef <- assetManager.loadAssetAs[MaterialDef]( |
|
|
|
|
|
os.rel / "Common" / "MatDefs" / "Misc" / "Unshaded.j3md" |
|
|
|
|
|
) |
|
|
|
|
|
material = new Material(materialDef) |
|
|
|
|
|
_ = material.setColor("Color", ColorRGBA.Blue) |
|
|
|
|
|
mesh = PlayerController.Defaults.defaultMesh.withMaterial(material) |
|
|
|
|
|
npcNode = PlayerController.Defaults.defaultNpcNode( |
|
|
|
|
|
mesh, |
|
|
|
|
|
initialPos, |
|
|
|
|
|
npcPhysicsControl, |
|
|
|
|
|
npcName |
|
|
|
|
|
) |
|
|
|
|
|
npcActor <- npcActorTask.hideErrors |
|
|
|
|
|
_ <- (for { |
|
|
|
|
|
_ <- physicsSpace += npcPhysicsControl |
|
|
|
|
|
_ <- physicsSpace += npcNode |
|
|
|
|
|
_ <- rootNode += npcNode |
|
|
|
|
|
} yield ()).hideErrors |
|
|
} yield npcActor |
|
|
} yield npcActor |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
class FollowControl(playerNode: Node) extends AbstractControl { |
|
|
class FollowControl(playerNode: Node) extends AbstractControl { |
|
|
override def controlUpdate(tpf: Float): Unit = { |
|
|
|
|
|
|
|
|
override def controlUpdate(tpf: Float): Unit = |
|
|
this.spatial.setLocalTranslation(playerNode.getLocalTranslation()) |
|
|
this.spatial.setLocalTranslation(playerNode.getLocalTranslation()) |
|
|
} |
|
|
|
|
|
override def controlRender( |
|
|
override def controlRender( |
|
|
rm: RenderManager, |
|
|
rm: RenderManager, |
|
|
vp: ViewPort |
|
|
vp: ViewPort |
|
|