-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from JD557/pure-render-loop
Split render loops into pure and impure render loops
- Loading branch information
Showing
11 changed files
with
109 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
core/js/src/test/scala/eu/joaocosta/minart/backend/JsRenderLoopSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
package eu.joaocosta.minart.backend | ||
|
||
import eu.joaocosta.minart.backend._ | ||
import eu.joaocosta.minart.core._ | ||
|
||
class JsRenderLoopSpec extends RenderLoopTests { | ||
lazy val renderLoop: RenderLoop = JsRenderLoop | ||
lazy val renderLoop: ImpureRenderLoop = JsRenderLoop | ||
lazy val renderLoopName: String = "JsRenderLoop" | ||
override lazy val testLoop: Boolean = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 2 additions & 1 deletion
3
core/jvm/src/test/scala/eu/joaocosta/minart/backend/JavaRenderLoopSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,9 @@ | ||
package eu.joaocosta.minart.backend | ||
|
||
import eu.joaocosta.minart.backend._ | ||
import eu.joaocosta.minart.core._ | ||
|
||
class JavaRenderLoopSpec extends RenderLoopTests { | ||
lazy val renderLoop: RenderLoop = JavaRenderLoop | ||
lazy val renderLoop: ImpureRenderLoop = JavaRenderLoop | ||
lazy val renderLoopName: String = "JavaRenderLoop" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
core/shared/src/main/scala/eu/joaocosta/minart/backend/ImpureRenderLoop.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package eu.joaocosta.minart.backend | ||
|
||
import eu.joaocosta.minart.core._ | ||
import eu.joaocosta.minart.backend.defaults.DefaultBackend | ||
|
||
trait ImpureRenderLoop extends RenderLoop[Function1, Function2] { | ||
def infiniteRenderLoop[S]( | ||
canvasManager: CanvasManager, | ||
initialState: S, | ||
renderFrame: (Canvas, S) => S, | ||
frameRate: FrameRate): Unit = | ||
finiteRenderLoop(canvasManager, initialState, renderFrame, (_: S) => false, frameRate) | ||
|
||
def infiniteRenderLoop( | ||
canvasManager: CanvasManager, | ||
renderFrame: Canvas => Unit, | ||
frameRate: FrameRate): Unit = | ||
infiniteRenderLoop(canvasManager, (), (c: Canvas, _: Unit) => renderFrame(c), frameRate) | ||
} | ||
|
||
object ImpureRenderLoop { | ||
/** | ||
* Returns an [[ImpureRenderLoop]] for the default backend for the target platform. | ||
*/ | ||
def default()(implicit d: DefaultBackend[Any, ImpureRenderLoop]): ImpureRenderLoop = | ||
d.defaultValue(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
pure/shared/src/main/scala/eu/joaocosta/minart/pure/backend/PureRenderLoop.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package eu.joaocosta.minart.pure.backend | ||
|
||
import eu.joaocosta.minart.backend.ImpureRenderLoop | ||
import eu.joaocosta.minart.backend.defaults.DefaultBackend | ||
import eu.joaocosta.minart.core._ | ||
import eu.joaocosta.minart.pure._ | ||
|
||
class PureRenderLoop(impureRenderLoop: ImpureRenderLoop) extends RenderLoop[RIO, PureRenderLoop.StateCanvasIO] { | ||
|
||
def finiteRenderLoop[S]( | ||
canvasManager: CanvasManager, | ||
initialState: S, | ||
renderFrame: S => CanvasIO[S], | ||
terminateWhen: S => Boolean, | ||
frameRate: FrameRate): Unit = | ||
impureRenderLoop.finiteRenderLoop[S]( | ||
canvasManager, | ||
initialState, | ||
(canvas, state) => renderFrame(state).run(canvas), | ||
terminateWhen, | ||
frameRate) | ||
|
||
def infiniteRenderLoop[S]( | ||
canvasManager: CanvasManager, | ||
initialState: S, | ||
renderFrame: S => CanvasIO[S], | ||
frameRate: FrameRate): Unit = | ||
impureRenderLoop.infiniteRenderLoop[S]( | ||
canvasManager, | ||
initialState, | ||
(canvas, state) => renderFrame(state).run(canvas), | ||
frameRate) | ||
|
||
def infiniteRenderLoop( | ||
canvasManager: CanvasManager, | ||
renderFrame: CanvasIO[Unit], | ||
frameRate: FrameRate): Unit = | ||
impureRenderLoop.infiniteRenderLoop( | ||
canvasManager, | ||
canvas => renderFrame.run(canvas), | ||
frameRate) | ||
|
||
def singleFrame( | ||
canvasManager: CanvasManager, | ||
renderFrame: CanvasIO[Unit]): Unit = | ||
impureRenderLoop.singleFrame( | ||
canvasManager, | ||
canvas => renderFrame.run(canvas)) | ||
} | ||
|
||
object PureRenderLoop { | ||
type StateCanvasIO[-Canvas, -State, +A] = Function1[State, RIO[Canvas, A]] | ||
|
||
/** | ||
* Returns [[PureRenderLoop]] for the default backend for the target platform. | ||
*/ | ||
def default()(implicit d: DefaultBackend[Any, ImpureRenderLoop]): PureRenderLoop = | ||
new PureRenderLoop(d.defaultValue(())) | ||
} |