Skip to content

Commit

Permalink
Moves renderer out of FrameContext and replaces it with a method pass…
Browse files Browse the repository at this point in the history
…through
  • Loading branch information
hobnob committed Nov 7, 2024
1 parent 729b504 commit 61198b5
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +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)
val frameContext =
new FrameContext[StartUpData](gameTime, dice, inputState, boundaryLocator, startUpData, renderer.captureScreen)

val processSceneViewModel: (Model, ViewModel) => Outcome[ViewModel] = (m, vm) =>
globalEvents
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ final class StandardFrameProcessor[StartUpData, Model, ViewModel](
boundaryLocator: BoundaryLocator,
renderer: => Renderer
): Outcome[(Model, ViewModel, SceneUpdateFragment)] =
val frameContext = new FrameContext[StartUpData](gameTime, dice, inputState, boundaryLocator, startUpData, renderer)
val frameContext =
new FrameContext[StartUpData](gameTime, dice, inputState, boundaryLocator, startUpData, renderer.captureScreen)
Outcome.join(
for {
m <- processModel(frameContext, model, globalEvents)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,6 @@ trait Renderer:
*/
def captureScreen(captureConfig: Batch[ScreenCaptureConfig]): Batch[Either[String, AssetType.Image]]

/** Capture the screen as an image, with the specified configuration
*
* @param captureOption
* 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")
}

object Renderer:
def blackHole = new Renderer {
def renderingTechnology: RenderingTechnology = RenderingTechnology.WebGL1
Expand Down
33 changes: 28 additions & 5 deletions indigo/indigo/src/main/scala/indigo/shared/FrameContext.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package indigo.shared

import indigo.platform.renderer.Renderer
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
Expand Down Expand Up @@ -31,11 +33,10 @@ final class FrameContext[StartUpData](
val inputState: InputState,
val boundaryLocator: BoundaryLocator,
_startUpData: => StartUpData,
_renderer: => Renderer
_captureScreen: Batch[ScreenCaptureConfig] => Batch[Either[String, AssetType.Image]]
):

lazy val startUpData = _startUpData
lazy private val renderer = _renderer
lazy val startUpData = _startUpData

export gameTime.running
export gameTime.delta
Expand All @@ -44,4 +45,26 @@ final class FrameContext[StartUpData](
export inputState.gamepad
export boundaryLocator.findBounds
export boundaryLocator.bounds
export renderer.captureScreen

/** 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")
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ final case class SubSystemFrameContext[ReferenceData](
inputState,
boundaryLocator,
(),
Renderer.blackHole
Renderer.blackHole.captureScreen
)

object SubSystemFrameContext {
Expand Down

0 comments on commit 61198b5

Please sign in to comment.