Execute on called at one place instead of many

This commit is contained in:
Rohan Sircar 2021-01-10 12:36:04 +05:30
parent 6ccbf7e11d
commit 978215b510
3 changed files with 44 additions and 53 deletions

View File

@ -101,7 +101,10 @@ class MainApp(
bulletAppState <- Task(new BulletAppState()) bulletAppState <- Task(new BulletAppState())
_ <- Task(stateManager.attach(bulletAppState)) _ <- Task(stateManager.attach(bulletAppState))
_ <- logger.info("Initializing console stream") _ <- logger.info("Initializing console stream")
_ <- wire[MainAppDelegate].init(gameApp.scheduler) _ <-
wire[MainAppDelegate]
.init(gameApp.scheduler)
.executeOn(gameApp.scheduler)
} yield gameAppFib } yield gameAppFib
} }
@ -165,7 +168,6 @@ class MainAppDelegate(
rootNode, rootNode,
bulletAppState.physicsSpace bulletAppState.physicsSpace
) )
.executeOn(appScheduler)
_ <- createPlayerController(appScheduler) _ <- createPlayerController(appScheduler)
.absorbWith(e => DummyException("boom")) .absorbWith(e => DummyException("boom"))
.onErrorRestart(3) .onErrorRestart(3)
@ -240,55 +242,44 @@ class MainAppDelegate(
def createTestNpc( def createTestNpc(
appScheduler: monix.execution.Scheduler, appScheduler: monix.execution.Scheduler,
npcName: String npcName: String
) = ) = {
// : IO[PlayerController.Error, Unit] = val initialPos = ImVector3f(50, 5, 0)
{ val npcPhysicsControl = new BetterCharacterControl(1.5f, 6f, 1f)
val initialPos = ImVector3f(50, 5, 0) // (1f, 2.1f, 10f)
// val modelPath = os.rel / "Models" / "Jaime" / "Jaime.j3o" .withJumpForce(ImVector3f(0, 5f, 0))
val npcPhysicsControl = new BetterCharacterControl(1.5f, 6f, 1f) val mbNpcNode = PlayerController.Defaults.defaultNpcNode(
// (1f, 2.1f, 10f) assetManager,
.withJumpForce(ImVector3f(0, 5f, 0)) initialPos,
// val npcMovementActor = AkkaUtils.spawnActorL2( npcPhysicsControl,
// new NpcMovementActor2.Props( npcName
// initialPos, )
// tickEventBus, val npcActorTask = AkkaUtils.spawnActorL(
// npcPhysicsControl NpcActorSupervisor
// ).behavior, .Props(
// s"${npcName}-npcMovementActor" new NpcMovementActor.Props(
// ) enqueueR,
val mbNpcNode = PlayerController.Defaults.defaultNpcNode( initialPos,
assetManager, // tickEventBus,
initialPos, npcPhysicsControl
npcPhysicsControl, ).behavior,
npcName npcName,
) initialPos
val npcActorTask = AkkaUtils.spawnActorL( )
NpcActorSupervisor .behavior,
.Props( s"${npcName}-npcActorSupervisor"
new NpcMovementActor.Props( )
enqueueR, // .taggedWith[PlayerControllerTags.PlayerTag]
initialPos,
// tickEventBus,
npcPhysicsControl
).behavior,
npcName,
initialPos
)
.behavior,
s"${npcName}-npcActorSupervisor"
)
// .taggedWith[PlayerControllerTags.PlayerTag]
for { for {
npcNode <- IO.fromEither(mbNpcNode) npcNode <- IO.fromEither(mbNpcNode)
npcActor <- npcActorTask npcActor <- npcActorTask
_ <- IO { _ <- IO {
physicsSpace += npcPhysicsControl physicsSpace += npcPhysicsControl
physicsSpace += npcNode physicsSpace += npcNode
rootNode += npcNode rootNode += npcNode
} }
} yield npcActor } yield npcActor
} }
} }

View File

@ -93,7 +93,7 @@ object GameApp {
def resource( def resource(
logger: Logger[Task], logger: Logger[Task],
jmeScheduler: Scheduler, jmeThread: Scheduler,
schedulers: Schedulers schedulers: Schedulers
) = ) =
Resource.make( Resource.make(
@ -112,7 +112,7 @@ object GameApp {
app.setSettings(settings) app.setSettings(settings)
} }
gameApp <- Task(new GameApp(logger, app)) gameApp <- Task(new GameApp(logger, app))
fib <- gameApp.start.executeOn(jmeScheduler).start fib <- gameApp.start.executeOn(jmeThread).start
_ <- Task.fromCancelablePromise(startSignal) _ <- Task.fromCancelablePromise(startSignal)
} yield gameApp -> fib } yield gameApp -> fib
)(_._2.cancel) )(_._2.cancel)

View File

@ -96,7 +96,7 @@ object PlayerController {
} }
} yield ()) } yield ())
.onErrorHandleWith(e => IO.raiseError(GenericError(e.getMessage()))) .onErrorHandleWith(e => IO.raiseError(GenericError(e.getMessage())))
.executeOn(appScheduler) // .executeOn(appScheduler)
} }
def apply( def apply(