Some Refactorings
This commit is contained in:
parent
88293cebde
commit
45ab129790
@ -1,6 +1,5 @@
|
||||
package wow.doge.mygame
|
||||
|
||||
import akka.actor.typed.ActorRef
|
||||
import akka.actor.typed.ActorSystem
|
||||
import akka.actor.typed.Scheduler
|
||||
import akka.actor.typed.SpawnProtocol
|
||||
@ -31,7 +30,7 @@ import wow.doge.mygame.game.GameAppActor
|
||||
import wow.doge.mygame.game.GameAppTags
|
||||
import wow.doge.mygame.game.entities.EntityIds
|
||||
import wow.doge.mygame.game.entities.NpcActorSupervisor
|
||||
import wow.doge.mygame.game.entities.NpcMovementActor2
|
||||
import wow.doge.mygame.game.entities.NpcMovementActor
|
||||
import wow.doge.mygame.game.entities.PlayerController
|
||||
import wow.doge.mygame.game.entities.PlayerControllerTags
|
||||
import wow.doge.mygame.game.subsystems.input.GameInputHandler
|
||||
@ -40,10 +39,8 @@ import wow.doge.mygame.implicits._
|
||||
import wow.doge.mygame.launcher.Launcher
|
||||
import wow.doge.mygame.launcher.Launcher.LauncherResult
|
||||
import wow.doge.mygame.math.ImVector3f
|
||||
import wow.doge.mygame.subsystems.events.EventBus
|
||||
import wow.doge.mygame.subsystems.events.EventsModule
|
||||
import wow.doge.mygame.subsystems.events.PlayerCameraEvent
|
||||
import wow.doge.mygame.subsystems.events.PlayerMovementEvent
|
||||
import wow.doge.mygame.subsystems.events.PlayerEvent
|
||||
import wow.doge.mygame.subsystems.events.TickEvent
|
||||
import wow.doge.mygame.subsystems.scriptsystem.ScriptInitMode
|
||||
import wow.doge.mygame.subsystems.scriptsystem.ScriptSystemResource
|
||||
@ -71,12 +68,11 @@ class MainApp(
|
||||
def gameInit: Task[Fiber[Throwable, Unit]] =
|
||||
for {
|
||||
eventsModule <- Task(new EventsModule(spawnProtocol))
|
||||
playerMovementEventBus <- eventsModule.playerMovementEventBusTask
|
||||
playerCameraEventBus <- eventsModule.playerCameraEventBusTask
|
||||
playerEventBus <- eventsModule.playerEventBusTask
|
||||
mainEventBus <- eventsModule.mainEventBusTask
|
||||
tickEventBus <- eventsModule.tickEventBusTask
|
||||
gameAppActor <- AkkaUtils.spawnActorL2(
|
||||
GameAppActor.Props(tickEventBus).create,
|
||||
GameAppActor.Props(tickEventBus).behavior,
|
||||
"gameAppActor"
|
||||
)
|
||||
_ <- gameAppActor !! GameAppActor.Start
|
||||
@ -152,10 +148,7 @@ class MainAppDelegate(
|
||||
gameApp: GameApp,
|
||||
implicit val spawnProtocol: ActorSystem[SpawnProtocol.Command],
|
||||
loggerL: Logger[Task],
|
||||
playerMovementEventBus: ActorRef[
|
||||
EventBus.Command[PlayerMovementEvent]
|
||||
],
|
||||
playerCameraEventBus: ActorRef[EventBus.Command[PlayerCameraEvent]],
|
||||
playerEventBus: GameEventBus[PlayerEvent],
|
||||
tickEventBus: GameEventBus[TickEvent],
|
||||
inputManager: InputManager,
|
||||
assetManager: AssetManager,
|
||||
@ -275,7 +268,7 @@ class MainAppDelegate(
|
||||
// initialPos,
|
||||
// tickEventBus,
|
||||
// npcPhysicsControl
|
||||
// ).create,
|
||||
// ).behavior,
|
||||
// s"${npcName}-npcMovementActor"
|
||||
// )
|
||||
lazy val mbNpcNode = PlayerController.Defaults.defaultNpcNode(
|
||||
@ -287,16 +280,16 @@ class MainAppDelegate(
|
||||
val npcActorTask = AkkaUtils.spawnActorL2(
|
||||
NpcActorSupervisor
|
||||
.Props(
|
||||
new NpcMovementActor2.Props(
|
||||
new NpcMovementActor.Props(
|
||||
enqueueR,
|
||||
initialPos,
|
||||
// tickEventBus,
|
||||
npcPhysicsControl
|
||||
).create,
|
||||
).behavior,
|
||||
npcName,
|
||||
initialPos
|
||||
)
|
||||
.create,
|
||||
.behavior,
|
||||
s"${npcName}-npcActorSupervisor"
|
||||
)
|
||||
// .taggedWith[PlayerControllerTags.PlayerTag]
|
||||
|
@ -117,7 +117,7 @@ object SpawnSystem {
|
||||
final case object Complete extends Complete
|
||||
|
||||
sealed trait SpawnRequest
|
||||
final case class SpawnSpatial(node: Node) extends SpawnRequest
|
||||
final case class SpawnSpatial(nodeTask: Task[Node]) extends SpawnRequest
|
||||
|
||||
final case class SpawnRequestWrapper(
|
||||
spawnRequest: SpawnRequest,
|
||||
@ -147,7 +147,7 @@ class SpawnSystem(
|
||||
|
||||
for {
|
||||
spawnSystem <- SpawnSystem(logger)
|
||||
n <- spawnSystem.request(SpawnSpatial(new Node("Test")))
|
||||
res <- spawnSystem.request(SpawnSpatial(Task(new Node("Test"))))
|
||||
} yield ()
|
||||
|
||||
// val spawnChannel = ConcurrentChannel[Task].of[Result, SpawnRequest]
|
||||
@ -164,18 +164,20 @@ class SpawnSystem(
|
||||
_ <- handleSpawn(message)
|
||||
} yield receive(consumer)
|
||||
case Left(r) =>
|
||||
logger.info("Worker $$index is done!")
|
||||
logger.info("Closing Spawn System")
|
||||
}
|
||||
|
||||
private def handleSpawn(spawnRequestWrapper: SpawnRequestWrapper) =
|
||||
spawnRequestWrapper match {
|
||||
case SpawnRequestWrapper(spawnRequest, result) =>
|
||||
spawnRequest match {
|
||||
case SpawnSpatial(spatial) =>
|
||||
logger.debug(
|
||||
s"Spawning spatial with name ${spatial.getName()}"
|
||||
) >> result
|
||||
.complete(Ok)
|
||||
case SpawnSpatial(spatialTask) =>
|
||||
spatialTask.flatMap(spatial =>
|
||||
logger.debug(
|
||||
s"Spawning spatial with name ${spatial.getName()}"
|
||||
) >> result
|
||||
.complete(Ok)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ object GameAppActor {
|
||||
// loggerL: Logger[Task]
|
||||
tickEventBus: GameEventBus[TickEvent]
|
||||
) {
|
||||
def create =
|
||||
def behavior =
|
||||
Behaviors.setup[Command] { ctx =>
|
||||
ctx.log.info("Hello from GameAppActor")
|
||||
val renderTickGenerator =
|
||||
@ -40,7 +40,7 @@ object GameAppActor {
|
||||
val tickGeneratorTimer = ctx.spawn(
|
||||
GenericTimerActor
|
||||
.Props(renderTickGenerator, TickGenerator.Send, 10.millis)
|
||||
.create,
|
||||
.behavior,
|
||||
"tickGeneratorTimer"
|
||||
)
|
||||
|
||||
|
@ -32,7 +32,7 @@ object NpcActorSupervisor {
|
||||
final case class Move(pos: ImVector3f) extends Command
|
||||
private final case class InternalMove(
|
||||
move: Move,
|
||||
signal: CancelableFuture[NpcMovementActor2.DoneMoving.type]
|
||||
signal: CancelableFuture[NpcMovementActor.DoneMoving.type]
|
||||
) extends Command
|
||||
private case object DoneMoving extends Command
|
||||
// private case class MovementResponse(response: CancelableFuture[_]) extends Command
|
||||
@ -40,11 +40,11 @@ object NpcActorSupervisor {
|
||||
private case object NoOp extends Command
|
||||
|
||||
final case class Props(
|
||||
npcMovementActorBehavior: Behavior[NpcMovementActor2.Command],
|
||||
npcMovementActorBehavior: Behavior[NpcMovementActor.Command],
|
||||
npcName: String,
|
||||
initialPos: ImVector3f
|
||||
) {
|
||||
def create =
|
||||
def behavior =
|
||||
Behaviors.setup[Command] { ctx =>
|
||||
val npcMovementActor = ctx.spawn(
|
||||
(npcMovementActorBehavior),
|
||||
@ -58,7 +58,7 @@ object NpcActorSupervisor {
|
||||
final case class State(
|
||||
)
|
||||
final case class Children(
|
||||
npcMovementActor: ActorRef[NpcMovementActor2.Command]
|
||||
npcMovementActor: ActorRef[NpcMovementActor.Command]
|
||||
)
|
||||
}
|
||||
class NpcActorSupervisor(
|
||||
@ -73,21 +73,21 @@ class NpcActorSupervisor(
|
||||
GenericTimerActor
|
||||
.Props(
|
||||
children.npcMovementActor,
|
||||
NpcMovementActor2.MovementTick,
|
||||
NpcMovementActor.MovementTick,
|
||||
100.millis
|
||||
)
|
||||
.create,
|
||||
.behavior,
|
||||
s"npc-John-NpcActorTimer"
|
||||
)
|
||||
|
||||
def idle(state: State): Behavior[NpcActorSupervisor.Command] =
|
||||
Behaviors.setup { _ =>
|
||||
ctx.log.info("Inside Idle State")
|
||||
ctx.log.debug("Inside Idle State")
|
||||
Behaviors.receiveMessage[Command] {
|
||||
case m @ Move(pos) =>
|
||||
ctx.ask(
|
||||
children.npcMovementActor,
|
||||
NpcMovementActor2.MoveTo(pos, _)
|
||||
NpcMovementActor.MoveTo(pos, _)
|
||||
) {
|
||||
case Success(signal) => InternalMove(m, signal)
|
||||
case Failure(exception) => LogError(exception)
|
||||
@ -106,7 +106,7 @@ class NpcActorSupervisor(
|
||||
def moving(
|
||||
state: State,
|
||||
targetPos: ImVector3f,
|
||||
signal: CancelableFuture[NpcMovementActor2.DoneMoving.type]
|
||||
signal: CancelableFuture[NpcMovementActor.DoneMoving.type]
|
||||
): Behavior[NpcActorSupervisor.Command] =
|
||||
Behaviors.setup { _ =>
|
||||
movementTimer ! GenericTimerActor.Start
|
||||
@ -125,11 +125,11 @@ class NpcActorSupervisor(
|
||||
Behaviors.same
|
||||
case m @ Move(pos) =>
|
||||
movementTimer ! GenericTimerActor.Stop
|
||||
children.npcMovementActor ! NpcMovementActor2.StopMoving
|
||||
children.npcMovementActor ! NpcMovementActor.StopMoving
|
||||
signal.cancel()
|
||||
ctx.ask(
|
||||
children.npcMovementActor,
|
||||
NpcMovementActor2.MoveTo(pos, _)
|
||||
NpcMovementActor.MoveTo(pos, _)
|
||||
) {
|
||||
case Success(signal) => InternalMove(m, signal)
|
||||
case Failure(exception) => LogError(exception)
|
||||
@ -148,7 +148,7 @@ class NpcActorSupervisor(
|
||||
}
|
||||
}
|
||||
|
||||
object NpcMovementActor2 {
|
||||
object NpcMovementActor {
|
||||
|
||||
case object DoneMoving
|
||||
|
||||
@ -167,25 +167,25 @@ object NpcMovementActor2 {
|
||||
// val tickEventBus: GameEventBus[TickEvent],
|
||||
val movable: T
|
||||
) {
|
||||
def create =
|
||||
def behavior =
|
||||
Behaviors.setup[Command] { ctx =>
|
||||
new NpcMovementActor2(ctx, this).receive(State())
|
||||
new NpcMovementActor(ctx, this).receive(State())
|
||||
}
|
||||
}
|
||||
|
||||
final case class State()
|
||||
}
|
||||
class NpcMovementActor2[T](
|
||||
ctx: ActorContext[NpcMovementActor2.Command],
|
||||
props: NpcMovementActor2.Props[T]
|
||||
class NpcMovementActor[T](
|
||||
ctx: ActorContext[NpcMovementActor.Command],
|
||||
props: NpcMovementActor.Props[T]
|
||||
)(implicit cm: CanMove[T]) {
|
||||
import NpcMovementActor2._
|
||||
import NpcMovementActor._
|
||||
|
||||
def location = cm.location(props.movable)
|
||||
|
||||
def receive(
|
||||
state: State
|
||||
): Behavior[NpcMovementActor2.Command] =
|
||||
): Behavior[NpcMovementActor.Command] =
|
||||
Behaviors.receiveMessagePartial {
|
||||
case AskPosition(replyTo) =>
|
||||
replyTo ! location
|
||||
@ -211,7 +211,7 @@ class NpcMovementActor2[T](
|
||||
reachDestination: CancelablePromise[DoneMoving.type],
|
||||
targetPos: ImVector3f,
|
||||
state: State
|
||||
): Behavior[NpcMovementActor2.Command] =
|
||||
): Behavior[NpcMovementActor.Command] =
|
||||
Behaviors.receiveMessagePartial {
|
||||
case StopMoving =>
|
||||
ctx.log.debug(
|
||||
@ -234,7 +234,7 @@ class NpcMovementActor2[T](
|
||||
}
|
||||
}
|
||||
|
||||
object NpcMovementActor {
|
||||
object NpcMovementActorNotUsed {
|
||||
sealed trait Command
|
||||
final case class Props(
|
||||
imMovementActorBehavior: Behavior[ImMovementActor.Command],
|
||||
@ -246,7 +246,7 @@ object NpcMovementActor {
|
||||
tickEventBus: GameEventBus[TickEvent]
|
||||
) {
|
||||
|
||||
def create: Behavior[Command] =
|
||||
def behavior: Behavior[Command] =
|
||||
Behaviors.setup { ctx =>
|
||||
val movementActor = ctx.spawn(
|
||||
Behaviors
|
||||
|
@ -15,8 +15,7 @@ import org.slf4j.event.Level
|
||||
import wow.doge.mygame.game.subsystems.movement.CanMove
|
||||
import wow.doge.mygame.subsystems.events.EventBus
|
||||
import wow.doge.mygame.subsystems.events.EventsModule.GameEventBus
|
||||
import wow.doge.mygame.subsystems.events.PlayerCameraEvent
|
||||
import wow.doge.mygame.subsystems.events.PlayerMovementEvent
|
||||
import wow.doge.mygame.subsystems.events.PlayerEvent
|
||||
import wow.doge.mygame.subsystems.events.TickEvent
|
||||
import wow.doge.mygame.subsystems.events.TickEvent.RenderTick
|
||||
import wow.doge.mygame.subsystems.movement.ImMovementActor
|
||||
@ -24,15 +23,12 @@ import wow.doge.mygame.subsystems.movement.ImMovementActor
|
||||
object PlayerActorSupervisor {
|
||||
sealed trait Command
|
||||
final case class Props(
|
||||
playerMovementEventBus: ActorRef[
|
||||
EventBus.Command[PlayerMovementEvent]
|
||||
],
|
||||
playerCameraEventBus: ActorRef[EventBus.Command[PlayerCameraEvent]],
|
||||
playerEventBus: GameEventBus[PlayerEvent],
|
||||
tickEventBus: GameEventBus[TickEvent],
|
||||
imMovementActorBehavior: Behavior[ImMovementActor.Command],
|
||||
playerCameraActorBehavior: Behavior[PlayerCameraActor.Command]
|
||||
) {
|
||||
def create[T: CanMove](movable: T) =
|
||||
def behavior[T: CanMove](movable: T) =
|
||||
Behaviors.logMessages(
|
||||
LogOptions()
|
||||
.withLevel(Level.TRACE)
|
||||
@ -64,15 +60,15 @@ object PlayerActorSupervisor {
|
||||
.Props(
|
||||
movementActor,
|
||||
playerCameraActor,
|
||||
playerMovementEventBus,
|
||||
playerEventBus,
|
||||
tickEventBus
|
||||
)
|
||||
.create,
|
||||
.behavior,
|
||||
"playerMovementAcor"
|
||||
)
|
||||
|
||||
//init actors
|
||||
playerCameraEventBus ! EventBus.Subscribe(playerCameraEl)
|
||||
playerEventBus ! EventBus.Subscribe(playerCameraEl)
|
||||
|
||||
new PlayerActorSupervisor(
|
||||
ctx,
|
||||
@ -107,13 +103,11 @@ object PlayerMovementActor {
|
||||
final case class Props(
|
||||
movementActor: ActorRef[ImMovementActor.Command],
|
||||
playerCameraActor: ActorRef[PlayerCameraActor.Command],
|
||||
playerMovementEventBus: ActorRef[
|
||||
EventBus.Command[PlayerMovementEvent]
|
||||
],
|
||||
playerEventBus: GameEventBus[PlayerEvent],
|
||||
tickEventBus: GameEventBus[TickEvent]
|
||||
) {
|
||||
|
||||
def create: Behavior[Command] =
|
||||
def behavior: Behavior[Command] =
|
||||
Behaviors.setup { ctx =>
|
||||
val playerMovementEl = ctx.spawn(
|
||||
Behaviors
|
||||
@ -131,7 +125,7 @@ object PlayerMovementActor {
|
||||
val renderTickEl =
|
||||
ctx.spawn(renderTickElBehavior, "playerMovementTickListener")
|
||||
|
||||
playerMovementEventBus ! EventBus.Subscribe(playerMovementEl)
|
||||
playerEventBus ! EventBus.Subscribe(playerMovementEl)
|
||||
tickEventBus ! EventBus.Subscribe(renderTickEl)
|
||||
Behaviors.receiveMessage { msg => Behaviors.same }
|
||||
}
|
||||
@ -150,7 +144,7 @@ object GenericTimerActor {
|
||||
messageToSend: T,
|
||||
timeInterval: FiniteDuration
|
||||
) {
|
||||
val create = Behaviors.withTimers[Command] { timers =>
|
||||
val behavior = Behaviors.withTimers[Command] { timers =>
|
||||
new GenericTimerActor(timers, TimerKey(Random.nextLong()), this).idle
|
||||
}
|
||||
}
|
||||
|
@ -24,7 +24,7 @@ object PlayerCameraActor {
|
||||
val enqueueR: Function1[() => Unit, Unit],
|
||||
val getPlayerLocation: Function0[Vector3f]
|
||||
) {
|
||||
def create =
|
||||
def behavior =
|
||||
Behaviors.logMessages(
|
||||
LogOptions()
|
||||
.withLevel(Level.TRACE)
|
||||
|
@ -24,10 +24,8 @@ import wow.doge.mygame.game.SimpleAppExt
|
||||
import wow.doge.mygame.implicits._
|
||||
import wow.doge.mygame.math.ImVector3f
|
||||
import wow.doge.mygame.state.MyMaterial
|
||||
import wow.doge.mygame.subsystems.events.EventBus
|
||||
import wow.doge.mygame.subsystems.events.EventsModule.GameEventBus
|
||||
import wow.doge.mygame.subsystems.events.PlayerCameraEvent
|
||||
import wow.doge.mygame.subsystems.events.PlayerMovementEvent
|
||||
import wow.doge.mygame.subsystems.events.PlayerEvent
|
||||
import wow.doge.mygame.subsystems.events.TickEvent
|
||||
import wow.doge.mygame.subsystems.movement.ImMovementActor
|
||||
import wow.doge.mygame.utils.AkkaUtils
|
||||
@ -50,10 +48,7 @@ object PlayerController {
|
||||
physicsSpace: PhysicsSpace,
|
||||
initialPlayerPos: ImVector3f = ImVector3f.ZERO,
|
||||
spawnProtocol: ActorRef[SpawnProtocol.Command],
|
||||
playerMovementEventBus: ActorRef[
|
||||
EventBus.Command[PlayerMovementEvent]
|
||||
],
|
||||
playerCameraEventBus: ActorRef[EventBus.Command[PlayerCameraEvent]],
|
||||
playerEventBus: GameEventBus[PlayerEvent],
|
||||
playerPhysicsControl: BetterCharacterControl,
|
||||
appScheduler: monix.execution.Scheduler,
|
||||
playerNode: Node @@ PlayerControllerTags.PlayerTag,
|
||||
@ -68,22 +63,22 @@ object PlayerController {
|
||||
spawnProtocol,
|
||||
"playerActorSupervisor",
|
||||
new PlayerActorSupervisor.Props(
|
||||
playerMovementEventBus,
|
||||
playerCameraEventBus,
|
||||
playerEventBus,
|
||||
// playerCameraEventBus,
|
||||
tickEventBus,
|
||||
new ImMovementActor.Props(
|
||||
enqueueR,
|
||||
playerPhysicsControl,
|
||||
camera
|
||||
).create,
|
||||
).behavior,
|
||||
// wireWith(PlayerCameraEventListener.apply _)
|
||||
// PlayerCameraEventListener()
|
||||
new PlayerCameraActor.Props(
|
||||
cameraPivotNode,
|
||||
enqueueR,
|
||||
playerNode.getWorldTranslation _
|
||||
).create
|
||||
).create(playerPhysicsControl)
|
||||
).behavior
|
||||
).behavior(playerPhysicsControl)
|
||||
)
|
||||
_ <- Task(rootNode += playerNode)
|
||||
_ <- IO {
|
||||
|
@ -15,6 +15,7 @@ import wow.doge.mygame.implicits._
|
||||
import wow.doge.mygame.subsystems.events.EventBus
|
||||
import wow.doge.mygame.subsystems.events.EventsModule.GameEventBus
|
||||
import wow.doge.mygame.subsystems.events.PlayerCameraEvent
|
||||
import wow.doge.mygame.subsystems.events.PlayerEvent
|
||||
import wow.doge.mygame.subsystems.events.PlayerMovementEvent
|
||||
import wow.doge.mygame.utils.IOUtils._
|
||||
|
||||
@ -22,8 +23,8 @@ object GameInputHandler {
|
||||
|
||||
final class Props(
|
||||
inputManager: InputManager,
|
||||
playerMovementEventBus: GameEventBus[PlayerMovementEvent],
|
||||
playerCameraEventBus: GameEventBus[PlayerCameraEvent]
|
||||
playerEventBus: GameEventBus[PlayerEvent]
|
||||
// playerCameraEventBus: GameEventBus[PlayerCameraEvent]
|
||||
// tickEventBus: GameEventBus[TickEvent]
|
||||
) {
|
||||
def begin =
|
||||
@ -34,19 +35,19 @@ object GameInputHandler {
|
||||
_ <- toIO(
|
||||
generateMovementInputEvents(
|
||||
inputManager,
|
||||
playerMovementEventBus
|
||||
playerEventBus
|
||||
).completedL.startAndForget
|
||||
)
|
||||
_ <- toIO(
|
||||
generateAnalogMovementEvents(
|
||||
inputManager,
|
||||
playerMovementEventBus
|
||||
playerEventBus
|
||||
).completedL.startAndForget
|
||||
)
|
||||
_ <- toIO(
|
||||
generateCameraEvents(
|
||||
inputManager,
|
||||
playerCameraEventBus
|
||||
playerEventBus
|
||||
).completedL.startAndForget
|
||||
)
|
||||
_ <- toIO(
|
||||
@ -130,9 +131,7 @@ object GameInputHandler {
|
||||
|
||||
def generateMovementInputEvents(
|
||||
inputManager: InputManager,
|
||||
playerMovementEventBus: ActorRef[
|
||||
EventBus.Command[PlayerMovementEvent]
|
||||
]
|
||||
playerEventBus: GameEventBus[PlayerEvent]
|
||||
) = {
|
||||
val name = "playerMovementInputEventsGenerator"
|
||||
inputManager
|
||||
@ -142,28 +141,28 @@ object GameInputHandler {
|
||||
action.binding match {
|
||||
case PlayerMovementInput.WalkLeft =>
|
||||
me.Task(
|
||||
playerMovementEventBus ! EventBus.Publish(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerMovementEvent.PlayerMovedLeft(pressed = action.value),
|
||||
name
|
||||
)
|
||||
)
|
||||
case PlayerMovementInput.WalkRight =>
|
||||
me.Task(
|
||||
playerMovementEventBus ! EventBus.Publish(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerMovementEvent.PlayerMovedRight(pressed = action.value),
|
||||
name
|
||||
)
|
||||
)
|
||||
case PlayerMovementInput.WalkForward =>
|
||||
me.Task(
|
||||
playerMovementEventBus ! EventBus.Publish(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerMovementEvent.PlayerMovedForward(pressed = action.value),
|
||||
name
|
||||
)
|
||||
)
|
||||
case PlayerMovementInput.WalkBackward =>
|
||||
me.Task(
|
||||
playerMovementEventBus ! EventBus.Publish(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerMovementEvent.PlayerMovedBackward(pressed = action.value),
|
||||
name
|
||||
)
|
||||
@ -171,7 +170,7 @@ object GameInputHandler {
|
||||
case PlayerMovementInput.Jump =>
|
||||
if (action.value) {
|
||||
me.Task(
|
||||
playerMovementEventBus ! EventBus.Publish(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerMovementEvent.PlayerJumped,
|
||||
name
|
||||
)
|
||||
@ -183,9 +182,7 @@ object GameInputHandler {
|
||||
|
||||
def generateAnalogMovementEvents(
|
||||
inputManager: InputManager,
|
||||
playerMovementEventBus: ActorRef[
|
||||
EventBus.Command[PlayerMovementEvent]
|
||||
]
|
||||
playerEventBus: GameEventBus[PlayerEvent]
|
||||
) = {
|
||||
// val name = "analogMovementEventsGenerator"
|
||||
inputManager
|
||||
@ -213,7 +210,7 @@ object GameInputHandler {
|
||||
|
||||
def generateCameraEvents(
|
||||
inputManager: InputManager,
|
||||
playerCameraEventBus: ActorRef[EventBus.Command[PlayerCameraEvent]]
|
||||
playerEventBus: ActorRef[EventBus.Command[PlayerEvent]]
|
||||
) = {
|
||||
val name = "cameraMovementEventsGenerator"
|
||||
inputManager
|
||||
@ -223,28 +220,28 @@ object GameInputHandler {
|
||||
analogEvent.binding match {
|
||||
case PlayerCameraInput.CameraRotateLeft =>
|
||||
me.Task(
|
||||
playerCameraEventBus ! EventBus.Publish(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerCameraEvent.CameraLeft,
|
||||
name
|
||||
)
|
||||
)
|
||||
case PlayerCameraInput.CameraRotateRight =>
|
||||
me.Task(
|
||||
playerCameraEventBus ! EventBus.Publish(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerCameraEvent.CameraRight,
|
||||
name
|
||||
)
|
||||
)
|
||||
case PlayerCameraInput.CameraRotateUp =>
|
||||
me.Task(
|
||||
playerCameraEventBus ! EventBus.Publish(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerCameraEvent.CameraMovedUp,
|
||||
name
|
||||
)
|
||||
)
|
||||
case PlayerCameraInput.CameraRotateDown =>
|
||||
me.Task(
|
||||
playerCameraEventBus ! EventBus.Publish(
|
||||
playerEventBus ! EventBus.Publish(
|
||||
PlayerCameraEvent.CameraMovedDown,
|
||||
name
|
||||
)
|
||||
|
@ -56,7 +56,7 @@ object CanMove {
|
||||
inst.setWalkDirection(Vector3f.ZERO)
|
||||
}
|
||||
|
||||
implicit val implCanMoveForGeom = new CanMove[Spatial] with LazyLogging {
|
||||
implicit val implCanMoveForSpatial = new CanMove[Spatial] with LazyLogging {
|
||||
override def move(
|
||||
inst: Spatial,
|
||||
direction: ImVector3f,
|
||||
|
@ -0,0 +1,61 @@
|
||||
package wow.doge.mygame.game.subsystems.movement
|
||||
|
||||
import com.jme3.bullet.control.BetterCharacterControl
|
||||
import com.jme3.math.FastMath
|
||||
import com.jme3.math.Quaternion
|
||||
import com.jme3.math.Vector3f
|
||||
import monix.eval.Coeval
|
||||
import wow.doge.mygame.implicits._
|
||||
import wow.doge.mygame.math.ImVector3f
|
||||
import wow.doge.mygame.subsystems.movement.RotateDir
|
||||
|
||||
// experiment to see if it would be useful to use an effect wrapper for a typeclass like this
|
||||
trait CanMove2[-A, F[_]] {
|
||||
// def getDirection(cam: Camera, cardinalDir: CardinalDirection): ImVector3f
|
||||
def move(inst: A, direction: ImVector3f, speedFactor: Float = 20f): F[Unit]
|
||||
def location(inst: A): F[ImVector3f]
|
||||
def jump(inst: A): F[Unit]
|
||||
def stop(inst: A): F[Unit]
|
||||
def rotate(inst: A, rotateDir: RotateDir): F[Unit]
|
||||
}
|
||||
|
||||
object CanMove2 {
|
||||
implicit val implCanMoveForBetterCharacterControl =
|
||||
new CanMove2[BetterCharacterControl, Coeval] {
|
||||
override def move(
|
||||
inst: BetterCharacterControl,
|
||||
direction: ImVector3f,
|
||||
speedFactor: Float = 20f
|
||||
): Coeval[Unit] =
|
||||
Coeval {
|
||||
val dir = direction.mutable.normalizeLocal()
|
||||
inst.setViewDirection(dir.negate())
|
||||
inst.setWalkDirection(dir.mult(speedFactor))
|
||||
}
|
||||
override def location(inst: BetterCharacterControl) =
|
||||
Coeval(inst.getSpatial().getLocalTranslation().immutable)
|
||||
override def jump(inst: BetterCharacterControl): Coeval[Unit] =
|
||||
Coeval(inst.jump())
|
||||
override def rotate(
|
||||
inst: BetterCharacterControl,
|
||||
rotateDir: RotateDir
|
||||
): Coeval[Unit] =
|
||||
Coeval {
|
||||
val q =
|
||||
rotateDir match {
|
||||
case RotateDir.Left =>
|
||||
new Quaternion()
|
||||
.fromAngleNormalAxis(5 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y)
|
||||
case RotateDir.Right =>
|
||||
new Quaternion()
|
||||
.fromAngleAxis(-5 * FastMath.DEG_TO_RAD, Vector3f.UNIT_Y)
|
||||
}
|
||||
|
||||
val tmp = new Vector3f()
|
||||
inst.getViewDirection(tmp)
|
||||
inst.setViewDirection(q.mult(tmp))
|
||||
}
|
||||
override def stop(inst: BetterCharacterControl) =
|
||||
Coeval(inst.setWalkDirection(Vector3f.ZERO))
|
||||
}
|
||||
}
|
@ -39,7 +39,7 @@ object ImMovementActor {
|
||||
// ]
|
||||
val camera: Camera
|
||||
) {
|
||||
def create: Behavior[Command] =
|
||||
def behavior: Behavior[Command] =
|
||||
Behaviors.setup(ctx => new ImMovementActor(ctx, this).receive(State()))
|
||||
}
|
||||
|
||||
|
@ -24,11 +24,11 @@ class EventsModule(spawnProtocol: ActorSystem[SpawnProtocol.Command]) {
|
||||
|
||||
lazy val eventBusLogger = SLogger[EventBus[_]]
|
||||
|
||||
lazy val playerMovementEventBusTask =
|
||||
createEventBus[PlayerMovementEvent]("movementEventBus")
|
||||
lazy val playerEventBusTask =
|
||||
createEventBus[PlayerEvent]("playerEventBus")
|
||||
|
||||
lazy val playerCameraEventBusTask =
|
||||
createEventBus[PlayerCameraEvent]("playerCameraEventBus", Level.DEBUG)
|
||||
// lazy val playerCameraEventBusTask =
|
||||
// createEventBus[PlayerCameraEvent]("playerCameraEventBus", Level.DEBUG)
|
||||
|
||||
lazy val tickEventBusTask =
|
||||
createEventBus[TickEvent]("tickEventBus", Level.TRACE)
|
||||
|
@ -19,6 +19,13 @@ import groovy.util.GroovyScriptEngine
|
||||
import org.slf4j.event.Level
|
||||
|
||||
object ScriptActor {
|
||||
|
||||
/**
|
||||
* aka script representation
|
||||
*/
|
||||
sealed trait ScriptTag
|
||||
type ScriptObject = Any @@ ScriptTag
|
||||
|
||||
trait Kotlin
|
||||
type KotlinScriptEngine = ScriptEngine @@ Kotlin
|
||||
|
||||
@ -26,7 +33,7 @@ object ScriptActor {
|
||||
sealed trait Command
|
||||
final case class CompileAny(
|
||||
path: os.Path,
|
||||
result: ActorRef[Either[Error, Any]]
|
||||
result: ActorRef[Either[Error, ScriptObject]]
|
||||
) extends Command
|
||||
|
||||
final case class CompileAll(
|
||||
@ -145,15 +152,21 @@ class ScriptActor(
|
||||
Behaviors.same
|
||||
}
|
||||
|
||||
def getScript(path: os.Path): Either[Error, Any] =
|
||||
def getScript(path: os.Path): Either[Error, ScriptObject] =
|
||||
determineScriptType(path) match {
|
||||
case Right(ScalaType) =>
|
||||
runScala(path, scalaRunner).flatMap(ensureReturnedObjectNotNull)
|
||||
runScala(path, scalaRunner)
|
||||
.flatMap(ensureReturnedObjectNotNull)
|
||||
.map(_.taggedWith[ScriptTag])
|
||||
case Right(KotlinType) =>
|
||||
runKotlin(path, kotlinRunner).flatMap(ensureReturnedObjectNotNull)
|
||||
runKotlin(path, kotlinRunner)
|
||||
.flatMap(ensureReturnedObjectNotNull)
|
||||
.map(_.taggedWith[ScriptTag])
|
||||
case Right(GroovyType) =>
|
||||
runGroovy(path, groovyRunner).flatMap(ensureReturnedObjectNotNull)
|
||||
case l @ Left(err) => l
|
||||
runGroovy(path, groovyRunner)
|
||||
.flatMap(ensureReturnedObjectNotNull)
|
||||
.map(_.taggedWith[ScriptTag])
|
||||
case l @ Left(err) => l.map(_.taggedWith[ScriptTag])
|
||||
}
|
||||
|
||||
type LOL = Map[os.Path, Either[wow.doge.mygame.state.ScriptActor.Error, Any]]
|
||||
|
@ -15,13 +15,11 @@ import akka.util.Timeout
|
||||
import com.typesafe.scalalogging.Logger
|
||||
import org.slf4j.event.Level
|
||||
import wow.doge.mygame.state.ScriptActor
|
||||
import scala.concurrent.duration._
|
||||
import ScriptActor.ScriptObject
|
||||
|
||||
object ScriptCachingActor {
|
||||
|
||||
/**
|
||||
* aka script representation
|
||||
*/
|
||||
type ScriptObject = Any
|
||||
type ScriptsMap = Map[os.Path, ScriptObject]
|
||||
type ScriptResult = Either[ScriptActor.Error, ScriptObject]
|
||||
|
||||
@ -162,7 +160,6 @@ class ScriptCachingActor(
|
||||
// Behaviors.same
|
||||
|
||||
case DelegateToChild(scriptActor, scriptPath, requester) =>
|
||||
import scala.concurrent.duration._
|
||||
implicit val timeout = Timeout(15.seconds)
|
||||
// child ! ScriptActor.CompileAny(scriptPath, requester)
|
||||
askChildForScriptCompilation(
|
||||
|
Loading…
Reference in New Issue
Block a user