From fc4db79a730848d33143d0d32b8665fa704609f6 Mon Sep 17 00:00:00 2001 From: davesmith00000 Date: Sat, 9 Nov 2024 23:15:14 +0000 Subject: [PATCH] Context to replace FrameContext --- .../scala/indigoextras/jobs/JobMarket.scala | 6 +- .../subsystems/AssetBundleLoader.scala | 6 +- .../indigoextras/subsystems/Automata.scala | 14 +- .../indigoextras/subsystems/FPSCounter.scala | 13 +- .../scala/indigoextras/ui/InputField.scala | 20 +- .../indigoextras/jobs/JobMarketTests.scala | 4 +- .../FakeSubSystemFrameContext.scala | 14 +- .../indigoextras/ui/InputFieldTests.scala | 6 +- .../src/main/scala/indigo/IndigoDemo.scala | 6 +- .../src/main/scala/indigo/IndigoGame.scala | 6 +- .../src/main/scala/indigo/IndigoSandbox.scala | 6 +- .../src/main/scala/indigo/IndigoShader.scala | 6 +- .../indigo/entry/ScenesFrameProcessor.scala | 38 ++-- .../indigo/entry/StandardFrameProcessor.scala | 25 ++- .../scala/indigo/gameengine/GameEngine.scala | 2 +- .../src/main/scala/indigo/package.scala | 7 +- .../scala/indigo/scenes/SceneContext.scala | 25 +-- .../scala/indigo/scenes/SceneManager.scala | 38 ++-- .../main/scala/indigo/shared/Context.scala | 209 ++++++++++++++++++ .../scala/indigo/shared/FrameContext.scala | 71 ------ .../indigo/shared/subsystems/SubSystem.scala | 4 +- .../shared/subsystems/SubSystemContext.scala | 50 +++++ .../subsystems/SubSystemFrameContext.scala | 72 ------ .../subsystems/SubSystemsRegister.scala | 6 +- .../FakeSubSystemFrameContext.scala | 14 +- .../subsystems/PointsTrackerExample.scala | 6 +- .../scala/com/example/perf/PerfGame.scala | 6 +- .../main/scala/example/IndigoPhysics.scala | 6 +- .../src/main/scala/example/PhysicsScene.scala | 2 +- .../com/example/sandbox/SandboxGame.scala | 8 +- .../com/example/sandbox/SandboxView.scala | 8 +- .../example/sandbox/scenes/BoundsScene.scala | 36 +-- .../example/sandbox/scenes/CameraScene.scala | 8 +- .../sandbox/scenes/CaptureScreenScene.scala | 4 +- .../sandbox/scenes/ConfettiScene.scala | 4 +- .../example/sandbox/scenes/CratesScene.scala | 2 +- .../example/sandbox/scenes/LightsScene.scala | 8 +- .../sandbox/scenes/OriginalScene.scala | 4 +- .../sandbox/scenes/PathFindingScene.scala | 4 +- .../sandbox/scenes/RefractionScene.scala | 4 +- .../example/sandbox/scenes/ShapesScene.scala | 20 +- .../example/sandbox/scenes/TextBoxScene.scala | 4 +- .../sandbox/scenes/TimelineScene.scala | 6 +- .../com/example/sandbox/scenes/UiScene.scala | 2 +- .../main/scala/tyrian/TyrianSubSystem.scala | 6 +- .../main/scala/example/game/GameScene.scala | 4 +- .../scala/example/game/MyAwesomeGame.scala | 6 +- 47 files changed, 466 insertions(+), 360 deletions(-) create mode 100644 indigo/indigo/src/main/scala/indigo/shared/Context.scala delete mode 100644 indigo/indigo/src/main/scala/indigo/shared/FrameContext.scala create mode 100644 indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemContext.scala delete mode 100644 indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemFrameContext.scala diff --git a/indigo/indigo-extras/src/main/scala/indigoextras/jobs/JobMarket.scala b/indigo/indigo-extras/src/main/scala/indigoextras/jobs/JobMarket.scala index 40be8b4a1..759fb9b6d 100644 --- a/indigo/indigo-extras/src/main/scala/indigoextras/jobs/JobMarket.scala +++ b/indigo/indigo-extras/src/main/scala/indigoextras/jobs/JobMarket.scala @@ -5,7 +5,7 @@ import indigo.shared.datatypes.BindingKey import indigo.shared.events.GlobalEvent import indigo.shared.scenegraph.SceneUpdateFragment import indigo.shared.subsystems.SubSystem -import indigo.shared.subsystems.SubSystemFrameContext +import indigo.shared.subsystems.SubSystemContext import indigo.shared.subsystems.SubSystemId /** The JobMarket is a subsystem that manages a global pool of available jobs. @@ -36,7 +36,7 @@ final case class JobMarket[Model](id: SubSystemId, availableJobs: List[Job]) ext private given CanEqual[Option[Job], Option[Job]] = CanEqual.derived def update( - frameContext: SubSystemFrameContext[ReferenceData], + frameContext: SubSystemContext[ReferenceData], jobs: List[Job] ): JobMarketEvent => Outcome[List[Job]] = { case JobMarketEvent.Post(job) => @@ -57,7 +57,7 @@ final case class JobMarket[Model](id: SubSystemId, availableJobs: List[Job]) ext Outcome(jobs) } - def present(frameContext: SubSystemFrameContext[ReferenceData], jobs: List[Job]): Outcome[SceneUpdateFragment] = + def present(frameContext: SubSystemContext[ReferenceData], jobs: List[Job]): Outcome[SceneUpdateFragment] = Outcome(SceneUpdateFragment.empty) } diff --git a/indigo/indigo-extras/src/main/scala/indigoextras/subsystems/AssetBundleLoader.scala b/indigo/indigo-extras/src/main/scala/indigoextras/subsystems/AssetBundleLoader.scala index 376d2c041..a99d45d6c 100644 --- a/indigo/indigo-extras/src/main/scala/indigoextras/subsystems/AssetBundleLoader.scala +++ b/indigo/indigo-extras/src/main/scala/indigoextras/subsystems/AssetBundleLoader.scala @@ -11,7 +11,7 @@ import indigo.shared.events.GlobalEvent import indigo.shared.events.SubSystemEvent import indigo.shared.scenegraph.SceneUpdateFragment import indigo.shared.subsystems.SubSystem -import indigo.shared.subsystems.SubSystemFrameContext +import indigo.shared.subsystems.SubSystemContext import indigo.shared.subsystems.SubSystemId // Provides "at least once" message delivery for updates on a bundle's loading status. @@ -37,7 +37,7 @@ final class AssetBundleLoader[Model] extends SubSystem[Model]: private given CanEqual[Option[Set[AssetType]], Option[Set[AssetType]]] = CanEqual.derived def update( - frameContext: SubSystemFrameContext[ReferenceData], + frameContext: SubSystemContext[ReferenceData], tracker: AssetBundleTracker ): GlobalEvent => Outcome[AssetBundleTracker] = // Asset Bundle Loader Commands @@ -76,7 +76,7 @@ final class AssetBundleLoader[Model] extends SubSystem[Model]: Outcome(tracker) def present( - frameContext: SubSystemFrameContext[ReferenceData], + frameContext: SubSystemContext[ReferenceData], model: AssetBundleTracker ): Outcome[SceneUpdateFragment] = Outcome(SceneUpdateFragment.empty) diff --git a/indigo/indigo-extras/src/main/scala/indigoextras/subsystems/Automata.scala b/indigo/indigo-extras/src/main/scala/indigoextras/subsystems/Automata.scala index 6bb725c26..5f9552cd0 100644 --- a/indigo/indigo-extras/src/main/scala/indigoextras/subsystems/Automata.scala +++ b/indigo/indigo-extras/src/main/scala/indigoextras/subsystems/Automata.scala @@ -12,7 +12,7 @@ import indigo.shared.events.SubSystemEvent import indigo.shared.scenegraph.SceneNode import indigo.shared.scenegraph._ import indigo.shared.subsystems.SubSystem -import indigo.shared.subsystems.SubSystemFrameContext +import indigo.shared.subsystems.SubSystemContext import indigo.shared.subsystems.SubSystemId import indigo.shared.temporal.Signal import indigo.shared.temporal.SignalReader @@ -57,7 +57,7 @@ final case class Automata[Model]( private given CanEqual[Option[Int], Option[Int]] = CanEqual.derived def update( - frameContext: SubSystemFrameContext[ReferenceData], + frameContext: SubSystemContext[ReferenceData], state: AutomataState ): AutomataEvent => Outcome[AutomataState] = case Spawn(key, position, lifeSpan, payload) if key == poolKey => @@ -68,7 +68,7 @@ final case class Automata[Model]( automaton.onCull, new AutomatonSeedValues( position, - frameContext.gameTime.running, + frameContext.time.running, lifeSpan.getOrElse(automaton.lifespan), frameContext.dice.roll, payload @@ -108,12 +108,12 @@ final case class Automata[Model]( case Update(key) if key == poolKey => val cullEvents = state.pool - .filterNot(_.isAlive(frameContext.gameTime.running)) + .filterNot(_.isAlive(frameContext.time.running)) .flatMap(sa => sa.onCull(sa.seedValues)) Outcome( state.copy( - pool = state.pool.filter(_.isAlive(frameContext.gameTime.running)) + pool = state.pool.filter(_.isAlive(frameContext.time.running)) ), Batch(cullEvents) ) @@ -121,8 +121,8 @@ final case class Automata[Model]( case _ => Outcome(state) - def present(frameContext: SubSystemFrameContext[ReferenceData], state: AutomataState): Outcome[SceneUpdateFragment] = - val updated = Automata.renderNoLayer(state.pool, frameContext.gameTime) + def present(frameContext: SubSystemContext[ReferenceData], state: AutomataState): Outcome[SceneUpdateFragment] = + val updated = Automata.renderNoLayer(state.pool, frameContext.time) Outcome( SceneUpdateFragment( diff --git a/indigo/indigo-extras/src/main/scala/indigoextras/subsystems/FPSCounter.scala b/indigo/indigo-extras/src/main/scala/indigoextras/subsystems/FPSCounter.scala index 700799b18..98b3fe9bf 100644 --- a/indigo/indigo-extras/src/main/scala/indigoextras/subsystems/FPSCounter.scala +++ b/indigo/indigo-extras/src/main/scala/indigoextras/subsystems/FPSCounter.scala @@ -17,7 +17,7 @@ import indigo.shared.scenegraph.SceneUpdateFragment import indigo.shared.scenegraph.Shape import indigo.shared.scenegraph.TextBox import indigo.shared.subsystems.SubSystem -import indigo.shared.subsystems.SubSystemFrameContext +import indigo.shared.subsystems.SubSystemContext import indigo.shared.subsystems.SubSystemId import indigo.shared.time.FPS import indigo.shared.time.Seconds @@ -56,15 +56,15 @@ final case class FPSCounter[Model]( Outcome(FPSCounterState.initial(startPosition)) def update( - context: SubSystemFrameContext[ReferenceData], + context: SubSystemContext[ReferenceData], model: FPSCounterState ): GlobalEvent => Outcome[FPSCounterState] = { case FrameTick => - if (context.gameTime.running >= (model.lastInterval + Seconds(1))) + if (context.time.running >= (model.lastInterval + Seconds(1))) Outcome( model.copy( fps = decideNextFps(model.frameCountSinceInterval), - lastInterval = context.gameTime.running, + lastInterval = context.time.running, frameCountSinceInterval = 0 ) ) @@ -82,7 +82,7 @@ final case class FPSCounter[Model]( .withFontFamily(fontFamily) .withFontSize(fontSize) - def present(context: SubSystemFrameContext[ReferenceData], model: FPSCounterState): Outcome[SceneUpdateFragment] = + def present(context: SubSystemContext[ReferenceData], model: FPSCounterState): Outcome[SceneUpdateFragment] = val text: TextBox = textBox .withText(s"""FPS ${model.fps.toString}""") @@ -90,8 +90,7 @@ final case class FPSCounter[Model]( .moveTo(model.position + 2) val size: Rectangle = - context.boundaryLocator - .measureText(text) + context.bounds.measureText(text) val boxSize = ({ (s: Size) => diff --git a/indigo/indigo-extras/src/main/scala/indigoextras/ui/InputField.scala b/indigo/indigo-extras/src/main/scala/indigoextras/ui/InputField.scala index 79b771598..e2a8bfe46 100644 --- a/indigo/indigo-extras/src/main/scala/indigoextras/ui/InputField.scala +++ b/indigo/indigo-extras/src/main/scala/indigoextras/ui/InputField.scala @@ -1,7 +1,7 @@ package indigoextras.ui import indigo.shared.BoundaryLocator -import indigo.shared.FrameContext +import indigo.shared.Context import indigo.shared.Outcome import indigo.shared.collections.Batch import indigo.shared.constants.Key @@ -35,8 +35,8 @@ final case class InputField( onLoseFocus: () => Batch[GlobalEvent] ) derives CanEqual: - def bounds(boundaryLocator: BoundaryLocator): Option[Rectangle] = - boundaryLocator.findBounds(assets.text.withText(text).moveTo(position)) + def bounds(_bounds: Context.Services.Bounds): Option[Rectangle] = + _bounds.find(assets.text.withText(text).moveTo(position)) def withText(newText: String): InputField = this.copy( @@ -166,7 +166,7 @@ final case class InputField( def withLoseFocusActions(actions: => Batch[GlobalEvent]): InputField = this.copy(onLoseFocus = () => actions) - def update(frameContext: FrameContext[?]): Outcome[InputField] = { + def update(context: Context[?]): Outcome[InputField] = { @tailrec def rec( keysReleased: List[Key], @@ -177,7 +177,7 @@ final case class InputField( keysReleased match { case Nil => if (touched) - Outcome(acc.copy(lastCursorMove = frameContext.gameTime.running), Batch.fromOption(changeEvent)) + Outcome(acc.copy(lastCursorMove = context.frame.time.running), Batch.fromOption(changeEvent)) else Outcome(acc, Batch.fromOption(changeEvent)) @@ -215,13 +215,13 @@ final case class InputField( val updated: Outcome[InputField] = if (hasFocus) - rec(frameContext.inputState.keyboard.keysReleased.toList, this, false, None) + rec(context.frame.input.keyboard.keysReleased.toList, this, false, None) else Outcome(this) - if (frameContext.inputState.pointers.isReleased) - bounds(frameContext.boundaryLocator) match + if (context.frame.input.pointers.isReleased) + bounds(context.services.bounds) match case Some(bounds) => - if frameContext.inputState.pointers.wasUpWithin(bounds, MouseButton.LeftMouseButton) then + if context.frame.input.pointers.wasUpWithin(bounds, MouseButton.LeftMouseButton) then updated.flatMap(_.giveFocus) else updated.flatMap(_.loseFocus) case _ => @@ -231,7 +231,7 @@ final case class InputField( def draw( gameTime: GameTime, - boundaryLocator: BoundaryLocator + boundaryLocator: Context.Services.Bounds ): Batch[SceneNode] = { val field = assets.text diff --git a/indigo/indigo-extras/src/test/scala/indigoextras/jobs/JobMarketTests.scala b/indigo/indigo-extras/src/test/scala/indigoextras/jobs/JobMarketTests.scala index cf715979a..981da7a3d 100644 --- a/indigo/indigo-extras/src/test/scala/indigoextras/jobs/JobMarketTests.scala +++ b/indigo/indigo-extras/src/test/scala/indigoextras/jobs/JobMarketTests.scala @@ -11,14 +11,14 @@ import indigo.shared.events.FrameTick import indigo.shared.events.InputState import indigo.shared.scenegraph.SceneAudio import indigo.shared.subsystems -import indigo.shared.subsystems.SubSystemFrameContext +import indigo.shared.subsystems.SubSystemContext import indigo.shared.subsystems.SubSystemId import indigo.shared.time.GameTime class JobMarketTests extends munit.FunSuite { val context = - SubSystemFrameContext[Unit]( + SubSystemContext[Unit]( GameTime.zero, Dice.loaded(6), InputState.default, diff --git a/indigo/indigo-extras/src/test/scala/indigoextras/subsystems/FakeSubSystemFrameContext.scala b/indigo/indigo-extras/src/test/scala/indigoextras/subsystems/FakeSubSystemFrameContext.scala index 25a0f161c..9096bb5e1 100644 --- a/indigo/indigo-extras/src/test/scala/indigoextras/subsystems/FakeSubSystemFrameContext.scala +++ b/indigo/indigo-extras/src/test/scala/indigoextras/subsystems/FakeSubSystemFrameContext.scala @@ -6,14 +6,14 @@ import indigo.shared.BoundaryLocator import indigo.shared.FontRegister import indigo.shared.dice.Dice import indigo.shared.events.InputState -import indigo.shared.subsystems.SubSystemFrameContext +import indigo.shared.subsystems.SubSystemContext import indigo.shared.time.GameTime import indigo.shared.time.Seconds object FakeSubSystemFrameContext: - def context(sides: Int): SubSystemFrameContext[Unit] = - SubSystemFrameContext( + def context(sides: Int): SubSystemContext[Unit] = + SubSystemContext( GameTime.zero, Dice.loaded(sides), InputState.default, @@ -21,8 +21,8 @@ object FakeSubSystemFrameContext: () ) - def context(sides: Int, time: Seconds): SubSystemFrameContext[Unit] = - SubSystemFrameContext( + def context(sides: Int, time: Seconds): SubSystemContext[Unit] = + SubSystemContext( GameTime.is(time), Dice.loaded(sides), InputState.default, @@ -30,8 +30,8 @@ object FakeSubSystemFrameContext: () ) - def context(sides: Int, time: Seconds, delta: Seconds): SubSystemFrameContext[Unit] = - SubSystemFrameContext( + def context(sides: Int, time: Seconds, delta: Seconds): SubSystemContext[Unit] = + SubSystemContext( GameTime.withDelta(time, delta), Dice.loaded(sides), InputState.default, diff --git a/indigo/indigo-extras/src/test/scala/indigoextras/ui/InputFieldTests.scala b/indigo/indigo-extras/src/test/scala/indigoextras/ui/InputFieldTests.scala index f50597c12..b96feb83e 100644 --- a/indigo/indigo-extras/src/test/scala/indigoextras/ui/InputFieldTests.scala +++ b/indigo/indigo-extras/src/test/scala/indigoextras/ui/InputFieldTests.scala @@ -5,7 +5,7 @@ import indigo.platform.renderer.Renderer import indigo.shared.AnimationsRegister import indigo.shared.BoundaryLocator import indigo.shared.FontRegister -import indigo.shared.FrameContext +import indigo.shared.Context import indigo.shared.assets.AssetName import indigo.shared.collections.Batch import indigo.shared.constants.Key @@ -276,8 +276,8 @@ class InputFieldTests extends munit.FunSuite { KeyboardEvent.KeyUp(Key.KEY_C) ) - def context: FrameContext[Unit] = - new FrameContext[Unit]( + def context: Context[Unit] = + new Context[Unit]( GameTime.zero, Dice.loaded(1), new InputState(Mouse.default, new Keyboard(keysUp, Batch.empty, None), Gamepad.default, Pointers.default), diff --git a/indigo/indigo/src/main/scala/indigo/IndigoDemo.scala b/indigo/indigo/src/main/scala/indigo/IndigoDemo.scala index 62cf10571..7ff23ccb4 100644 --- a/indigo/indigo/src/main/scala/indigo/IndigoDemo.scala +++ b/indigo/indigo/src/main/scala/indigo/IndigoDemo.scala @@ -84,7 +84,7 @@ trait IndigoDemo[BootData, StartUpData, Model, ViewModel] extends GameLauncher[S * A function that maps GlobalEvent's to the next version of your model, and encapsuates failures or resulting * events within the Outcome wrapper. */ - def updateModel(context: FrameContext[StartUpData], model: Model): GlobalEvent => Outcome[Model] + def updateModel(context: Context[StartUpData], model: Model): GlobalEvent => Outcome[Model] /** A pure function for updating your game's view model in the context of the running frame and the events acting upon * it. @@ -101,7 +101,7 @@ trait IndigoDemo[BootData, StartUpData, Model, ViewModel] extends GameLauncher[S * events within the Outcome wrapper. */ def updateViewModel( - context: FrameContext[StartUpData], + context: Context[StartUpData], model: Model, viewModel: ViewModel ): GlobalEvent => Outcome[ViewModel] @@ -120,7 +120,7 @@ trait IndigoDemo[BootData, StartUpData, Model, ViewModel] extends GameLauncher[S * A function that produces a description of what to present next, and encapsuates failures or resulting events * within the Outcome wrapper. */ - def present(context: FrameContext[StartUpData], model: Model, viewModel: ViewModel): Outcome[SceneUpdateFragment] + def present(context: Context[StartUpData], model: Model, viewModel: ViewModel): Outcome[SceneUpdateFragment] private val subSystemsRegister: SubSystemsRegister[Model] = new SubSystemsRegister() diff --git a/indigo/indigo/src/main/scala/indigo/IndigoGame.scala b/indigo/indigo/src/main/scala/indigo/IndigoGame.scala index a7fd0014c..6b5858c8d 100644 --- a/indigo/indigo/src/main/scala/indigo/IndigoGame.scala +++ b/indigo/indigo/src/main/scala/indigo/IndigoGame.scala @@ -105,7 +105,7 @@ trait IndigoGame[BootData, StartUpData, Model, ViewModel] extends GameLauncher[S * A function that maps GlobalEvent's to the next version of your model, and encapsulates failures or resulting * events within the Outcome wrapper. */ - def updateModel(context: FrameContext[StartUpData], model: Model): GlobalEvent => Outcome[Model] + def updateModel(context: Context[StartUpData], model: Model): GlobalEvent => Outcome[Model] /** A pure function for updating your game's view model in the context of the running frame and the events acting upon * it. @@ -122,7 +122,7 @@ trait IndigoGame[BootData, StartUpData, Model, ViewModel] extends GameLauncher[S * resulting events within the Outcome wrapper. */ def updateViewModel( - context: FrameContext[StartUpData], + context: Context[StartUpData], model: Model, viewModel: ViewModel ): GlobalEvent => Outcome[ViewModel] @@ -141,7 +141,7 @@ trait IndigoGame[BootData, StartUpData, Model, ViewModel] extends GameLauncher[S * A function that produces a description of what to present next, and encapsulates failures or resulting events * within the Outcome wrapper. */ - def present(context: FrameContext[StartUpData], model: Model, viewModel: ViewModel): Outcome[SceneUpdateFragment] + def present(context: Context[StartUpData], model: Model, viewModel: ViewModel): Outcome[SceneUpdateFragment] private val subSystemsRegister: SubSystemsRegister[Model] = new SubSystemsRegister() diff --git a/indigo/indigo/src/main/scala/indigo/IndigoSandbox.scala b/indigo/indigo/src/main/scala/indigo/IndigoSandbox.scala index 4993c702f..11259b85f 100644 --- a/indigo/indigo/src/main/scala/indigo/IndigoSandbox.scala +++ b/indigo/indigo/src/main/scala/indigo/IndigoSandbox.scala @@ -75,7 +75,7 @@ trait IndigoSandbox[StartUpData, Model] extends GameLauncher[StartUpData, Model, * A function that maps GlobalEvent's to the next version of your model, and encapsuates failures or resulting * events within the Outcome wrapper. */ - def updateModel(context: FrameContext[StartUpData], model: Model): GlobalEvent => Outcome[Model] + def updateModel(context: Context[StartUpData], model: Model): GlobalEvent => Outcome[Model] /** A pure function for presenting your game. The result is a side effect free declaration of what you intend to be * presented to the player next. @@ -91,11 +91,11 @@ trait IndigoSandbox[StartUpData, Model] extends GameLauncher[StartUpData, Model, * A function that produces a description of what to present next, and encapsuates failures or resulting events * within the Outcome wrapper. */ - def present(context: FrameContext[StartUpData], model: Model): Outcome[SceneUpdateFragment] + def present(context: Context[StartUpData], model: Model): Outcome[SceneUpdateFragment] private def indigoGame: GameEngine[StartUpData, Model, Unit] = { - val updateViewModel: (FrameContext[StartUpData], Model, Unit) => GlobalEvent => Outcome[Unit] = + val updateViewModel: (Context[StartUpData], Model, Unit) => GlobalEvent => Outcome[Unit] = (_, _, vm) => _ => Outcome(vm) val eventFilters: EventFilters = diff --git a/indigo/indigo/src/main/scala/indigo/IndigoShader.scala b/indigo/indigo/src/main/scala/indigo/IndigoShader.scala index 2a7802dfc..5e1eebdf5 100644 --- a/indigo/indigo/src/main/scala/indigo/IndigoShader.scala +++ b/indigo/indigo/src/main/scala/indigo/IndigoShader.scala @@ -116,7 +116,7 @@ trait IndigoShader extends GameLauncher[IndigoShaderModel, IndigoShaderModel, Un Outcome(startupData) private def updateModel( - context: FrameContext[IndigoShaderModel], + context: Context[IndigoShaderModel], model: IndigoShaderModel ): GlobalEvent => Outcome[IndigoShaderModel] = { case ViewportResize(vp) => @@ -130,7 +130,7 @@ trait IndigoShader extends GameLauncher[IndigoShaderModel, IndigoShaderModel, Un } private def present( - context: FrameContext[IndigoShaderModel], + context: Context[IndigoShaderModel], model: IndigoShaderModel ): Outcome[SceneUpdateFragment] = Outcome( @@ -155,7 +155,7 @@ trait IndigoShader extends GameLauncher[IndigoShaderModel, IndigoShaderModel, Un boot: BootResult[IndigoShaderModel, IndigoShaderModel] ): GameEngine[IndigoShaderModel, IndigoShaderModel, Unit] = { - val updateViewModel: (FrameContext[IndigoShaderModel], IndigoShaderModel, Unit) => GlobalEvent => Outcome[Unit] = + val updateViewModel: (Context[IndigoShaderModel], IndigoShaderModel, Unit) => GlobalEvent => Outcome[Unit] = (_, _, vm) => _ => Outcome(vm) val eventFilters: EventFilters = diff --git a/indigo/indigo/src/main/scala/indigo/entry/ScenesFrameProcessor.scala b/indigo/indigo/src/main/scala/indigo/entry/ScenesFrameProcessor.scala index 565f1378b..100e471b3 100644 --- a/indigo/indigo/src/main/scala/indigo/entry/ScenesFrameProcessor.scala +++ b/indigo/indigo/src/main/scala/indigo/entry/ScenesFrameProcessor.scala @@ -4,7 +4,7 @@ import indigo.gameengine.FrameProcessor import indigo.platform.renderer.Renderer import indigo.scenes.SceneManager import indigo.shared.BoundaryLocator -import indigo.shared.FrameContext +import indigo.shared.Context import indigo.shared.Outcome import indigo.shared.collections.Batch import indigo.shared.datatypes.BindingKey @@ -14,7 +14,7 @@ import indigo.shared.events.EventFilters import indigo.shared.events.GlobalEvent import indigo.shared.events.InputState import indigo.shared.scenegraph.SceneUpdateFragment -import indigo.shared.subsystems.SubSystemFrameContext._ +import indigo.shared.subsystems.SubSystemContext.* import indigo.shared.subsystems.SubSystemsRegister import indigo.shared.time.GameTime @@ -22,9 +22,9 @@ final class ScenesFrameProcessor[StartUpData, Model, ViewModel]( val subSystemsRegister: SubSystemsRegister[Model], val sceneManager: SceneManager[StartUpData, Model, ViewModel], val eventFilters: EventFilters, - val modelUpdate: (FrameContext[StartUpData], Model) => GlobalEvent => Outcome[Model], - val viewModelUpdate: (FrameContext[StartUpData], Model, ViewModel) => GlobalEvent => Outcome[ViewModel], - val viewUpdate: (FrameContext[StartUpData], Model, ViewModel) => Outcome[SceneUpdateFragment] + val modelUpdate: (Context[StartUpData], Model) => GlobalEvent => Outcome[Model], + val viewModelUpdate: (Context[StartUpData], Model, ViewModel) => GlobalEvent => Outcome[ViewModel], + val viewUpdate: (Context[StartUpData], Model, ViewModel) => Outcome[SceneUpdateFragment] ) extends FrameProcessor[StartUpData, Model, ViewModel] with StandardFrameProcessorFunctions[StartUpData, Model, ViewModel]: @@ -40,8 +40,8 @@ final class ScenesFrameProcessor[StartUpData, Model, ViewModel]( renderer: => Renderer ): Outcome[(Model, ViewModel, SceneUpdateFragment)] = { - val frameContext = - new FrameContext[StartUpData](gameTime, dice, inputState, boundaryLocator, startUpData, renderer.captureScreen) + val context = + Context[StartUpData](gameTime, dice, inputState, boundaryLocator, startUpData, renderer.captureScreen) val processSceneViewModel: (Model, ViewModel) => Outcome[ViewModel] = (m, vm) => globalEvents @@ -49,30 +49,30 @@ final class ScenesFrameProcessor[StartUpData, Model, ViewModel]( .collect { case Some(e) => e } .foldLeft(Outcome(vm)) { (acc, e) => acc.flatMap { next => - sceneManager.updateViewModel(frameContext, m, next)(e) + sceneManager.updateViewModel(context, m, next)(e) } } val processSceneView: (Model, ViewModel) => Outcome[SceneUpdateFragment] = (m, vm) => Outcome.merge( - processView(frameContext, m, vm), - sceneManager.updateView(frameContext, m, vm) + processView(context, m, vm), + sceneManager.updateView(context, m, vm) )(_ |+| _) Outcome.join( for { - m <- processModel(frameContext, model, globalEvents) - sm <- processSceneModel(frameContext, m, globalEvents) - vm <- processViewModel(frameContext, sm, viewModel, globalEvents) + m <- processModel(context, model, globalEvents) + sm <- processSceneModel(context, m, globalEvents) + vm <- processViewModel(context, sm, viewModel, globalEvents) svm <- processSceneViewModel(sm, vm) - e <- processSubSystems(frameContext, m, globalEvents).eventsAsOutcome + e <- processSubSystems(context, m, globalEvents).eventsAsOutcome v <- processSceneView(sm, svm) } yield Outcome((sm, svm, v), e) ) } def processSceneModel( - frameContext: FrameContext[StartUpData], + context: Context[StartUpData], model: Model, globalEvents: Batch[GlobalEvent] ): Outcome[Model] = @@ -81,16 +81,16 @@ final class ScenesFrameProcessor[StartUpData, Model, ViewModel]( .collect { case Some(e) => e } .foldLeft(Outcome(model)) { (acc, e) => acc.flatMap { next => - sceneManager.updateModel(frameContext, next)(e) + sceneManager.updateModel(context, next)(e) } } def processSubSystems( - frameContext: FrameContext[StartUpData], + context: Context[StartUpData], model: Model, globalEvents: Batch[GlobalEvent] ): Outcome[Unit] = Outcome.merge( - subSystemsRegister.update(frameContext.forSubSystems, model, globalEvents.toJSArray), - sceneManager.updateSubSystems(frameContext.forSubSystems, model, globalEvents) + subSystemsRegister.update(context.forSubSystems, model, globalEvents.toJSArray), + sceneManager.updateSubSystems(context.forSubSystems, model, globalEvents) )((_, _) => ()) diff --git a/indigo/indigo/src/main/scala/indigo/entry/StandardFrameProcessor.scala b/indigo/indigo/src/main/scala/indigo/entry/StandardFrameProcessor.scala index 4d4361dad..147149120 100644 --- a/indigo/indigo/src/main/scala/indigo/entry/StandardFrameProcessor.scala +++ b/indigo/indigo/src/main/scala/indigo/entry/StandardFrameProcessor.scala @@ -3,7 +3,7 @@ package indigo.entry import indigo.gameengine.FrameProcessor import indigo.platform.renderer.Renderer import indigo.shared.BoundaryLocator -import indigo.shared.FrameContext +import indigo.shared.Context import indigo.shared.Outcome import indigo.shared.collections.Batch import indigo.shared.dice.Dice @@ -11,16 +11,16 @@ import indigo.shared.events.EventFilters import indigo.shared.events.GlobalEvent import indigo.shared.events.InputState import indigo.shared.scenegraph.SceneUpdateFragment -import indigo.shared.subsystems.SubSystemFrameContext._ +import indigo.shared.subsystems.SubSystemContext._ import indigo.shared.subsystems.SubSystemsRegister import indigo.shared.time.GameTime final class StandardFrameProcessor[StartUpData, Model, ViewModel]( val subSystemsRegister: SubSystemsRegister[Model], val eventFilters: EventFilters, - val modelUpdate: (FrameContext[StartUpData], Model) => GlobalEvent => Outcome[Model], - val viewModelUpdate: (FrameContext[StartUpData], Model, ViewModel) => GlobalEvent => Outcome[ViewModel], - val viewUpdate: (FrameContext[StartUpData], Model, ViewModel) => Outcome[SceneUpdateFragment] + val modelUpdate: (Context[StartUpData], Model) => GlobalEvent => Outcome[Model], + val viewModelUpdate: (Context[StartUpData], Model, ViewModel) => GlobalEvent => Outcome[ViewModel], + val viewUpdate: (Context[StartUpData], Model, ViewModel) => Outcome[SceneUpdateFragment] ) extends FrameProcessor[StartUpData, Model, ViewModel] with StandardFrameProcessorFunctions[StartUpData, Model, ViewModel]: @@ -36,7 +36,8 @@ final class StandardFrameProcessor[StartUpData, Model, ViewModel]( renderer: => Renderer ): Outcome[(Model, ViewModel, SceneUpdateFragment)] = val frameContext = - new FrameContext[StartUpData](gameTime, dice, inputState, boundaryLocator, startUpData, renderer.captureScreen) + Context[StartUpData](gameTime, dice, inputState, boundaryLocator, startUpData, renderer.captureScreen) + Outcome.join( for { m <- processModel(frameContext, model, globalEvents) @@ -49,12 +50,12 @@ final class StandardFrameProcessor[StartUpData, Model, ViewModel]( trait StandardFrameProcessorFunctions[StartUpData, Model, ViewModel]: def subSystemsRegister: SubSystemsRegister[Model] def eventFilters: EventFilters - def modelUpdate: (FrameContext[StartUpData], Model) => GlobalEvent => Outcome[Model] - def viewModelUpdate: (FrameContext[StartUpData], Model, ViewModel) => GlobalEvent => Outcome[ViewModel] - def viewUpdate: (FrameContext[StartUpData], Model, ViewModel) => Outcome[SceneUpdateFragment] + def modelUpdate: (Context[StartUpData], Model) => GlobalEvent => Outcome[Model] + def viewModelUpdate: (Context[StartUpData], Model, ViewModel) => GlobalEvent => Outcome[ViewModel] + def viewUpdate: (Context[StartUpData], Model, ViewModel) => Outcome[SceneUpdateFragment] def processModel( - frameContext: FrameContext[StartUpData], + frameContext: Context[StartUpData], model: Model, globalEvents: Batch[GlobalEvent] ): Outcome[Model] = @@ -68,7 +69,7 @@ trait StandardFrameProcessorFunctions[StartUpData, Model, ViewModel]: } def processViewModel( - frameContext: FrameContext[StartUpData], + frameContext: Context[StartUpData], model: Model, viewModel: ViewModel, globalEvents: Batch[GlobalEvent] @@ -83,7 +84,7 @@ trait StandardFrameProcessorFunctions[StartUpData, Model, ViewModel]: } def processView( - frameContext: FrameContext[StartUpData], + frameContext: Context[StartUpData], model: Model, viewModel: ViewModel ): Outcome[SceneUpdateFragment] = diff --git a/indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala b/indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala index 2c5210fd0..349440099 100644 --- a/indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala +++ b/indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala @@ -178,7 +178,7 @@ final class GameEngine[StartUpData, GameModel, ViewModel]( audioPlayer.addAudioAssets(accumulatedAssetCollection.sounds) - val randomSeed = (if (firstRun) 0 else gameLoopInstance.runningTimeReference) + gameLoopInstance.initialSeed + val randomSeed = (if (firstRun) 0 else gameLoopInstance.runningTimeReference) // + gameLoopInstance.initialSeed // TODO: Bug here. Black screen of no-render death. if (firstRun) platform = new Platform(parentElement, gameConfig, globalEventStream, dynamicText) diff --git a/indigo/indigo/src/main/scala/indigo/package.scala b/indigo/indigo/src/main/scala/indigo/package.scala index 487e2422b..9c9cca9d7 100644 --- a/indigo/indigo/src/main/scala/indigo/package.scala +++ b/indigo/indigo/src/main/scala/indigo/package.scala @@ -617,8 +617,11 @@ val ImageType: shared.ImageType.type = shared.ImageType type BoundaryLocator = shared.BoundaryLocator -type FrameContext[StartUpData] = shared.FrameContext[StartUpData] -type SubSystemFrameContext[ReferenceData] = shared.subsystems.SubSystemFrameContext[ReferenceData] +type Context[StartUpData] = shared.Context[StartUpData] +val Context: shared.Context.type = shared.Context + +type SubSystemContext[ReferenceData] = shared.subsystems.SubSystemContext[ReferenceData] +val SubSystemContext: shared.subsystems.SubSystemContext.type = shared.subsystems.SubSystemContext //WebSockets diff --git a/indigo/indigo/src/main/scala/indigo/scenes/SceneContext.scala b/indigo/indigo/src/main/scala/indigo/scenes/SceneContext.scala index d85c1b979..25cca402c 100644 --- a/indigo/indigo/src/main/scala/indigo/scenes/SceneContext.scala +++ b/indigo/indigo/src/main/scala/indigo/scenes/SceneContext.scala @@ -1,7 +1,7 @@ package indigo.scenes import indigo.shared.BoundaryLocator -import indigo.shared.FrameContext +import indigo.shared.Context import indigo.shared.datatypes.Rectangle import indigo.shared.dice.Dice import indigo.shared.events.InputState @@ -25,28 +25,15 @@ import indigo.shared.time.Seconds final class SceneContext[StartUpData]( val sceneName: SceneName, val sceneStartTime: Seconds, - val frameContext: FrameContext[StartUpData] + val context: Context[StartUpData] ): - export frameContext.gameTime - export frameContext.dice - export frameContext.inputState - export frameContext.boundaryLocator - export frameContext.startUpData - export frameContext.gameTime.running - export frameContext.gameTime.delta - export frameContext.inputState.mouse - export frameContext.inputState.keyboard - export frameContext.inputState.gamepad - export frameContext.inputState.pointers - export frameContext.findBounds - export frameContext.bounds - export frameContext.captureScreen + export context.* /** The running time of the current scene calculated as the game's total running time minus time the scene was * entered. */ lazy val sceneRunning: Seconds = - frameContext.gameTime.running - sceneStartTime + context.frame.time.running - sceneStartTime - def toFrameContext: FrameContext[StartUpData] = - frameContext + def toFrameContext: Context[StartUpData] = + context diff --git a/indigo/indigo/src/main/scala/indigo/scenes/SceneManager.scala b/indigo/indigo/src/main/scala/indigo/scenes/SceneManager.scala index 90c826d38..1d2eb254f 100644 --- a/indigo/indigo/src/main/scala/indigo/scenes/SceneManager.scala +++ b/indigo/indigo/src/main/scala/indigo/scenes/SceneManager.scala @@ -1,6 +1,6 @@ package indigo.scenes -import indigo.shared.FrameContext +import indigo.shared.Context import indigo.shared.IndigoLogger import indigo.shared.Outcome import indigo.shared.collections.Batch @@ -8,8 +8,8 @@ import indigo.shared.collections.NonEmptyList import indigo.shared.events.EventFilters import indigo.shared.events.GlobalEvent import indigo.shared.scenegraph.SceneUpdateFragment -import indigo.shared.subsystems.SubSystemFrameContext -import indigo.shared.subsystems.SubSystemFrameContext._ +import indigo.shared.subsystems.SubSystemContext +import indigo.shared.subsystems.SubSystemContext._ import indigo.shared.subsystems.SubSystemsRegister import indigo.shared.time.Seconds @@ -42,9 +42,9 @@ class SceneManager[StartUpData, GameModel, ViewModel]( // Scene delegation - def updateModel(frameContext: FrameContext[StartUpData], model: GameModel): GlobalEvent => Outcome[GameModel] = + def updateModel(ctx: Context[StartUpData], model: GameModel): GlobalEvent => Outcome[GameModel] = case SceneEvent.First => - lastSceneChangeAt = frameContext.gameTime.running + lastSceneChangeAt = ctx.frame.time.running val from = finderInstance.current.name finderInstance = finderInstance.first @@ -57,7 +57,7 @@ class SceneManager[StartUpData, GameModel, ViewModel]( Outcome(model, events) case SceneEvent.Last => - lastSceneChangeAt = frameContext.gameTime.running + lastSceneChangeAt = ctx.frame.time.running val from = finderInstance.current.name finderInstance = finderInstance.last @@ -70,7 +70,7 @@ class SceneManager[StartUpData, GameModel, ViewModel]( Outcome(model, events) case SceneEvent.Next => - lastSceneChangeAt = frameContext.gameTime.running + lastSceneChangeAt = ctx.frame.time.running val from = finderInstance.current.name finderInstance = finderInstance.forward @@ -83,7 +83,7 @@ class SceneManager[StartUpData, GameModel, ViewModel]( Outcome(model, events) case SceneEvent.LoopNext => - lastSceneChangeAt = frameContext.gameTime.running + lastSceneChangeAt = ctx.frame.time.running val from = finderInstance.current.name finderInstance = finderInstance.forwardLoop @@ -96,7 +96,7 @@ class SceneManager[StartUpData, GameModel, ViewModel]( Outcome(model, events) case SceneEvent.Previous => - lastSceneChangeAt = frameContext.gameTime.running + lastSceneChangeAt = ctx.frame.time.running val from = finderInstance.current.name finderInstance = finderInstance.backward @@ -109,7 +109,7 @@ class SceneManager[StartUpData, GameModel, ViewModel]( Outcome(model, events) case SceneEvent.LoopPrevious => - lastSceneChangeAt = frameContext.gameTime.running + lastSceneChangeAt = ctx.frame.time.running val from = finderInstance.current.name finderInstance = finderInstance.backwardLoop @@ -122,7 +122,7 @@ class SceneManager[StartUpData, GameModel, ViewModel]( Outcome(model, events) case SceneEvent.JumpTo(name) => - lastSceneChangeAt = frameContext.gameTime.running + lastSceneChangeAt = ctx.frame.time.running val from = finderInstance.current.name finderInstance = finderInstance.jumpToSceneByName(name) @@ -144,12 +144,12 @@ class SceneManager[StartUpData, GameModel, ViewModel]( Scene .updateModel( scene, - SceneContext(scene.name, lastSceneChangeAt, frameContext), + SceneContext(scene.name, lastSceneChangeAt, ctx), model )(event) def updateSubSystems( - frameContext: SubSystemFrameContext[Unit], + ctx: SubSystemContext[Unit], model: GameModel, globalEvents: Batch[GlobalEvent] ): Outcome[SubSystemsRegister[GameModel]] = @@ -159,7 +159,7 @@ class SceneManager[StartUpData, GameModel, ViewModel]( subSystemStates .get(scene.name.toString) .map { - _.update(frameContext, model, globalEvents.toJSArray) + _.update(ctx, model, globalEvents.toJSArray) } } .getOrElse( @@ -169,7 +169,7 @@ class SceneManager[StartUpData, GameModel, ViewModel]( ) def updateViewModel( - frameContext: FrameContext[StartUpData], + ctx: Context[StartUpData], model: GameModel, viewModel: ViewModel ): GlobalEvent => Outcome[ViewModel] = @@ -181,13 +181,13 @@ class SceneManager[StartUpData, GameModel, ViewModel]( case Some(scene) => Scene.updateViewModel( scene, - SceneContext(scene.name, lastSceneChangeAt, frameContext), + SceneContext(scene.name, lastSceneChangeAt, ctx), model, viewModel ) def updateView( - frameContext: FrameContext[StartUpData], + ctx: Context[StartUpData], model: GameModel, viewModel: ViewModel ): Outcome[SceneUpdateFragment] = @@ -200,14 +200,14 @@ class SceneManager[StartUpData, GameModel, ViewModel]( val subsystemView = subSystemStates .get(scene.name.toString) .map { ssr => - ssr.present(frameContext.forSubSystems, model) + ssr.present(ctx.forSubSystems, model) } .getOrElse(Outcome(SceneUpdateFragment.empty)) Outcome.merge( Scene.updateView( scene, - SceneContext(scene.name, lastSceneChangeAt, frameContext), + SceneContext(scene.name, lastSceneChangeAt, ctx), model, viewModel ), diff --git a/indigo/indigo/src/main/scala/indigo/shared/Context.scala b/indigo/indigo/src/main/scala/indigo/shared/Context.scala new file mode 100644 index 000000000..6c32712cf --- /dev/null +++ b/indigo/indigo/src/main/scala/indigo/shared/Context.scala @@ -0,0 +1,209 @@ +package indigo.shared + +import indigo.FontKey +import indigo.platform.renderer.ScreenCaptureConfig +import indigo.shared.assets.AssetType +import indigo.shared.collections.Batch +import indigo.shared.datatypes.Rectangle +import indigo.shared.dice.Dice +import indigo.shared.events.InputState +import indigo.shared.scenegraph.SceneNode +import indigo.shared.scenegraph.TextBox +import indigo.shared.scenegraph.TextLine +import indigo.shared.time.GameTime + +final class Context[StartUpData]( + _startUpData: => StartUpData, + val frame: Context.Frame, + val services: Context.Services +): + lazy val startUpData = _startUpData + +object Context: + + def apply[StartUpData]( + gameTime: GameTime, + dice: Dice, + inputState: InputState, + boundaryLocator: BoundaryLocator, + startUpData: StartUpData, + _captureScreen: Batch[ScreenCaptureConfig] => Batch[Either[String, AssetType.Image]] + ): Context[StartUpData] = + new Context( + startUpData, + Frame( + dice, + gameTime, + inputState + ), + Services( + boundaryLocator, + scala.util.Random(), + _captureScreen + ) + ) + + final class Frame( + val dice: Dice, + val time: GameTime, + val input: InputState + ): + export time.running + export time.delta + export input.mouse + export input.keyboard + export input.gamepad + export input.pointers + + trait Services: + def bounds: Services.Bounds + def random: Services.Random + def screenCapture: Services.ScreenCapture + + object Services: + + def apply( + boundaryLocator: BoundaryLocator, + _random: scala.util.Random, + _captureScreen: Batch[ScreenCaptureConfig] => Batch[Either[String, AssetType.Image]] + ): Services = + new Services: + def bounds: Services.Bounds = + new Bounds: + def measureText(textBox: TextBox): Rectangle = boundaryLocator.measureText(textBox) + def find(sceneNode: SceneNode): Option[Rectangle] = boundaryLocator.findBounds(sceneNode) + def get(sceneNode: SceneNode): Rectangle = boundaryLocator.bounds(sceneNode) + def textAsLinesWithBounds( + text: String, + fontKey: FontKey, + letterSpacing: Int, + lineHeight: Int + ): Batch[TextLine] = + boundaryLocator.textAsLinesWithBounds(text, fontKey, letterSpacing, lineHeight) + + def random: Services.Random = + new Random: + def nextBoolean: Boolean = _random.nextBoolean() + def nextDouble: Double = _random.nextDouble() + def between(minInclusive: Double, maxExclusive: Double): Double = + _random.between(minInclusive, maxExclusive) + def nextFloat: Float = _random.nextFloat() + def between(minInclusive: Float, maxExclusive: Float): Float = _random.between(minInclusive, maxExclusive) + def nextInt: Int = _random.nextInt() + def nextInt(n: Int): Int = _random.nextInt(n) + def between(minInclusive: Int, maxExclusive: Int): Int = _random.between(minInclusive, maxExclusive) + def nextLong: Long = _random.nextLong() + def nextLong(n: Long): Long = _random.nextLong(n) + def between(minInclusive: Long, maxExclusive: Long): Long = _random.between(minInclusive, maxExclusive) + def nextString(length: Int): String = _random.nextString(length) + def nextPrintableChar(): Char = _random.nextPrintableChar() + def setSeed(seed: Long): Unit = _random.setSeed(seed) + def shuffle[T](xs: List[T]): List[T] = _random.shuffle(xs) + def alphanumeric(take: Int): List[Char] = _random.alphanumeric.take(take).toList + + def screenCapture: Services.ScreenCapture = + new ScreenCapture: + def captureScreen(captureConfig: Batch[ScreenCaptureConfig]): Batch[Either[String, AssetType.Image]] = + _captureScreen(captureConfig) + + def captureScreen(captureConfig: ScreenCaptureConfig): Either[String, AssetType.Image] = + captureScreen(Batch(captureConfig)).headOption match { + case Some(v) => v + case None => Left("Could not capture image") + } + + def noop: Services = + new Services: + def bounds: Bounds = + new Bounds: + def measureText(textBox: TextBox): Rectangle = Rectangle.zero + def find(sceneNode: SceneNode): Option[Rectangle] = None + def get(sceneNode: SceneNode): Rectangle = Rectangle.zero + def textAsLinesWithBounds( + text: String, + fontKey: FontKey, + letterSpacing: Int, + lineHeight: Int + ): Batch[TextLine] = + Batch.empty + + def random: Random = + new Random: + def nextBoolean: Boolean = false + def nextDouble: Double = 0.0 + def between(minInclusive: Double, maxExclusive: Double): Double = 0.0 + def nextFloat: Float = 0.0f + def between(minInclusive: Float, maxExclusive: Float): Float = 0.0f + def nextInt: Int = 0 + def nextInt(n: Int): Int = 0 + def between(minInclusive: Int, maxExclusive: Int): Int = 0 + def nextLong: Long = 0L + def nextLong(n: Long): Long = 0L + def between(minInclusive: Long, maxExclusive: Long): Long = 0L + def nextString(length: Int): String = "" + def nextPrintableChar(): Char = ' ' + def setSeed(seed: Long): Unit = () + def shuffle[T](xs: List[T]): List[T] = xs + def alphanumeric(take: Int): List[Char] = List.fill(take)(' ') + + def screenCapture: ScreenCapture = + new ScreenCapture: + def captureScreen(captureConfig: Batch[ScreenCaptureConfig]): Batch[Either[String, AssetType.Image]] = + Batch.empty + def captureScreen(captureConfig: ScreenCaptureConfig): Either[String, AssetType.Image] = Left( + "Screen capture not supported in noop implementation" + ) + + trait Bounds { + def measureText(textBox: TextBox): Rectangle + + /** Safely finds the bounds of any given scene node, if the node has bounds. It is not possible to sensibly + * measure the bounds of some node types, such as clones, and some nodes are dependant on external data that may + * be missing. + */ + def find(sceneNode: SceneNode): Option[Rectangle] + + /** Finds the bounds or returns a `Rectangle` of size zero for convenience. + */ + def get(sceneNode: SceneNode): Rectangle + + def textAsLinesWithBounds(text: String, fontKey: FontKey, letterSpacing: Int, lineHeight: Int): Batch[TextLine] + } + trait Random { + def nextBoolean: Boolean + def nextDouble: Double + def between(minInclusive: Double, maxExclusive: Double): Double + def nextFloat: Float + def between(minInclusive: Float, maxExclusive: Float): Float + def nextInt: Int + def nextInt(n: Int): Int + def between(minInclusive: Int, maxExclusive: Int): Int + def nextLong: Long + def nextLong(n: Long): Long + def between(minInclusive: Long, maxExclusive: Long): Long + def nextString(length: Int): String + def nextPrintableChar(): Char + def setSeed(seed: Long): Unit + def shuffle[T](xs: List[T]): List[T] + def alphanumeric(take: Int): List[Char] + } + trait ScreenCapture { + + /** Capture the screen as a number of images, each with the specified configuration + * + * @param captureConfig + * The configurations to use when capturing the screen + * @return + * A batch containing either the captured images, or error messages + */ + def captureScreen(captureConfig: Batch[ScreenCaptureConfig]): Batch[Either[String, AssetType.Image]] + + /** Capture the screen as an image, with the specified configuration + * + * @param captureConfig + * The configuration to use when capturing the screen + * @return + * The captured image, or an error message + */ + def captureScreen(captureConfig: ScreenCaptureConfig): Either[String, AssetType.Image] + } diff --git a/indigo/indigo/src/main/scala/indigo/shared/FrameContext.scala b/indigo/indigo/src/main/scala/indigo/shared/FrameContext.scala deleted file mode 100644 index 7520b892a..000000000 --- a/indigo/indigo/src/main/scala/indigo/shared/FrameContext.scala +++ /dev/null @@ -1,71 +0,0 @@ -package indigo.shared - -import indigo.platform.renderer.ScreenCaptureConfig -import indigo.shared.assets.AssetType -import indigo.shared.collections.Batch -import indigo.shared.datatypes.Rectangle -import indigo.shared.dice.Dice -import indigo.shared.events.InputState -import indigo.shared.input.Gamepad -import indigo.shared.input.Keyboard -import indigo.shared.input.Mouse -import indigo.shared.scenegraph.SceneNode -import indigo.shared.time.GameTime -import indigo.shared.time.Seconds - -/** The FrameContext is the context in which the current frame will be processed. In includes values that are unique to - * this frame, and also globally available services. - * - * @param gameTime - * A sampled instance of time that you should use everywhere that you need a time value. - * @param dice - * A pseudo-random number generator, made predictable / reproducible by being seeded on the current running time. - * @param inputState - * A snapshot of the state of the various input methods, also allows input mapping of combinations of inputs. - * @param boundaryLocator - * A service that can be interrogated for the calculated dimensions of screen elements. - * @param startUpData - * A read only reference to any and all data created during start up / set up. - */ -final class FrameContext[StartUpData]( - val gameTime: GameTime, - val dice: Dice, - val inputState: InputState, - val boundaryLocator: BoundaryLocator, - _startUpData: => StartUpData, - _captureScreen: Batch[ScreenCaptureConfig] => Batch[Either[String, AssetType.Image]] -): - - lazy val startUpData = _startUpData - - export gameTime.running - export gameTime.delta - export inputState.mouse - export inputState.keyboard - export inputState.gamepad - export inputState.pointers - export boundaryLocator.findBounds - export boundaryLocator.bounds - - /** Capture the screen as a number of images, each with the specified configuration - * - * @param captureConfig - * The configurations to use when capturing the screen - * @return - * A batch containing either the captured images, or error messages - */ - def captureScreen(captureConfig: Batch[ScreenCaptureConfig]): Batch[Either[String, AssetType.Image]] = - _captureScreen(captureConfig) - - /** Capture the screen as an image, with the specified configuration - * - * @param captureConfig - * The configuration to use when capturing the screen - * @return - * The captured image, or an error message - */ - def captureScreen(captureConfig: ScreenCaptureConfig): Either[String, AssetType.Image] = - captureScreen(Batch(captureConfig)).headOption match { - case Some(v) => v - case None => Left("Could not capture image") - } diff --git a/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystem.scala b/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystem.scala index 51e15374c..0cafdc7e5 100644 --- a/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystem.scala +++ b/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystem.scala @@ -24,11 +24,11 @@ trait SubSystem[Model]: def initialModel: Outcome[SubSystemModel] def update( - context: SubSystemFrameContext[ReferenceData], + context: SubSystemContext[ReferenceData], model: SubSystemModel ): EventType => Outcome[SubSystemModel] def present( - context: SubSystemFrameContext[ReferenceData], + context: SubSystemContext[ReferenceData], model: SubSystemModel ): Outcome[SceneUpdateFragment] diff --git a/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemContext.scala b/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemContext.scala new file mode 100644 index 000000000..80bd70595 --- /dev/null +++ b/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemContext.scala @@ -0,0 +1,50 @@ +package indigo.shared.subsystems + +import indigo.platform.renderer.Renderer +import indigo.shared.BoundaryLocator +import indigo.shared.Context +import indigo.shared.datatypes.Rectangle +import indigo.shared.dice.Dice +import indigo.shared.events.InputState +import indigo.shared.input.Gamepad +import indigo.shared.input.Keyboard +import indigo.shared.input.Mouse +import indigo.shared.scenegraph.SceneNode +import indigo.shared.time.GameTime +import indigo.shared.time.Seconds + +/** Similar to [FrameContext] but without access to start up data. The SubSystemContext is the context in which the + * current frame will be processed. In includes values that are unique to this frame, and also globally available + * services. + * + * @param gameTime + * A sampled instance of time that you should use everywhere that you need a time value. + * @param dice + * A psuedorandom number generator, made predicatable/reproducable by being seeded on the current running time. + * @param inputState + * A snapshot of the state of the various input methods, also allows input mapping of combinations of inputs. + * @param boundaryLocator + * A service that can be interogated for the calculated dimensions of screen elements. + */ +final case class SubSystemContext[ReferenceData]( + reference: ReferenceData, + frame: Context.Frame, + services: Context.Services +): + export frame.* + export services.* + + def toContext: Context[Unit] = + new Context[Unit]((), frame, services) + +object SubSystemContext { + + extension (ctx: Context[?]) + def forSubSystems: SubSystemContext[Unit] = + new SubSystemContext( + (), + ctx.frame, + ctx.services + ) + +} diff --git a/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemFrameContext.scala b/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemFrameContext.scala deleted file mode 100644 index 794a500d1..000000000 --- a/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemFrameContext.scala +++ /dev/null @@ -1,72 +0,0 @@ -package indigo.shared.subsystems - -import indigo.platform.renderer.Renderer -import indigo.shared.BoundaryLocator -import indigo.shared.FrameContext -import indigo.shared.datatypes.Rectangle -import indigo.shared.dice.Dice -import indigo.shared.events.InputState -import indigo.shared.input.Gamepad -import indigo.shared.input.Keyboard -import indigo.shared.input.Mouse -import indigo.shared.scenegraph.SceneNode -import indigo.shared.time.GameTime -import indigo.shared.time.Seconds - -/** Similar to [FrameContext] but without access to start up data. The SubSystemFrameContext is the context in which the - * current frame will be processed. In includes values that are unique to this frame, and also globally available - * services. - * - * @param gameTime - * A sampled instance of time that you should use everywhere that you need a time value. - * @param dice - * A psuedorandom number generator, made predicatable/reproducable by being seeded on the current running time. - * @param inputState - * A snapshot of the state of the various input methods, also allows input mapping of combinations of inputs. - * @param boundaryLocator - * A service that can be interogated for the calculated dimensions of screen elements. - */ -final case class SubSystemFrameContext[ReferenceData]( - gameTime: GameTime, - dice: Dice, - inputState: InputState, - boundaryLocator: BoundaryLocator, - reference: ReferenceData -): - - val running: Seconds = gameTime.running - val delta: Seconds = gameTime.delta - - val mouse: Mouse = inputState.mouse - val keyboard: Keyboard = inputState.keyboard - val gamepad: Gamepad = inputState.gamepad - - def findBounds(sceneGraphNode: SceneNode): Option[Rectangle] = - boundaryLocator.findBounds(sceneGraphNode) - - def bounds(sceneGraphNode: SceneNode): Rectangle = - boundaryLocator.bounds(sceneGraphNode) - - def toFrameContext: FrameContext[Unit] = - new FrameContext[Unit]( - gameTime, - dice, - inputState, - boundaryLocator, - (), - Renderer.blackHole.captureScreen - ) - -object SubSystemFrameContext { - - extension (frameContext: FrameContext[?]) - def forSubSystems: SubSystemFrameContext[Unit] = - new SubSystemFrameContext( - frameContext.gameTime, - frameContext.dice, - frameContext.inputState, - frameContext.boundaryLocator, - () - ) - -} diff --git a/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemsRegister.scala b/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemsRegister.scala index 2261fe669..db22ebde1 100644 --- a/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemsRegister.scala +++ b/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemsRegister.scala @@ -5,7 +5,7 @@ import indigo.shared.Outcome import indigo.shared.collections.Batch import indigo.shared.events.GlobalEvent import indigo.shared.scenegraph.SceneUpdateFragment -import indigo.shared.subsystems.SubSystemFrameContext +import indigo.shared.subsystems.SubSystemContext import scalajs.js @@ -44,7 +44,7 @@ final class SubSystemsRegister[Model] { // @SuppressWarnings(Array("scalafix:DisableSyntax.asInstanceOf")) def update( - frameContext: SubSystemFrameContext[Unit], + frameContext: SubSystemContext[Unit], gameModel: Model, globalEvents: js.Array[GlobalEvent] ): Outcome[SubSystemsRegister[Model]] = { @@ -88,7 +88,7 @@ final class SubSystemsRegister[Model] { } // @SuppressWarnings(Array("scalafix:DisableSyntax.asInstanceOf")) - def present(frameContext: SubSystemFrameContext[Unit], gameModel: Model): Outcome[SceneUpdateFragment] = + def present(frameContext: SubSystemContext[Unit], gameModel: Model): Outcome[SceneUpdateFragment] = registeredSubSystems .map { rss => rss.subSystem.present( diff --git a/indigo/indigo/src/test/scala/indigo/shared/subsystems/FakeSubSystemFrameContext.scala b/indigo/indigo/src/test/scala/indigo/shared/subsystems/FakeSubSystemFrameContext.scala index 02d21f055..026d43f31 100644 --- a/indigo/indigo/src/test/scala/indigo/shared/subsystems/FakeSubSystemFrameContext.scala +++ b/indigo/indigo/src/test/scala/indigo/shared/subsystems/FakeSubSystemFrameContext.scala @@ -6,14 +6,14 @@ import indigo.shared.BoundaryLocator import indigo.shared.FontRegister import indigo.shared.dice.Dice import indigo.shared.events.InputState -import indigo.shared.subsystems.SubSystemFrameContext +import indigo.shared.subsystems.SubSystemContext import indigo.shared.time.GameTime import indigo.shared.time.Seconds object FakeSubSystemFrameContext: - def context(sides: Int): SubSystemFrameContext[Unit] = - SubSystemFrameContext( + def context(sides: Int): SubSystemContext[Unit] = + SubSystemContext( GameTime.zero, Dice.loaded(sides), InputState.default, @@ -21,8 +21,8 @@ object FakeSubSystemFrameContext: () ) - def context(sides: Int, time: Seconds): SubSystemFrameContext[Unit] = - SubSystemFrameContext( + def context(sides: Int, time: Seconds): SubSystemContext[Unit] = + SubSystemContext( GameTime.is(time), Dice.loaded(sides), InputState.default, @@ -30,8 +30,8 @@ object FakeSubSystemFrameContext: () ) - def context(sides: Int, time: Seconds, delta: Seconds): SubSystemFrameContext[Unit] = - SubSystemFrameContext( + def context(sides: Int, time: Seconds, delta: Seconds): SubSystemContext[Unit] = + SubSystemContext( GameTime.withDelta(time, delta), Dice.loaded(sides), InputState.default, diff --git a/indigo/indigo/src/test/scala/indigo/shared/subsystems/PointsTrackerExample.scala b/indigo/indigo/src/test/scala/indigo/shared/subsystems/PointsTrackerExample.scala index 502b95116..8777adfae 100644 --- a/indigo/indigo/src/test/scala/indigo/shared/subsystems/PointsTrackerExample.scala +++ b/indigo/indigo/src/test/scala/indigo/shared/subsystems/PointsTrackerExample.scala @@ -7,7 +7,7 @@ import indigo.shared.events.GlobalEvent import indigo.shared.materials.Material import indigo.shared.scenegraph.SceneUpdateFragment import indigo.shared.scenegraph.Text -import indigo.shared.subsystems.SubSystemFrameContext +import indigo.shared.subsystems.SubSystemContext final case class PointsTrackerExample(num: Int, startingPoints: Int) extends SubSystem[Int] { type EventType = PointsTrackerEvent @@ -27,7 +27,7 @@ final case class PointsTrackerExample(num: Int, startingPoints: Int) extends Sub def initialModel: Outcome[Int] = Outcome(startingPoints) - def update(context: SubSystemFrameContext[Int], points: Int): PointsTrackerEvent => Outcome[Int] = { + def update(context: SubSystemContext[Int], points: Int): PointsTrackerEvent => Outcome[Int] = { case PointsTrackerEvent.Add(pts) => Outcome(points + pts + context.reference) @@ -36,7 +36,7 @@ final case class PointsTrackerExample(num: Int, startingPoints: Int) extends Sub .addGlobalEvents(GameOver) } - def present(context: SubSystemFrameContext[Int], points: Int): Outcome[SceneUpdateFragment] = + def present(context: SubSystemContext[Int], points: Int): Outcome[SceneUpdateFragment] = Outcome( SceneUpdateFragment(Text(points.toString, 0, 0, 1, FontKey(""), Material.Bitmap(AssetName("Testing")))) ) diff --git a/indigo/perf/src/main/scala/com/example/perf/PerfGame.scala b/indigo/perf/src/main/scala/com/example/perf/PerfGame.scala index e107a2121..d5ccf5e8a 100644 --- a/indigo/perf/src/main/scala/com/example/perf/PerfGame.scala +++ b/indigo/perf/src/main/scala/com/example/perf/PerfGame.scala @@ -92,13 +92,13 @@ object PerfGame extends IndigoDemo[Unit, Dude, DudeModel, Unit] { Outcome(res.getOrElse(Startup.Failure("Failed to load the dude"))) } - def updateModel(context: FrameContext[Dude], model: DudeModel): GlobalEvent => Outcome[DudeModel] = + def updateModel(context: Context[Dude], model: DudeModel): GlobalEvent => Outcome[DudeModel] = PerfModel.updateModel(model) - def updateViewModel(context: FrameContext[Dude], model: DudeModel, viewModel: Unit): GlobalEvent => Outcome[Unit] = + def updateViewModel(context: Context[Dude], model: DudeModel, viewModel: Unit): GlobalEvent => Outcome[Unit] = _ => Outcome(viewModel) - def present(context: FrameContext[Dude], model: DudeModel, viewModel: Unit): Outcome[SceneUpdateFragment] = + def present(context: Context[Dude], model: DudeModel, viewModel: Unit): Outcome[SceneUpdateFragment] = Outcome(PerfView.updateView(model)) } diff --git a/indigo/physics/src/main/scala/example/IndigoPhysics.scala b/indigo/physics/src/main/scala/example/IndigoPhysics.scala index 234547164..c24949936 100644 --- a/indigo/physics/src/main/scala/example/IndigoPhysics.scala +++ b/indigo/physics/src/main/scala/example/IndigoPhysics.scala @@ -40,7 +40,7 @@ object IndigoPhysics extends IndigoGame[Unit, Unit, Model, Unit]: Outcome(Startup.Success(())) def updateModel( - context: FrameContext[Unit], + context: Context[Unit], model: Model ): GlobalEvent => Outcome[Model] = case KeyboardEvent.KeyUp(Key.PAGE_UP) => @@ -53,14 +53,14 @@ object IndigoPhysics extends IndigoGame[Unit, Unit, Model, Unit]: Outcome(model) def updateViewModel( - context: FrameContext[Unit], + context: Context[Unit], model: Model, viewModel: Unit ): GlobalEvent => Outcome[Unit] = _ => Outcome(viewModel) def present( - context: FrameContext[Unit], + context: Context[Unit], model: Model, viewModel: Unit ): Outcome[SceneUpdateFragment] = diff --git a/indigo/physics/src/main/scala/example/PhysicsScene.scala b/indigo/physics/src/main/scala/example/PhysicsScene.scala index 338d5f9f5..b90365ebe 100644 --- a/indigo/physics/src/main/scala/example/PhysicsScene.scala +++ b/indigo/physics/src/main/scala/example/PhysicsScene.scala @@ -30,7 +30,7 @@ trait PhysicsScene extends Scene[Unit, Model, Unit]: world: World[MyTag] ): GlobalEvent => Outcome[World[MyTag]] = case FrameTick => - world.update(context.delta) + world.update(context.frame.time.delta) case _ => Outcome(world) diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxGame.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxGame.scala index 3b801d029..6f4369761 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxGame.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxGame.scala @@ -195,13 +195,13 @@ object SandboxGame extends IndigoGame[SandboxBootData, SandboxStartupData, Sandb } def updateModel( - context: FrameContext[SandboxStartupData], + context: Context[SandboxStartupData], model: SandboxGameModel ): GlobalEvent => Outcome[SandboxGameModel] = SandboxModel.updateModel(model) def updateViewModel( - context: FrameContext[SandboxStartupData], + context: Context[SandboxStartupData], model: SandboxGameModel, viewModel: SandboxViewModel ): GlobalEvent => Outcome[SandboxViewModel] = { @@ -210,7 +210,7 @@ object SandboxGame extends IndigoGame[SandboxBootData, SandboxStartupData, Sandb case FrameTick => val updateOffset: Point = - context.inputState.gamepad.dpad match { + context.frame.input.gamepad.dpad match { case GamepadDPad(true, _, _, _) => viewModel.offset + Point(0, -1) @@ -262,7 +262,7 @@ object SandboxGame extends IndigoGame[SandboxBootData, SandboxStartupData, Sandb } def present( - context: FrameContext[SandboxStartupData], + context: Context[SandboxStartupData], model: SandboxGameModel, viewModel: SandboxViewModel ): Outcome[SceneUpdateFragment] = diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxView.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxView.scala index aca0484ec..cfbb696f8 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxView.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxView.scala @@ -1,6 +1,6 @@ package com.example.sandbox -import indigo._ +import indigo.* object SandboxView: @@ -10,7 +10,7 @@ object SandboxView: model: SandboxGameModel, viewModel: SandboxViewModel, mouse: Mouse, - bl: BoundaryLocator + bl: Context.Services.Bounds ): SceneUpdateFragment = { mouse.isClickedAt.headOption match { case Some(position) => println("Mouse clicked at: " + position.toString()) @@ -92,13 +92,13 @@ object SandboxView: .moveTo(mouse.position.x, mouse.position.y) ) - def uiLayer(bl: BoundaryLocator): Batch[SceneNode] = + def uiLayer(bl: Context.Services.Bounds): Batch[SceneNode] = Batch( Text("AB!\n!C", 2, 2, 5, Fonts.fontKey, SandboxAssets.fontMaterial.withAlpha(0.5)).alignLeft, Text("AB!\n!C", 100, 2, 5, Fonts.fontKey, SandboxAssets.fontMaterial.withAlpha(0.5)).alignCenter, Text("AB!\n\n!C", 200, 2, 5, Fonts.fontKey, SandboxAssets.fontMaterial.withAlpha(0.5)).alignRight .withEventHandler { - case (txt, MouseEvent.Click(pt)) if bl.bounds(txt).contains(pt) => + case (txt, MouseEvent.Click(pt)) if bl.get(txt).contains(pt) => println("Clicked me!") None diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/BoundsScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/BoundsScene.scala index e934f26de..ac17d3caf 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/BoundsScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/BoundsScene.scala @@ -53,31 +53,31 @@ object BoundsScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi val graphic: Graphic[Material.Bitmap] = Graphic(Rectangle(0, 0, 40, 40), 1, BoundsAssets.junctionBoxMaterialOff) .moveTo(context.startUpData.viewportCenter) - .rotateTo(Radians.fromSeconds(context.running * speed)) + .rotateTo(Radians.fromSeconds(context.frame.time.running * speed)) val text: Text[Material.ImageEffects] = Text("boom!\nfish", Fonts.fontKey, SandboxAssets.fontMaterial).alignRight .moveTo(150, 100) - .rotateTo(Radians.fromSeconds(context.running * speed).negative) + .rotateTo(Radians.fromSeconds(context.frame.time.running * speed).negative) val shapeBox: Shape.Box = Shape .Box(Rectangle(0, 0, 60, 30), Fill.Color(RGBA.Red), Stroke(4, RGBA.Yellow)) .moveTo(180, 130) .withRef(10, 10) - .rotateTo(Radians.fromSeconds(context.running * speed)) + .rotateTo(Radians.fromSeconds(context.frame.time.running * speed)) val shapeCircle: Shape.Circle = Shape .Circle(Point(0), 20, Fill.Color(RGBA.Yellow), Stroke(2, RGBA.Cyan)) .moveTo(180, 80) - .rotateTo(Radians.fromSeconds(context.running * speed).invert) + .rotateTo(Radians.fromSeconds(context.frame.time.running * speed).invert) val shapeLine: Shape.Line = Shape .Line(Point(0), Point(30), Stroke(4, RGBA.Green)) .moveTo(180, 10) - .rotateTo(Radians.fromSeconds(context.running * speed)) + .rotateTo(Radians.fromSeconds(context.frame.time.running * speed)) val shapePolygon: Shape.Polygon = Shape @@ -88,13 +88,13 @@ object BoundsScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi Point(70, 20) ) .moveTo(180, 150) - .rotateTo(Radians.fromSeconds(context.running * speed).invert) + .rotateTo(Radians.fromSeconds(context.frame.time.running * speed).invert) val sprite: Sprite[Material.ImageEffects] = context.startUpData.dude.sprite .scaleBy(2, 2) .moveTo(50, 120) - .rotateTo(Radians.fromSeconds(context.running * speed)) + .rotateTo(Radians.fromSeconds(context.frame.time.running * speed)) .withBindingKey("Sprite bounds anim".bindingKey) val group: Group = @@ -103,14 +103,14 @@ object BoundsScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi Graphic(Rectangle(0, 0, 40, 40), 1, BoundsAssets.junctionBoxMaterialOff).moveBy(15, 15) ) .moveTo(200, 120) - .rotateTo(Radians.fromSeconds(context.running * speed)) + .rotateTo(Radians.fromSeconds(context.frame.time.running * speed)) .withRef(50, 50) val textBox = TextBox("Hello, World!", 100, 10).alignRight .withColor(RGBA.White) .withFontFamily(FontFamily(SandboxAssets.pixelFont.toString)) .moveTo(100, 50) - .rotateTo(Radians.fromSeconds(context.running * speed)) + .rotateTo(Radians.fromSeconds(context.frame.time.running * speed)) .withRef(50, 10) Outcome( @@ -121,19 +121,19 @@ object BoundsScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi Shape.Box(graphic.bounds, Fill.None, Stroke(1, RGBA.Green)), sprite, Shape.Box( - context.findBounds(sprite).getOrElse(Rectangle.zero), + context.services.bounds.find(sprite).getOrElse(Rectangle.zero), Fill.None, Stroke(1, RGBA.Red) ), text, Shape.Box( - context.findBounds(text).getOrElse(Rectangle.zero), + context.services.bounds.find(text).getOrElse(Rectangle.zero), Fill.None, Stroke(1, RGBA.Cyan) ), Shape.Circle(text.position, 3, Fill.None, Stroke(2, RGBA.White)), Shape.Circle( - context.findBounds(text).getOrElse(Rectangle.zero).center, + context.services.bounds.find(text).getOrElse(Rectangle.zero).center, 5, Fill.None, Stroke(2, RGBA.White) @@ -142,37 +142,37 @@ object BoundsScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi Shape.Circle(shapeBox.position, 3, Fill.None, Stroke(2, RGBA.White)), Shape .Circle( - context.findBounds(shapeBox).getOrElse(Rectangle.zero).center, + context.services.bounds.find(shapeBox).getOrElse(Rectangle.zero).center, 5, Fill.None, Stroke(2, RGBA.White) ), Shape.Box( - context.findBounds(shapeBox).getOrElse(Rectangle.zero), + context.services.bounds.find(shapeBox).getOrElse(Rectangle.zero), Fill.None, Stroke(1, RGBA.Magenta) ), shapeCircle, Shape.Box( - context.findBounds(shapeCircle).getOrElse(Rectangle.zero), + context.services.bounds.find(shapeCircle).getOrElse(Rectangle.zero), Fill.None, Stroke(1, RGBA.Magenta) ), shapeLine, Shape.Box( - context.findBounds(shapeLine).getOrElse(Rectangle.zero), + context.services.bounds.find(shapeLine).getOrElse(Rectangle.zero), Fill.None, Stroke(1, RGBA.Magenta) ), shapePolygon, Shape.Box( - context.findBounds(shapePolygon).getOrElse(Rectangle.zero), + context.services.bounds.find(shapePolygon).getOrElse(Rectangle.zero), Fill.None, Stroke(1, RGBA.Magenta) ), group, Shape.Box( - context.findBounds(group).getOrElse(Rectangle.zero), + context.services.bounds.find(group).getOrElse(Rectangle.zero), Fill.None, Stroke(1, RGBA.Yellow) ), diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/CameraScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/CameraScene.scala index 48c360e60..c20f949d8 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/CameraScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/CameraScene.scala @@ -72,14 +72,14 @@ object CameraScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi ).modifyCamera { case c: Camera.Fixed => c.toLookAt - .lookAt(context.mouse.position) - .rotateBy(Radians.fromSeconds(context.running * 0.2)) + .lookAt(context.frame.input.mouse.position) + .rotateBy(Radians.fromSeconds(context.frame.time.running * 0.2)) .withZoom(Zoom(0.75)) case c => c - // _.moveTo(orbit.at(context.running * 0.3)) - // .withZoom(zoom.at(context.running * 0.35)) + // _.moveTo(orbit.at(context.frame.time.running * 0.3)) + // .withZoom(zoom.at(context.frame.time.running * 0.35)) } ) } diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/CaptureScreenScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/CaptureScreenScene.scala index 1099bcce8..449580315 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/CaptureScreenScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/CaptureScreenScene.scala @@ -65,7 +65,7 @@ object CaptureScreenScene extends Scene[SandboxStartupData, SandboxGameModel, Sa val screenshots: Set[AssetType] = context // Capture 2 screenshots, 1 of the full screen and the other of the clipping rectangle // These are reduced by 0.125 so that it sits a quarter size of the real screen without further scaling - .captureScreen( + .services.screenCapture.captureScreen( Batch( // Get the full screen and scale it ScreenCaptureConfig.default @@ -104,7 +104,7 @@ object CaptureScreenScene extends Scene[SandboxStartupData, SandboxGameModel, Sa viewModel: CaptureScreenSceneViewModel ): Outcome[SceneUpdateFragment] = val screenshotScale = 0.3 - val viewPort = context.frameContext.startUpData.gameViewport.size / SandboxGame.magnificationLevel + val viewPort = context.startUpData.gameViewport.size / SandboxGame.magnificationLevel val bigRect = Rectangle((viewPort.width * screenshotScale).toInt, (viewPort.height * screenshotScale).toInt) val smallRect = Rectangle( 0, diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/ConfettiScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/ConfettiScene.scala index 6ac3a56d2..73b9e553f 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/ConfettiScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/ConfettiScene.scala @@ -42,11 +42,11 @@ object ConfettiScene extends Scene[SandboxStartupData, SandboxGameModel, Sandbox ): GlobalEvent => Outcome[ConfettiModel] = case FrameTick => - val pos = Signal.Orbit(context.startUpData.viewportCenter * 2, 100).at(context.running * 0.5).toPoint + val pos = Signal.Orbit(context.startUpData.viewportCenter * 2, 100).at(context.frame.time.running * 0.5).toPoint Outcome( model .spawn( - context.dice, + context.frame.dice, pos.x, pos.y, spawnCount diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/CratesScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/CratesScene.scala index 524f5bea3..6697dbd32 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/CratesScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/CratesScene.scala @@ -77,5 +77,5 @@ object CratesScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi ) ) ).addCloneBlanks(cloneBlanks) - .addLights(lights(move.at(context.running * 0.5))) + .addLights(lights(move.at(context.frame.time.running * 0.5))) ) diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/LightsScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/LightsScene.scala index 3b6db13bb..e5503a6d8 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/LightsScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/LightsScene.scala @@ -81,7 +81,7 @@ object LightsScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi DirectionLight(RGBA.Cyan.withAmount(0.1), RGBA.Cyan, Radians.zero), PointLight.default .withSpecular(RGBA.White) - .moveTo(context.mouse.position) + .moveTo(context.frame.input.mouse.position) .withColor(RGBA.Red.mix(RGBA.White, 0.1)) .withIntensity(2) .withFalloff(Falloff.smoothQuadratic.withRange(0, 80)), @@ -101,7 +101,7 @@ object LightsScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi Signal .Orbit(context.startUpData.viewportCenter, 80, Radians(0)) .affectTime(0.1) - .at(context.running) + .at(context.frame.time.running) .toPoint ) .modifyFalloff(_.withRange(0, 50)), @@ -113,7 +113,7 @@ object LightsScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi Signal .Orbit(context.startUpData.viewportCenter, 80, Radians(Radians.TAU.toDouble / 3)) .affectTime(0.1) - .at(context.running) + .at(context.frame.time.running) .toPoint ) .modifyFalloff(_.withRange(0, 50)), @@ -125,7 +125,7 @@ object LightsScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi Signal .Orbit(context.startUpData.viewportCenter, 80, Radians(Radians.TAU.toDouble / 3 * 2)) .affectTime(0.1) - .at(context.running) + .at(context.frame.time.running) .toPoint ) .modifyFalloff(_.withRange(0, 50)) diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/OriginalScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/OriginalScene.scala index 50a53f51f..ca6925368 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/OriginalScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/OriginalScene.scala @@ -49,11 +49,11 @@ object OriginalScene extends Scene[SandboxStartupData, SandboxGameModel, Sandbox ): Outcome[SceneUpdateFragment] = { val scene: SceneUpdateFragment = SandboxView - .updateView(model, viewModel, context.inputState.mouse, context.boundaryLocator) + .updateView(model, viewModel, context.frame.input.mouse, context.services.bounds) .addLayer( Layer( // viewModel.single.draw(gameTime, boundaryLocator) //|+| - viewModel.multi.draw(context.gameTime, context.boundaryLocator) + viewModel.multi.draw(context.frame.time, context.services.bounds) ).withDepth(Depth(1000)) ) diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/PathFindingScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/PathFindingScene.scala index b96858e83..e00b53bd1 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/PathFindingScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/PathFindingScene.scala @@ -56,8 +56,8 @@ object PathFindingScene extends Scene[SandboxStartupData, SandboxGameModel, Sand ) else // increase randomly the value at a random point - val n = context.dice.roll(model.data.length) - 1 - val v = (model.data(n) + context.dice.roll(increase)) % 256 + val n = context.frame.dice.roll(model.data.length) - 1 + val v = (model.data(n) + context.frame.dice.roll(increase)) % 256 model.data.update(n, v) Outcome(model) diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/RefractionScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/RefractionScene.scala index 5ead1bb1d..b61c09651 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/RefractionScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/RefractionScene.scala @@ -85,13 +85,13 @@ object RefractionScene extends Scene[SandboxStartupData, SandboxGameModel, Sandb .withBlending(Blending.Lighting(RGBA(0.2, 0.5, 0.3, 0.5))), Layer( distortion.moveTo(viewCenter + Point(50, 0)), - sliding.affectTime(0.3).at(context.gameTime.running) + sliding.affectTime(0.3).at(context.frame.time.running) ).withBlending( Refraction.blending( Signal.SmoothPulse .map(d => 0.25 * d) .affectTime(0.25) - .at(context.running) + .at(context.frame.time.running) ) ) ) diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/ShapesScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/ShapesScene.scala index cfca335bc..0957b9bf4 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/ShapesScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/ShapesScene.scala @@ -64,16 +64,16 @@ object ShapesScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi ): Outcome[SceneUpdateFragment] = { val circleGradient: Int = - Signal.SmoothPulse.map(d => 2 + (10 * d).toInt).at(context.running) + Signal.SmoothPulse.map(d => 2 + (10 * d).toInt).at(context.frame.time.running) val circlePosition: Point = - Signal.Orbit(Point(200, 150), 10).map(_.toPoint).affectTime(0.25).at(context.running) + Signal.Orbit(Point(200, 150), 10).map(_.toPoint).affectTime(0.25).at(context.frame.time.running) val lineThickness: Int = - Signal.SmoothPulse.map(d => (10 * d).toInt).at(context.running) + Signal.SmoothPulse.map(d => (10 * d).toInt).at(context.frame.time.running) val squareSize: Size = - val signal = Signal.SmoothPulse.map(d => (100 * d).toInt).affectTime(0.25).at(context.running) + val signal = Signal.SmoothPulse.map(d => (100 * d).toInt).affectTime(0.25).at(context.frame.time.running) Size( signal, @@ -115,21 +115,21 @@ object ShapesScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxVi Fill.LinearGradient(Point(0), RGBA.Magenta, Point(45), RGBA.Cyan), Stroke(4, RGBA.Black.withAlpha(0.75)) )( - Point(10, 10) - (Math.cos(Radians.fromSeconds(context.running).toDouble) * 5).toInt, - Point(20, 70) + (Math.sin(Radians.fromSeconds(context.running * Seconds(1.2)).toDouble) * 10).toInt, - Point(90, 90) + (Math.sin(Radians.fromSeconds(context.running * Seconds(0.8)).toDouble) * 6).toInt, - Point(70, 20) - (Math.cos(Radians.fromSeconds(context.running * Seconds(1.5)).toDouble) * 8).toInt + Point(10, 10) - (Math.cos(Radians.fromSeconds(context.frame.time.running).toDouble) * 5).toInt, + Point(20, 70) + (Math.sin(Radians.fromSeconds(context.frame.time.running * Seconds(1.2)).toDouble) * 10).toInt, + Point(90, 90) + (Math.sin(Radians.fromSeconds(context.frame.time.running * Seconds(0.8)).toDouble) * 6).toInt, + Point(70, 20) - (Math.cos(Radians.fromSeconds(context.frame.time.running * Seconds(1.5)).toDouble) * 8).toInt ) .moveTo(175, 10), blue, Shape.Box( - context.findBounds(blue).getOrElse(Rectangle.zero), + context.services.bounds.get(blue), Fill.None, Stroke(1, RGBA.Blue) ), // outline blue red, Shape.Box( - context.findBounds(red).getOrElse(Rectangle.zero), + context.services.bounds.get(red), Fill.None, Stroke(1, RGBA.Red) ), // outline red diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/TextBoxScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/TextBoxScene.scala index fc584e745..fec8efb53 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/TextBoxScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/TextBoxScene.scala @@ -63,7 +63,7 @@ object TextBoxScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxV 4, LightingAssets.junctionBoxMaterialOn.modifyLighting(_ => LightingModel.Unlit) ).moveTo(10, 10), - Shape.Box(context.findBounds(tb).getOrElse(Rectangle.zero), Fill.None).withStroke(Stroke(1, RGBA.Cyan)), + Shape.Box(context.services.bounds.get(tb), Fill.None).withStroke(Stroke(1, RGBA.Cyan)), tb.withDepth(Depth(3)).bold, tb.moveTo(50, 65).withDepth(Depth(3)), tb.moveTo(50, 80) @@ -73,7 +73,7 @@ object TextBoxScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxV .withStroke(TextStroke(RGBA.Red, Pixels(1))), hello .modifyStyle(_.withSize(Pixels(20))) - .moveTo(Signal.Orbit(Point(180, 70), 20).affectTime(0.25).at(context.running).toPoint) + .moveTo(Signal.Orbit(Point(180, 70), 20).affectTime(0.25).at(context.frame.time.running).toPoint) .withDepth(Depth(2)), model.dude.dude.sprite.play().withDepth(Depth(1)), tb.moveTo(50, 120).withDepth(Depth(3)).alignLeft, diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/TimelineScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/TimelineScene.scala index 43a610664..7b14c67ca 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/TimelineScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/TimelineScene.scala @@ -107,12 +107,12 @@ object TimelineScene extends Scene[SandboxStartupData, SandboxGameModel, Sandbox Outcome( SceneUpdateFragment( - tl(2.seconds).atOrLast(context.running)(crate).toBatch ++ + tl(2.seconds).atOrLast(context.frame.time.running)(crate).toBatch ++ spriteTimeline - .at(context.running)(dude) + .at(context.frame.time.running)(dude) .toBatch ++ clipTimeline - .at(context.running)(trafficLights) + .at(context.frame.time.running)(trafficLights) .toBatch ) ) diff --git a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/UiScene.scala b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/UiScene.scala index 208311a80..39a63f7aa 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/UiScene.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/scenes/UiScene.scala @@ -46,7 +46,7 @@ object UiScene extends Scene[SandboxStartupData, SandboxGameModel, SandboxViewMo viewModel: UiSceneViewModel ): GlobalEvent => Outcome[UiSceneViewModel] = case FrameTick => - viewModel.update(context.mouse, context.frameContext.inputState.pointers) + viewModel.update(context.frame.input.mouse, context.frame.input.pointers) case Log(msg) => println(msg) diff --git a/indigo/tyrian-indigo-bridge/src/main/scala/tyrian/TyrianSubSystem.scala b/indigo/tyrian-indigo-bridge/src/main/scala/tyrian/TyrianSubSystem.scala index 4924aec94..d66119019 100644 --- a/indigo/tyrian-indigo-bridge/src/main/scala/tyrian/TyrianSubSystem.scala +++ b/indigo/tyrian-indigo-bridge/src/main/scala/tyrian/TyrianSubSystem.scala @@ -7,7 +7,7 @@ import indigo.shared.events.FrameTick import indigo.shared.events.GlobalEvent import indigo.shared.scenegraph.SceneUpdateFragment import indigo.shared.subsystems.SubSystem -import indigo.shared.subsystems.SubSystemFrameContext +import indigo.shared.subsystems.SubSystemContext import indigo.shared.subsystems.SubSystemId import scala.collection.mutable @@ -52,7 +52,7 @@ final case class TyrianSubSystem[F[_]: Async, A, Model]( def initialModel: Outcome[Unit] = Outcome(()) - def update(context: SubSystemFrameContext[ReferenceData], model: Unit): GlobalEvent => Outcome[Unit] = + def update(context: SubSystemContext[ReferenceData], model: Unit): GlobalEvent => Outcome[Unit] = case TyrianEvent.Send(value) => bridge.eventTarget.dispatchEvent(TyrianIndigoBridge.BridgeToTyrian(indigoGameId, value)) Outcome(model) @@ -63,7 +63,7 @@ final case class TyrianSubSystem[F[_]: Async, A, Model]( case _ => Outcome(model) - def present(context: SubSystemFrameContext[ReferenceData], model: Unit): Outcome[SceneUpdateFragment] = + def present(context: SubSystemContext[ReferenceData], model: Unit): Outcome[SceneUpdateFragment] = Outcome(SceneUpdateFragment.empty) enum TyrianEvent extends GlobalEvent: diff --git a/indigo/tyrian-sandbox/src/main/scala/example/game/GameScene.scala b/indigo/tyrian-sandbox/src/main/scala/example/game/GameScene.scala index bc0e227fa..947f47847 100644 --- a/indigo/tyrian-sandbox/src/main/scala/example/game/GameScene.scala +++ b/indigo/tyrian-sandbox/src/main/scala/example/game/GameScene.scala @@ -42,8 +42,8 @@ final case class GameScene(clockwise: Boolean) extends Scene[Unit, Unit, Unit]: viewModel: Unit ): Outcome[SceneUpdateFragment] = val rotateAmount = - if clockwise then Radians.fromSeconds(context.running * 0.25) - else Radians(-Radians.fromSeconds(context.running * 0.25).toDouble) + if clockwise then Radians.fromSeconds(context.frame.time.running * 0.25) + else Radians(-Radians.fromSeconds(context.frame.time.running * 0.25).toDouble) Outcome( SceneUpdateFragment( diff --git a/indigo/tyrian-sandbox/src/main/scala/example/game/MyAwesomeGame.scala b/indigo/tyrian-sandbox/src/main/scala/example/game/MyAwesomeGame.scala index 4f17d63ac..e98c52420 100644 --- a/indigo/tyrian-sandbox/src/main/scala/example/game/MyAwesomeGame.scala +++ b/indigo/tyrian-sandbox/src/main/scala/example/game/MyAwesomeGame.scala @@ -51,7 +51,7 @@ final case class MyAwesomeGame(tyrianSubSystem: TyrianSubSystem[IO, String, Unit Outcome(Startup.Success(())) def updateModel( - context: FrameContext[Unit], + context: Context[Unit], model: Unit ): GlobalEvent => Outcome[Unit] = case tyrianSubSystem.TyrianEvent.Receive(msg) => @@ -67,14 +67,14 @@ final case class MyAwesomeGame(tyrianSubSystem: TyrianSubSystem[IO, String, Unit Outcome(model) def updateViewModel( - context: FrameContext[Unit], + context: Context[Unit], model: Unit, viewModel: Unit ): GlobalEvent => Outcome[Unit] = _ => Outcome(viewModel) def present( - context: FrameContext[Unit], + context: Context[Unit], model: Unit, viewModel: Unit ): Outcome[SceneUpdateFragment] =