diff --git a/indigo/build.sh b/indigo/build.sh old mode 100644 new mode 100755 diff --git a/indigo/indigo/src/main/scala/indigo/BootResult.scala b/indigo/indigo/src/main/scala/indigo/BootResult.scala index 9a6860e53..e09f9ba1d 100644 --- a/indigo/indigo/src/main/scala/indigo/BootResult.scala +++ b/indigo/indigo/src/main/scala/indigo/BootResult.scala @@ -4,7 +4,7 @@ import indigo.shared.shader.Shader import indigo.shared.subsystems.SubSystem /** The game bootstrapping process results in a `BootResult`, which only occurs once on initial game load. The boot - * result decribes all of the initial values of your game such as it's configuration, data, animations, assets, fonts, + * result describes all of the initial values of your game such as it's configuration, data, animations, assets, fonts, * subsystems, and shaders. You can add additional assets, animations, fonts, and shaders later during the setup * process, so it is recommended that you only load the bare minimum needed to get your game going during the boot * phase. diff --git a/indigo/indigo/src/main/scala/indigo/IndigoGame.scala b/indigo/indigo/src/main/scala/indigo/IndigoGame.scala index 254d1672b..a7fd0014c 100644 --- a/indigo/indigo/src/main/scala/indigo/IndigoGame.scala +++ b/indigo/indigo/src/main/scala/indigo/IndigoGame.scala @@ -51,12 +51,12 @@ trait IndigoGame[BootData, StartUpData, Model, ViewModel] extends GameLauncher[S def eventFilters: EventFilters /** `boot` provides the initial boot up function for your game, accepting commandline-like arguments and allowing you - * to declare pre-requist assets assets and data that must be in place for your game to get going. + * to declare pre-request assets assets and data that must be in place for your game to get going. * * @param flags * A simply key-value object/map passed in during initial boot. * @return - * Bootup data consisting of a custom data type, animations, subsytems, assets, fonts, and the game's config. + * Bootup data consisting of a custom data type, animations, subsystems, assets, fonts, and the game's config. */ def boot(flags: Map[String, String]): Outcome[BootResult[BootData, Model]] @@ -70,7 +70,7 @@ trait IndigoGame[BootData, StartUpData, Model, ViewModel] extends GameLauncher[S * @param assetCollection * Access to the Asset collection in order to, for example, parse text files. * @param dice - * Psuedorandom number generator + * Pseudorandom number generator * @return * Return start up data, which can include animations and fonts that could not be declared at boot time. */ @@ -102,7 +102,7 @@ trait IndigoGame[BootData, StartUpData, Model, ViewModel] extends GameLauncher[S * @param model * The latest version of the model to read from. * @return - * A function that maps GlobalEvent's to the next version of your model, and encapsuates failures or resulting + * 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] @@ -118,8 +118,8 @@ trait IndigoGame[BootData, StartUpData, Model, ViewModel] extends GameLauncher[S * @param viewModel * The latest version of the view model to read from. * @return - * A function that maps GlobalEvent's to the next version of your view model, and encapsuates failures or resulting - * events within the Outcome wrapper. + * A function that maps GlobalEvent's to the next version of your view model, and encapsulates failures or + * resulting events within the Outcome wrapper. */ def updateViewModel( context: FrameContext[StartUpData], @@ -138,7 +138,7 @@ trait IndigoGame[BootData, StartUpData, Model, ViewModel] extends GameLauncher[S * @param viewModel * The latest version of the view model to read from. * @return - * A function that produces a description of what to present next, and encapsuates failures or resulting events + * 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] diff --git a/indigo/indigo/src/main/scala/indigo/entry/ScenesFrameProcessor.scala b/indigo/indigo/src/main/scala/indigo/entry/ScenesFrameProcessor.scala index 08332d0ca..4b58252f4 100644 --- a/indigo/indigo/src/main/scala/indigo/entry/ScenesFrameProcessor.scala +++ b/indigo/indigo/src/main/scala/indigo/entry/ScenesFrameProcessor.scala @@ -1,11 +1,14 @@ package indigo.entry import indigo.gameengine.FrameProcessor +import indigo.platform.renderer.Renderer import indigo.scenes.SceneManager import indigo.shared.BoundaryLocator import indigo.shared.FrameContext import indigo.shared.Outcome import indigo.shared.collections.Batch +import indigo.shared.datatypes.BindingKey +import indigo.shared.datatypes.Rectangle import indigo.shared.dice.Dice import indigo.shared.events.EventFilters import indigo.shared.events.GlobalEvent @@ -33,10 +36,11 @@ final class ScenesFrameProcessor[StartUpData, Model, ViewModel]( globalEvents: Batch[GlobalEvent], inputState: InputState, dice: Dice, - boundaryLocator: BoundaryLocator + boundaryLocator: BoundaryLocator, + renderer: => Renderer ): Outcome[(Model, ViewModel, SceneUpdateFragment)] = { - val frameContext = new FrameContext[StartUpData](gameTime, dice, inputState, boundaryLocator, startUpData) + val frameContext = new FrameContext[StartUpData](gameTime, dice, inputState, boundaryLocator, startUpData, renderer) val processSceneViewModel: (Model, ViewModel) => Outcome[ViewModel] = (m, vm) => globalEvents diff --git a/indigo/indigo/src/main/scala/indigo/entry/StandardFrameProcessor.scala b/indigo/indigo/src/main/scala/indigo/entry/StandardFrameProcessor.scala index 8a306b322..aa69539b1 100644 --- a/indigo/indigo/src/main/scala/indigo/entry/StandardFrameProcessor.scala +++ b/indigo/indigo/src/main/scala/indigo/entry/StandardFrameProcessor.scala @@ -1,6 +1,7 @@ package indigo.entry import indigo.gameengine.FrameProcessor +import indigo.platform.renderer.Renderer import indigo.shared.BoundaryLocator import indigo.shared.FrameContext import indigo.shared.Outcome @@ -31,9 +32,10 @@ final class StandardFrameProcessor[StartUpData, Model, ViewModel]( globalEvents: Batch[GlobalEvent], inputState: InputState, dice: Dice, - boundaryLocator: BoundaryLocator + boundaryLocator: BoundaryLocator, + renderer: => Renderer ): Outcome[(Model, ViewModel, SceneUpdateFragment)] = - val frameContext = new FrameContext[StartUpData](gameTime, dice, inputState, boundaryLocator, startUpData) + val frameContext = new FrameContext[StartUpData](gameTime, dice, inputState, boundaryLocator, startUpData, renderer) Outcome.join( for { m <- processModel(frameContext, model, globalEvents) diff --git a/indigo/indigo/src/main/scala/indigo/gameengine/FrameProcessor.scala b/indigo/indigo/src/main/scala/indigo/gameengine/FrameProcessor.scala index ed31e6335..eff5552eb 100644 --- a/indigo/indigo/src/main/scala/indigo/gameengine/FrameProcessor.scala +++ b/indigo/indigo/src/main/scala/indigo/gameengine/FrameProcessor.scala @@ -1,5 +1,6 @@ package indigo.gameengine +import indigo.platform.renderer.Renderer import indigo.shared.BoundaryLocator import indigo.shared.Outcome import indigo.shared.collections.Batch @@ -18,5 +19,6 @@ trait FrameProcessor[StartUpData, Model, ViewModel]: globalEvents: Batch[GlobalEvent], inputState: InputState, dice: Dice, - boundaryLocator: BoundaryLocator + boundaryLocator: BoundaryLocator, + renderer: => Renderer ): Outcome[(Model, ViewModel, SceneUpdateFragment)] diff --git a/indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala b/indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala index b3993dcb7..c00de6e1c 100644 --- a/indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala +++ b/indigo/indigo/src/main/scala/indigo/gameengine/GameEngine.scala @@ -227,7 +227,8 @@ final class GameEngine[StartUpData, GameModel, ViewModel]( m, vm, frameProccessor, - !firstRun // If this isn't the first run, start with it frame locked. + !firstRun, // If this isn't the first run, start with it frame locked. + renderer ) } yield { renderer = rendererAndAssetMapping._1 @@ -363,7 +364,8 @@ object GameEngine { initialModel: GameModel, initialViewModel: GameModel => ViewModel, frameProccessor: FrameProcessor[StartUpData, GameModel, ViewModel], - startFrameLocked: Boolean + startFrameLocked: Boolean, + renderer: => Renderer ): Outcome[GameLoop[StartUpData, GameModel, ViewModel]] = Outcome( new GameLoop[StartUpData, GameModel, ViewModel]( @@ -375,7 +377,8 @@ object GameEngine { initialModel, initialViewModel(initialModel), frameProccessor, - startFrameLocked + startFrameLocked, + renderer ) ) diff --git a/indigo/indigo/src/main/scala/indigo/gameengine/GameLoop.scala b/indigo/indigo/src/main/scala/indigo/gameengine/GameLoop.scala index d841396a8..977739656 100644 --- a/indigo/indigo/src/main/scala/indigo/gameengine/GameLoop.scala +++ b/indigo/indigo/src/main/scala/indigo/gameengine/GameLoop.scala @@ -1,6 +1,7 @@ package indigo.gameengine import indigo.platform.assets.AssetCollection +import indigo.platform.renderer.Renderer import indigo.shared.BoundaryLocator import indigo.shared.IndigoLogger import indigo.shared.Outcome @@ -12,6 +13,7 @@ import indigo.shared.events.GlobalEvent import indigo.shared.events.IndigoSystemEvent import indigo.shared.events.InputEvent import indigo.shared.events.InputState +import indigo.shared.platform.ProcessedSceneData import indigo.shared.platform.SceneProcessor import indigo.shared.scenegraph.SceneUpdateFragment import indigo.shared.time.GameTime @@ -20,7 +22,6 @@ import indigo.shared.time.Seconds import scala.collection.mutable import scala.scalajs.js.JSConverters._ -import indigo.shared.platform.ProcessedSceneData final class GameLoop[StartUpData, GameModel, ViewModel]( rebuildGameLoop: AssetCollection => Unit, @@ -31,7 +32,8 @@ final class GameLoop[StartUpData, GameModel, ViewModel]( initialModel: GameModel, initialViewModel: ViewModel, frameProcessor: FrameProcessor[StartUpData, GameModel, ViewModel], - startFrameLocked: Boolean + startFrameLocked: Boolean, + renderer: => Renderer ): @SuppressWarnings(Array("scalafix:DisableSyntax.var")) @@ -130,7 +132,8 @@ final class GameLoop[StartUpData, GameModel, ViewModel]( events, _inputState, Dice.fromSeconds(gameTime.running), - boundaryLocator + boundaryLocator, + renderer ) // Persist frame state diff --git a/indigo/indigo/src/main/scala/indigo/platform/renderer/Renderer.scala b/indigo/indigo/src/main/scala/indigo/platform/renderer/Renderer.scala index 9d312a150..6dfaccf60 100644 --- a/indigo/indigo/src/main/scala/indigo/platform/renderer/Renderer.scala +++ b/indigo/indigo/src/main/scala/indigo/platform/renderer/Renderer.scala @@ -1,14 +1,14 @@ package indigo.platform.renderer +import indigo.shared.collections.Batch import indigo.shared.config.RenderingTechnology +import indigo.shared.datatypes.BindingKey +import indigo.shared.datatypes.Rectangle +import indigo.shared.datatypes.Size import indigo.shared.datatypes.mutable.CheapMatrix4 import indigo.shared.platform.ProcessedSceneData import indigo.shared.shader.RawShaderCode import indigo.shared.time.Seconds -import indigo.shared.datatypes.Rectangle -import indigo.shared.datatypes.Size -import indigo.shared.collections.Batch -import indigo.shared.datatypes.BindingKey trait Renderer: def renderingTechnology: RenderingTechnology @@ -22,3 +22,15 @@ trait Renderer: clippingRect: Rectangle = Rectangle(Size(screenWidth, screenHeight)), excludeLayers: Batch[BindingKey] = Batch.empty ): Batch[Byte] + +object Renderer: + def blackHole = new Renderer { + def renderingTechnology: RenderingTechnology = RenderingTechnology.WebGL1 + def screenWidth: Int = 0 + def screenHeight: Int = 0 + def orthographicProjectionMatrix: CheapMatrix4 = CheapMatrix4.identity + + def init(shaders: Set[RawShaderCode]): Unit = () + def drawScene(sceneData: ProcessedSceneData, runningTime: Seconds): Unit = () + def captureScreen(clippingRect: Rectangle, excludeLayers: Batch[BindingKey]): Batch[Byte] = Batch.empty + } diff --git a/indigo/indigo/src/main/scala/indigo/platform/renderer/webgl1/RendererWebGL1.scala b/indigo/indigo/src/main/scala/indigo/platform/renderer/webgl1/RendererWebGL1.scala index b0773bb76..05e85d58d 100644 --- a/indigo/indigo/src/main/scala/indigo/platform/renderer/webgl1/RendererWebGL1.scala +++ b/indigo/indigo/src/main/scala/indigo/platform/renderer/webgl1/RendererWebGL1.scala @@ -8,9 +8,13 @@ import indigo.platform.renderer.shared.ContextAndCanvas import indigo.platform.renderer.shared.LoadedTextureAsset import indigo.platform.renderer.shared.TextureLookupResult import indigo.platform.renderer.shared.WebGLHelper +import indigo.shared.collections.Batch import indigo.shared.config.GameViewport import indigo.shared.config.RenderingTechnology +import indigo.shared.datatypes.BindingKey import indigo.shared.datatypes.Radians +import indigo.shared.datatypes.Rectangle +import indigo.shared.datatypes.Size import indigo.shared.datatypes.mutable.CheapMatrix4 import indigo.shared.display.DisplayEntity import indigo.shared.display.DisplayGroup @@ -22,19 +26,15 @@ import indigo.shared.platform.RendererConfig import indigo.shared.scenegraph.Camera import indigo.shared.shader.RawShaderCode import indigo.shared.time.Seconds +import org.scalajs.dom import org.scalajs.dom.WebGLBuffer import org.scalajs.dom.WebGLProgram import org.scalajs.dom.WebGLRenderingContext import org.scalajs.dom.WebGLRenderingContext._ import org.scalajs.dom.WebGLUniformLocation -import org.scalajs.dom import org.scalajs.dom.html import scala.scalajs.js.typedarray.Float32Array -import indigo.shared.datatypes.Rectangle -import indigo.shared.datatypes.Size -import indigo.shared.collections.Batch -import indigo.shared.datatypes.BindingKey final class RendererWebGL1( config: RendererConfig, diff --git a/indigo/indigo/src/main/scala/indigo/platform/renderer/webgl2/RendererWebGL2.scala b/indigo/indigo/src/main/scala/indigo/platform/renderer/webgl2/RendererWebGL2.scala index 6184d1a34..5ffd5500c 100644 --- a/indigo/indigo/src/main/scala/indigo/platform/renderer/webgl2/RendererWebGL2.scala +++ b/indigo/indigo/src/main/scala/indigo/platform/renderer/webgl2/RendererWebGL2.scala @@ -1,5 +1,7 @@ package indigo.platform.renderer.webgl2 +import indigo.BindingKey +import indigo.Rectangle import indigo.facades.WebGL2RenderingContext import indigo.platform.assets.DynamicText import indigo.platform.events.GlobalEventStream @@ -12,10 +14,12 @@ import indigo.platform.renderer.shared.LoadedTextureAsset import indigo.platform.renderer.shared.TextureLookupResult import indigo.platform.renderer.shared.WebGLHelper import indigo.shared.QuickCache +import indigo.shared.collections.Batch import indigo.shared.config.GameViewport import indigo.shared.config.RenderingTechnology import indigo.shared.datatypes.RGBA import indigo.shared.datatypes.Radians +import indigo.shared.datatypes.Size import indigo.shared.datatypes.mutable.CheapMatrix4 import indigo.shared.events.ViewportResize import indigo.shared.platform.ProcessedSceneData @@ -37,10 +41,6 @@ import org.scalajs.dom.html import scala.scalajs.js.Dynamic import scala.scalajs.js.typedarray.Float32Array -import indigo.Rectangle -import indigo.BindingKey -import indigo.shared.collections.Batch -import indigo.shared.datatypes.Size @SuppressWarnings(Array("scalafix:DisableSyntax.null")) final class RendererWebGL2( diff --git a/indigo/indigo/src/main/scala/indigo/shared/FrameContext.scala b/indigo/indigo/src/main/scala/indigo/shared/FrameContext.scala index e76dd1d9b..7afd9de0e 100644 --- a/indigo/indigo/src/main/scala/indigo/shared/FrameContext.scala +++ b/indigo/indigo/src/main/scala/indigo/shared/FrameContext.scala @@ -1,5 +1,6 @@ package indigo.shared +import indigo.platform.renderer.Renderer import indigo.shared.datatypes.Rectangle import indigo.shared.dice.Dice import indigo.shared.events.InputState @@ -29,10 +30,12 @@ final class FrameContext[StartUpData]( val dice: Dice, val inputState: InputState, val boundaryLocator: BoundaryLocator, - _startUpData: => StartUpData + _startUpData: => StartUpData, + _renderer: => Renderer ): - lazy val startUpData = _startUpData + lazy val startUpData = _startUpData + lazy private val renderer = _renderer export gameTime.running export gameTime.delta @@ -41,3 +44,4 @@ final class FrameContext[StartUpData]( export inputState.gamepad export boundaryLocator.findBounds export boundaryLocator.bounds + export renderer.captureScreen diff --git a/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemFrameContext.scala b/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemFrameContext.scala index dc5e4c0eb..1af40b0e8 100644 --- a/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemFrameContext.scala +++ b/indigo/indigo/src/main/scala/indigo/shared/subsystems/SubSystemFrameContext.scala @@ -1,5 +1,6 @@ package indigo.shared.subsystems +import indigo.platform.renderer.Renderer import indigo.shared.BoundaryLocator import indigo.shared.FrameContext import indigo.shared.datatypes.Rectangle @@ -52,7 +53,8 @@ final case class SubSystemFrameContext[ReferenceData]( dice, inputState, boundaryLocator, - () + (), + Renderer.blackHole ) object SubSystemFrameContext { 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 3635c6893..966496850 100644 --- a/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxGame.scala +++ b/indigo/sandbox/src/main/scala/com/example/sandbox/SandboxGame.scala @@ -39,6 +39,7 @@ import indigoextras.subsystems.FPSCounter import indigoextras.ui.* import scala.scalajs.js.annotation.* +import com.example.sandbox.scenes.CaptureScreenScene @JSExportTopLevel("IndigoGame") object SandboxGame extends IndigoGame[SandboxBootData, SandboxStartupData, SandboxGameModel, SandboxViewModel]: @@ -77,7 +78,8 @@ object SandboxGame extends IndigoGame[SandboxBootData, SandboxStartupData, Sandb BoundingCircleScene, LineReflectionScene, CameraWithCloneTilesScene, - PathFindingScene + PathFindingScene, + CaptureScreenScene ) val eventFilters: EventFilters = EventFilters.Permissive