Skip to content

Commit

Permalink
Updates capture support so it's now available in the FrameContext
Browse files Browse the repository at this point in the history
  • Loading branch information
hobnob committed Oct 10, 2024
1 parent c0423bf commit e08c1e9
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 36 deletions.
Empty file modified indigo/build.sh
100644 → 100755
Empty file.
2 changes: 1 addition & 1 deletion indigo/indigo/src/main/scala/indigo/BootResult.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 7 additions & 7 deletions indigo/indigo/src/main/scala/indigo/IndigoGame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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]]

Expand All @@ -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.
*/
Expand Down Expand Up @@ -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]
Expand All @@ -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],
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)]
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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](
Expand All @@ -375,7 +377,8 @@ object GameEngine {
initialModel,
initialViewModel(initialModel),
frameProccessor,
startFrameLocked
startFrameLocked,
renderer
)
)

Expand Down
9 changes: 6 additions & 3 deletions indigo/indigo/src/main/scala/indigo/gameengine/GameLoop.scala
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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"))
Expand Down Expand Up @@ -130,7 +132,8 @@ final class GameLoop[StartUpData, GameModel, ViewModel](
events,
_inputState,
Dice.fromSeconds(gameTime.running),
boundaryLocator
boundaryLocator,
renderer
)

// Persist frame state
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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(
Expand Down
8 changes: 6 additions & 2 deletions indigo/indigo/src/main/scala/indigo/shared/FrameContext.scala
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand All @@ -41,3 +44,4 @@ final class FrameContext[StartUpData](
export inputState.gamepad
export boundaryLocator.findBounds
export boundaryLocator.bounds
export renderer.captureScreen
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -52,7 +53,8 @@ final case class SubSystemFrameContext[ReferenceData](
dice,
inputState,
boundaryLocator,
()
(),
Renderer.blackHole
)

object SubSystemFrameContext {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -77,7 +78,8 @@ object SandboxGame extends IndigoGame[SandboxBootData, SandboxStartupData, Sandb
BoundingCircleScene,
LineReflectionScene,
CameraWithCloneTilesScene,
PathFindingScene
PathFindingScene,
CaptureScreenScene
)

val eventFilters: EventFilters = EventFilters.Permissive
Expand Down

0 comments on commit e08c1e9

Please sign in to comment.