forked from nova/jmonkey-test
Rohan Sircar
4 years ago
48 changed files with 834 additions and 940 deletions
-
17build.sbt
-
2src/main/resources/dep.sc
-
3src/main/resources/hello.groovy
-
36src/main/resources/hello.main.kts
-
35src/main/resources/hello.sc
-
5src/main/resources/hello2.main.kts
-
108src/main/resources/hello2.sc
-
3src/main/scala/com/jme3/input/package.scala
-
3src/main/scala/com/jme3/syntax/package.scala
-
22src/main/scala/org/slf4j/impl/StaticLoggerBuilder.scala
-
27src/main/scala/wow/doge/mygame/ActorSystemModule.scala
-
121src/main/scala/wow/doge/mygame/Main.scala
-
139src/main/scala/wow/doge/mygame/MainApp.scala
-
120src/main/scala/wow/doge/mygame/MainModule.scala
-
2src/main/scala/wow/doge/mygame/executors/ExecutorsModule.scala
-
26src/main/scala/wow/doge/mygame/executors/GUIExecutor.scala
-
2src/main/scala/wow/doge/mygame/executors/Schedulers.scala
-
14src/main/scala/wow/doge/mygame/game/GameApp.scala
-
35src/main/scala/wow/doge/mygame/game/GameApp2.scala
-
38src/main/scala/wow/doge/mygame/game/GameAppActor.scala
-
42src/main/scala/wow/doge/mygame/game/GameModule.scala
-
43src/main/scala/wow/doge/mygame/game/GameSystemsInitializer.scala
-
4src/main/scala/wow/doge/mygame/game/appstates/MyBaseState.scala
-
12src/main/scala/wow/doge/mygame/game/appstates/PlayerMovementState.scala
-
17src/main/scala/wow/doge/mygame/game/appstates/ScriptingEngineState.scala
-
10src/main/scala/wow/doge/mygame/game/appstates/TestAppState.scala
-
2src/main/scala/wow/doge/mygame/game/components/Position.scala
-
31src/main/scala/wow/doge/mygame/game/nodes/PlayerActorSupervisor.scala
-
2src/main/scala/wow/doge/mygame/game/nodes/PlayerCameraActor.scala
-
60src/main/scala/wow/doge/mygame/game/nodes/PlayerController.scala
-
12src/main/scala/wow/doge/mygame/game/nodes/PlayerEventListeners.scala
-
135src/main/scala/wow/doge/mygame/game/subsystems/input/GameInputHandler.scala
-
3src/main/scala/wow/doge/mygame/game/subsystems/input/InputEnums.scala
-
57src/main/scala/wow/doge/mygame/game/subsystems/level/DefaultGameLevel.scala
-
34src/main/scala/wow/doge/mygame/game/subsystems/level/Level.scala
-
6src/main/scala/wow/doge/mygame/game/subsystems/movement/CanMove.scala
-
32src/main/scala/wow/doge/mygame/game/subsystems/movement/MovementActor.scala
-
5src/main/scala/wow/doge/mygame/implicits/EntityQuery.scala
-
206src/main/scala/wow/doge/mygame/implicits/package.scala
-
3src/main/scala/wow/doge/mygame/subsystems/events/EventBus.scala
-
68src/main/scala/wow/doge/mygame/subsystems/events/EventsModule.scala
-
64src/main/scala/wow/doge/mygame/subsystems/events/EventsModule2.scala
-
45src/main/scala/wow/doge/mygame/subsystems/moddingsystem/ModdingSystem.scala
-
21src/main/scala/wow/doge/mygame/subsystems/scriptsystem/ScriptActor.scala
-
19src/main/scala/wow/doge/mygame/subsystems/scriptsystem/ScriptCachingActor.scala
-
58src/main/scala/wow/doge/mygame/subsystems/scriptsystem/ScriptSystemModule.scala
-
6src/main/scala/wow/doge/mygame/utils/AkkaUtils.scala
-
7src/main/scala/wow/doge/mygame/utils/JFXConsoleStream.scala
@ -1,2 +0,0 @@ |
|||
// println("hello from dep") |
|||
class Test(x: Int) |
@ -1,3 +0,0 @@ |
|||
println "hello" |
|||
|
|||
this |
@ -1,36 +0,0 @@ |
|||
// @file:Import("src/main/resources/hello2.main.kts") |
|||
@file:DependsOn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0-M1") |
|||
@file:DependsOn("/home/rohan/.m2/repository/wow/doge/game/1.0-SNAPSHOT/game-1.0-SNAPSHOT.jar") |
|||
@file:DependsOn("/home/rohan/.ivy2/local/wow.doge/mygame_2.13/1.0-SNAPSHOT/jars/mygame_2.13.jar") |
|||
|
|||
import wow.doge.game.types.GameScript |
|||
|
|||
import kotlinx.coroutines.delay |
|||
import kotlinx.coroutines.launch |
|||
import kotlinx.coroutines.runBlocking |
|||
import kotlin.random.Random |
|||
|
|||
import wow.doge.mygame.components.Test |
|||
|
|||
|
|||
//println(x * 2) |
|||
|
|||
println("hello from main script") |
|||
|
|||
class GameScriptImpl : GameScript { |
|||
override fun start() = runBlocking { |
|||
for(x in 0 until 5) { |
|||
launch { |
|||
val del = Random.nextLong(20, 100) |
|||
|
|||
delay(del) |
|||
println("hello from start $x, delay is $del") |
|||
} |
|||
} |
|||
} |
|||
override fun stop() {println("hello from stop")} |
|||
} |
|||
|
|||
GameScriptImpl() |
|||
|
|||
class MyTest : Test() |
@ -1,35 +0,0 @@ |
|||
// #!/usr/bin/env amm |
|||
|
|||
// import coursierapi.MavenRepository |
|||
|
|||
// interp.repositories.update( |
|||
// interp.repositories() ::: List( |
|||
// MavenRepository.of("file://home/rohan/.m2/repository") |
|||
// ) |
|||
// ) |
|||
|
|||
// @ |
|||
// import $repo.`https://jcenter.bintray.com` |
|||
// // import $repo.`https://bintray.com/jmonkeyengine/com.jme3` |
|||
// import $file.dep |
|||
// import $ivy.`org.jmonkeyengine:jme3-core:3.2.4-stable` |
|||
// import $ivy.`wow.doge:game:1.0-SNAPSHOT` |
|||
// import wow.doge.game.types.GameScript |
|||
// import com.jme3.scene.control.Control |
|||
|
|||
// println("hello from script") |
|||
|
|||
// class Scr extends GameScript { |
|||
// def start(): Unit = println("hello from start") |
|||
|
|||
// def stop(): Unit = println("hello from stop") |
|||
// } |
|||
|
|||
// // class SomeClass extends Control {} |
|||
|
|||
// @main |
|||
// def main(): GameScript = new Scr() |
|||
import $file.dep |
|||
import dep.Test |
|||
|
|||
new Test(1) |
@ -1,5 +0,0 @@ |
|||
println("hello from dep") |
|||
|
|||
class Test(val x: Int) |
|||
|
|||
var x = 2 |
@ -1,108 +0,0 @@ |
|||
#!/usr/bin/env amm |
|||
// scala 2.13.3 |
|||
|
|||
// import coursierapi.MavenRepository |
|||
|
|||
// interp.repositories.update( |
|||
// interp.repositories() ::: List( |
|||
// MavenRepository.of("file://home/rohan/.m2/repository") |
|||
// ) |
|||
// ) |
|||
|
|||
// @ |
|||
import $repo.`https://jcenter.bintray.com` |
|||
// import $repo.`https://bintray.com/jmonkeyengine/com.jme3` |
|||
// import $file.dep |
|||
import $ivy.`org.jmonkeyengine:jme3-core:3.2.4-stable` |
|||
// import $ivy.`wow.doge:game:1.0-SNAPSHOT` |
|||
import $ivy.`wow.doge::mygame:1.0-SNAPSHOT` |
|||
// import wow.doge.game.types.GameScript |
|||
import com.jme3.scene.control.Control |
|||
|
|||
// println("hello from script") |
|||
|
|||
// class Scr extends GameScript { |
|||
// def start(): Unit = println("hello from start") |
|||
|
|||
// def stop(): Unit = println("hello from stop") |
|||
// } |
|||
|
|||
// // class SomeClass extends Control {} |
|||
|
|||
// @main |
|||
// def main(): GameScript = new Scr() |
|||
import com.simsilica.es.base.DefaultEntityData |
|||
import com.simsilica.es.EntityData |
|||
import com.jme3.app.Application |
|||
import wow.doge.mygame.game.Implicits._ |
|||
import wow.doge.mygame.components.TestComponent |
|||
import com.jme3.scene.shape.Box |
|||
import com.jme3.scene.Geometry |
|||
import com.jme3.material.Material |
|||
import com.jme3.math.ColorRGBA |
|||
import com.jme3.asset.AssetManager |
|||
import com.jme3.math.Vector3f |
|||
import wow.doge.mygame.state._ |
|||
class TestAppState( |
|||
// private var _entity: Option[EntityData] = Some(new DefaultEntityData()) |
|||
) extends MyBaseState { |
|||
protected lazy val b = new Box(1, 1, 1) |
|||
protected lazy val geom = new Geometry("Box", b) |
|||
protected lazy val mat = Material( |
|||
assetManager = assetManager, |
|||
path = "Common/MatDefs/Misc/Unshaded.j3md" |
|||
) |
|||
|
|||
// def entity = _entity |
|||
// override def initialize(app: Application): Unit = { |
|||
// super.initialize(app) |
|||
|
|||
// } |
|||
|
|||
override def init() = { |
|||
entityData |
|||
.createEntity() |
|||
.withComponents(TestComponent()) |
|||
// entityData.setComponents(x, TestComponent()) |
|||
val es = entityData.getEntities(classOf[TestComponent]) |
|||
println(es) |
|||
geom.setMaterial(mat) |
|||
rootNode.attachChild(geom) |
|||
|
|||
// geom.foreach(e => { |
|||
|
|||
// }) |
|||
} |
|||
|
|||
override def update(tpf: Float) = { |
|||
geom.rotate(0, 0.5f * tpf, 0) |
|||
geom.move(new Vector3f(0, 1 * tpf, 0)) |
|||
} |
|||
|
|||
override def cleanup(app: Application): Unit = { |
|||
// _entity.map(_.close()) |
|||
// _entity = None |
|||
} |
|||
|
|||
override def onEnable(): Unit = {} |
|||
|
|||
override def onDisable(): Unit = {} |
|||
|
|||
} |
|||
|
|||
object Material { |
|||
def apply( |
|||
color: String = "Color", |
|||
colorType: com.jme3.math.ColorRGBA = ColorRGBA.Blue, |
|||
assetManager: AssetManager, |
|||
path: String |
|||
): Material = { |
|||
val mat = |
|||
new Material(assetManager, path) |
|||
mat.setColor(color, colorType) |
|||
mat |
|||
} |
|||
} |
|||
|
|||
@main |
|||
def main(): MyBaseState = new TestAppState() |
@ -1,13 +1,12 @@ |
|||
package com.jme3 |
|||
|
|||
|
|||
/** |
|||
* Created by Brandon Barker on 6/21/17. |
|||
*/ |
|||
package object syntax { |
|||
|
|||
@specialized def discard[A](evaluateForSideEffectOnly: A): Unit = { |
|||
val _: A = evaluateForSideEffectOnly |
|||
val _ = evaluateForSideEffectOnly |
|||
() //Return unit to prevent warning due to discarding value |
|||
} |
|||
|
|||
|
@ -1,27 +0,0 @@ |
|||
package wow.doge.mygame |
|||
|
|||
import akka.actor.typed.ActorSystem |
|||
import cats.effect.Resource |
|||
import monix.bio.Task |
|||
import io.odin.Logger |
|||
import wow.doge.mygame.game.GameApp |
|||
import wow.doge.mygame.executors.Schedulers |
|||
|
|||
trait ActorSystemModule { |
|||
|
|||
def logger: Logger[Task] |
|||
def app: GameApp |
|||
def schedulers: Schedulers |
|||
|
|||
lazy val actorsResource = |
|||
Resource.make(logger.info("Creating Actor System") >> Task { |
|||
ActorSystem( |
|||
RootActor(app, schedulers, logger = logger), |
|||
name = "GameActorSystem" |
|||
) |
|||
})(sys => |
|||
logger.info("Shutting down actor system") >> Task( |
|||
sys.terminate() |
|||
) |
|||
) |
|||
} |
@ -0,0 +1,139 @@ |
|||
package wow.doge.mygame |
|||
|
|||
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 wow.doge.mygame.events.EventBus |
|||
import wow.doge.mygame.game.GameApp2 |
|||
import wow.doge.mygame.game.nodes.Player |
|||
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.EventsModule2 |
|||
import wow.doge.mygame.subsystems.events.PlayerCameraEvent |
|||
import wow.doge.mygame.game.subsystems.level.DefaultGameLevel |
|||
import com.jme3.renderer.ViewPort |
|||
import wow.doge.mygame.subsystems.scriptsystem.ScriptSystemResource |
|||
import wow.doge.mygame.subsystems.scriptsystem.ScriptInitMode |
|||
|
|||
class MainApp( |
|||
logger: Logger[Task], |
|||
gameApp: GameApp2, |
|||
spawnProtocol: ActorSystem[SpawnProtocol.Command], |
|||
jmeThread: monix.execution.Scheduler |
|||
)(implicit |
|||
@annotation.unused timeout: Timeout, |
|||
@annotation.unused scheduler: Scheduler |
|||
) { |
|||
|
|||
lazy val scriptSystemInit = |
|||
new ScriptSystemResource(os.pwd, spawnProtocol, ScriptInitMode.Eager).init |
|||
|
|||
lazy val gameInit: Task[Unit] = for { |
|||
eventsModule <- Task(new EventsModule2(spawnProtocol)) |
|||
playerMovementEventBus <- eventsModule.playerMovementEventBusTask |
|||
playerCameraEventBus <- eventsModule.playerCameraEventBusTask |
|||
gameAppFib <- gameApp.start.executeOn(jmeThread).start |
|||
/** |
|||
* schedule a fiber to run on the JME thread and wait for it's completion |
|||
* before proceeding forward, as a signal that JME thread has been |
|||
* initialized, otherwise we'll get NPEs trying to access the fields |
|||
* of the game app |
|||
*/ |
|||
initFib <- gameApp.enqueueL(() => Task("done")).start |
|||
_ <- initFib.join |
|||
inputManager <- gameApp.inputManager |
|||
assetManager <- gameApp.assetManager |
|||
stateManager <- gameApp.stateManager |
|||
camera <- gameApp.camera |
|||
rootNode <- gameApp.rootNode |
|||
enqueueR <- Task(gameApp.enqueue _) |
|||
viewPort <- gameApp.viewPort |
|||
bulletAppState <- Task(new BulletAppState()) |
|||
appScheduler <- Task(gameApp.scheduler) |
|||
// enqueueL <- Task(gameApp.enqueueL _) |
|||
_ <- wire[MainAppDelegate].init(gameApp.scheduler) |
|||
_ <- gameAppFib.join |
|||
} yield () |
|||
|
|||
lazy val program = for { |
|||
scriptSystem <- scriptSystemInit |
|||
game <- gameInit |
|||
} yield () |
|||
} |
|||
|
|||
class MainAppDelegate( |
|||
gameApp: GameApp2, |
|||
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, |
|||
viewPort: ViewPort, |
|||
enqueueR: Function1[() => Unit, Unit], |
|||
rootNode: Ref[Task, Node], |
|||
bulletAppState: BulletAppState |
|||
)(implicit |
|||
@annotation.unused timeout: Timeout, |
|||
@annotation.unused scheduler: Scheduler |
|||
) { |
|||
|
|||
def init(appScheduler: monix.execution.Scheduler) = |
|||
for { |
|||
_ <- loggerL.info("Initializing Systems") |
|||
_ <- Task(stateManager.attach(bulletAppState)) |
|||
_ <- Task( |
|||
assetManager.registerLocator( |
|||
(os.rel / "assets" / "town.zip"), |
|||
classOf[ZipLocator] |
|||
) |
|||
) |
|||
_ <- DefaultGameLevel(assetManager, viewPort) |
|||
.addToGame( |
|||
rootNode, |
|||
bulletAppState.physicsSpace |
|||
) |
|||
.executeOn(appScheduler) |
|||
_ <- createPlayerController(appScheduler).startAndForget.onErrorRestart(3) |
|||
_ <- wire[GameInputHandler.Props].begin.onErrorRestart(3) |
|||
} yield () |
|||
|
|||
def createPlayerController( |
|||
appScheduler: monix.execution.Scheduler |
|||
// 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[Player] |
|||
@annotation.unused |
|||
val modelPath = os.rel / "Models" / "Jaime" / "Jaime.j3o" |
|||
wire[PlayerController.Props].create |
|||
} |
|||
} |
@ -0,0 +1,35 @@ |
|||
package wow.doge.mygame.game |
|||
|
|||
import cats.effect.concurrent.Ref |
|||
import com.jme3.app.state.AppStateManager |
|||
import com.jme3.asset.AssetManager |
|||
import com.jme3.input.InputManager |
|||
import monix.bio.IO |
|||
import monix.bio.Task |
|||
|
|||
sealed trait Error |
|||
case object FlyCamNotExists extends Error |
|||
|
|||
class GameApp2(app: GameApp) { |
|||
def stateManager: Task[AppStateManager] = Task(app.getStateManager()) |
|||
def inputManager: Task[InputManager] = Task(app.getInputManager()) |
|||
def assetManager: Task[AssetManager] = Task(app.getAssetManager()) |
|||
def guiNode = Ref[Task].of(app.getGuiNode()) |
|||
def flyCam = |
|||
IO(app.getFlyByCamera()).onErrorHandleWith(_ => |
|||
IO.raiseError(FlyCamNotExists) |
|||
) |
|||
def camera = Task(app.getCamera()) |
|||
def viewPort = Task(app.getViewPort()) |
|||
def rootNode = Ref[Task].of(app.getRootNode()) |
|||
def enqueue(cb: () => Unit) = |
|||
app.enqueue(new Runnable { |
|||
override def run() = cb() |
|||
}) |
|||
def enqueueL[T](cb: () => T): Task[T] = app.enqueueL(cb) |
|||
|
|||
def start = Task(app.start()) |
|||
def stop = Task(app.stop()) |
|||
def scheduler = app.scheduler |
|||
|
|||
} |
@ -1,6 +1,6 @@ |
|||
package wow.doge.mygame.components |
|||
|
|||
import com.simsilica.es.EntityComponent; |
|||
import com.simsilica.es.EntityComponent |
|||
import wow.doge.mygame.math.ImVector3f |
|||
|
|||
final case class Position(location: ImVector3f) extends EntityComponent |
@ -0,0 +1,34 @@ |
|||
package wow.doge.mygame.game.subsystems.level |
|||
|
|||
import com.jme3.bullet.control.RigidBodyControl |
|||
import com.jme3.light.AmbientLight |
|||
import com.jme3.light.DirectionalLight |
|||
import com.jme3.scene.Spatial |
|||
import com.jme3.bullet.PhysicsSpace |
|||
import cats.effect.concurrent.Ref |
|||
import monix.bio.Task |
|||
import com.jme3.scene.Node |
|||
import wow.doge.mygame.implicits._ |
|||
|
|||
class Level( |
|||
model: Spatial, |
|||
physicsControl: RigidBodyControl, |
|||
ambientLight: AmbientLight, |
|||
directionalLight: DirectionalLight |
|||
) { |
|||
def addToGame(rootNode: Ref[Task, Node], physicsSpace: PhysicsSpace) = { |
|||
for { |
|||
_ <- rootNode.update(_ :+ model) |
|||
_ <- rootNode.update { r => |
|||
r.addLight(ambientLight) |
|||
r |
|||
} |
|||
_ <- rootNode.update { r => |
|||
r.addLight(directionalLight) |
|||
r |
|||
} |
|||
_ <- Task(physicsSpace += model) |
|||
_ <- Task(physicsSpace += physicsControl) |
|||
} yield () |
|||
} |
|||
} |
@ -1,64 +0,0 @@ |
|||
package wow.doge.mygame.subsystems.events |
|||
|
|||
import akka.actor.typed.ActorRef |
|||
import akka.actor.typed.SpawnProtocol |
|||
import wow.doge.mygame.implicits._ |
|||
import akka.actor.typed.Props |
|||
import akka.actor.typed.LogOptions |
|||
import com.typesafe.scalalogging.{Logger => SLLogger} |
|||
import wow.doge.mygame.events.EventBus |
|||
import akka.actor.typed.scaladsl.Behaviors |
|||
import scala.concurrent.duration._ |
|||
import akka.util.Timeout |
|||
import akka.actor.typed.SupervisorStrategy |
|||
import cats.effect.Resource |
|||
import akka.actor.typed.ActorSystem |
|||
import monix.bio.Task |
|||
import org.slf4j.event.Level |
|||
import wow.doge.mygame.subsystems.events.EntityMovementEvent.PlayerMovementEvent |
|||
|
|||
class EventsModule2( |
|||
spawnProtocol: ActorSystem[SpawnProtocol.Command] |
|||
) { |
|||
private implicit lazy val s = spawnProtocol.scheduler |
|||
|
|||
private implicit lazy val timeout = Timeout(1.second) |
|||
|
|||
private lazy val eventBusLogger = SLLogger[EventBus[_]] |
|||
|
|||
private lazy val playerMovementEventBusTask = |
|||
createEventBus[PlayerMovementEvent]("movementEventBus") |
|||
|
|||
private lazy val playerCameraEventBusTask = |
|||
createEventBus[PlayerCameraEvent]("playerCameraEventBus", Level.DEBUG) |
|||
|
|||
def createEventBus[T](busName: String, logLevel: Level = Level.DEBUG) = |
|||
spawnProtocol.askL( |
|||
SpawnProtocol.Spawn[EventBus.Command[T]]( |
|||
Behaviors.logMessages( |
|||
logOptions = LogOptions() |
|||
.withLevel(logLevel) |
|||
.withLogger(eventBusLogger.underlying), |
|||
Behaviors |
|||
.supervise(EventBus[T]()) |
|||
.onFailure[Exception](SupervisorStrategy.restart) |
|||
), |
|||
busName, |
|||
Props.empty, |
|||
_ |
|||
) |
|||
) |
|||
|
|||
type EventBuses = ( |
|||
ActorRef[ |
|||
EventBus.Command[EntityMovementEvent.PlayerMovementEvent], |
|||
], |
|||
ActorRef[EventBus.Command[PlayerCameraEvent]] |
|||
) |
|||
|
|||
val resource: Resource[Task, EventBuses] = |
|||
Resource.liftF(for { |
|||
playerMovementEventBus <- playerMovementEventBusTask |
|||
playerCameraEventBus <- playerCameraEventBusTask |
|||
} yield (playerMovementEventBus, playerCameraEventBus)) |
|||
} |
@ -1,23 +1,65 @@ |
|||
package wow.doge.mygame.subsystems.scriptsystem |
|||
|
|||
import wow.doge.mygame.utils.AkkaUtils |
|||
import cats.effect.Resource |
|||
import wow.doge.mygame.scriptsystem.ScriptCachingActor |
|||
import akka.actor.typed.ActorRef |
|||
import akka.actor.typed.Scheduler |
|||
import akka.actor.typed.SpawnProtocol |
|||
import akka.util.Timeout |
|||
import akka.actor.typed.Scheduler |
|||
import cats.effect.Resource |
|||
import wow.doge.mygame.scriptsystem.ScriptCachingActor |
|||
import wow.doge.mygame.utils.AkkaUtils |
|||
import monix.bio.Task |
|||
|
|||
/** |
|||
* Scripts can either be searched and compiled at startup (Eager mode) |
|||
* or compiled on demand (Lazy mode) |
|||
*/ |
|||
sealed trait ScriptInitMode |
|||
object ScriptInitMode { |
|||
case object Eager extends ScriptInitMode |
|||
case object Lazy extends ScriptInitMode |
|||
} |
|||
class ScriptSystemResource( |
|||
path: os.Path, |
|||
spawnProtocol: ActorRef[SpawnProtocol.Command] |
|||
spawnProtocol: ActorRef[SpawnProtocol.Command], |
|||
mode: ScriptInitMode = ScriptInitMode.Lazy |
|||
)(implicit timeout: Timeout, scheduler: Scheduler) { |
|||
def make = |
|||
Resource.liftF( |
|||
AkkaUtils.spawnActorL( |
|||
val make = { |
|||
// throw new Exception("boom") |
|||
findScriptFiles(os.pwd / "assets" / "scripts") |
|||
|
|||
lazy val scriptCacheActor = AkkaUtils.spawnActorL( |
|||
spawnProtocol, |
|||
"scriptCachingActor", |
|||
ScriptCachingActor() |
|||
) |
|||
|
|||
Resource.liftF(scriptCacheActor) |
|||
} |
|||
|
|||
val init = for { |
|||
scriptFiles <- Task(findScriptFiles(os.pwd / "assets" / "scripts")) |
|||
scriptCacheActor <- AkkaUtils.spawnActorL( |
|||
spawnProtocol, |
|||
"scriptCachingActor", |
|||
ScriptCachingActor() |
|||
) |
|||
} yield (scriptCacheActor) |
|||
|
|||
def findScriptFiles(wd: os.Path) = |
|||
os.walk |
|||
.stream(wd) |
|||
.filter(p => |
|||
os.isFile(p) && |
|||
(p.ext == "sc" || (p.baseName + "." + p.ext) |
|||
.contains(".main.kts") || p.ext == "groovy") |
|||
) |
|||
.toList |
|||
|
|||
// def findExternalScriptFiles = |
|||
// findScriptFiles(os.pwd / "assets" / "scripts") |
|||
// def findInternalScriptFiles = |
|||
// findScriptFiles((os.resource / "assets" / "scripts")) |
|||
|
|||
// def finalInternalScriptFiles = |
|||
} |
|||
// pwd / 'src / 'main / 'resources / 'assets / 'scripts |
Write
Preview
Loading…
Cancel
Save
Reference in new issue