Skip to content
This repository was archived by the owner on Nov 20, 2025. It is now read-only.

Commit ad84514

Browse files
Fixed #906: All performers now present a Batch[SceneNode]
1 parent 5d7fc89 commit ad84514

6 files changed

Lines changed: 19 additions & 12 deletions

File tree

indigo/indigo-extras/src/main/scala/indigoextras/actors/Actor.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ import indigo.Outcome
55
import indigo.shared.collections.Batch
66
import indigo.shared.scenegraph.SceneNode
77

8+
/** An Actor is a standalone entity that can update and present itself, and communicates with the world by reading
9+
* shared immutable data (`ReferenceData`) from the game model, and by receiving and emitting events.
10+
*
11+
* The Actor typeclass allows you to define an Actor for any type, so long as you can meaningfully provide an update
12+
* and a present function for it.
13+
*/
814
trait Actor[ReferenceData, ActorType]:
915

1016
/** Update this actor.

indigo/indigo-extras/src/main/scala/indigoextras/performers/Performer.scala

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@ import indigo.shared.scenegraph.SceneNode
1010
* different levels of performer complexity. It’s meant to be fun, but also to suggest how much responsibility each
1111
* type takes on in the simulation. From Leads who take the starring roles, to silent Extras filling the background, to
1212
* Narrators who influence events without being seen — each has a role to play.
13-
*
14-
* @tparam ReferenceData
15-
* The type of reference data used by the performer.
1613
*/
1714
sealed trait Performer[ReferenceData]:
1815

@@ -42,7 +39,7 @@ object Performer:
4239

4340
/** Draw the performer
4441
*/
45-
def present(context: PerformerContext[ReferenceData]): SceneNode
42+
def present(context: PerformerContext[ReferenceData]): Batch[SceneNode]
4643

4744
val hasCollider: Boolean = false
4845

@@ -65,7 +62,7 @@ object Performer:
6562

6663
/** Draw the performer
6764
*/
68-
def present(context: PerformerContext[ReferenceData], collider: Collider[PerformerId]): SceneNode
65+
def present(context: PerformerContext[ReferenceData], collider: Collider[PerformerId]): Batch[SceneNode]
6966

7067
val hasCollider: Boolean = true
7168

indigo/indigo-extras/src/main/scala/indigoextras/performers/PerformerPool.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ final case class PerformerPool[ReferenceData](
9191
): Outcome[Batch[SceneNode]] =
9292
performer match
9393
case p: Performer.Extra[ReferenceData] =>
94-
Outcome(Batch(p.present(context)))
94+
Outcome(p.present(context))
9595

9696
case p: Performer.Stunt[ReferenceData] =>
9797
colliderLookup(p.id) match
9898
case None =>
9999
Outcome(Batch.empty)
100100

101101
case Some(c) =>
102-
Outcome(Batch(p.present(context, c)))
102+
Outcome(p.present(context, c))
103103

104104
case p: Performer.Support[ReferenceData] =>
105105
p.present(context)

indigo/sandbox/src/main/scala/com/example/sandbox/SandboxGame.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object SandboxGame extends IndigoGame[SandboxBootData, SandboxStartupData, Sandb
2222
val viewportHeight: Int = gameHeight * magnificationLevel // 256
2323

2424
def initialScene(bootData: SandboxBootData): Option[SceneName] =
25-
Some(WindowsScene.name)
25+
Some(PerformerScene.name)
2626

2727
def scenes(bootData: SandboxBootData): NonEmptyList[Scene[SandboxStartupData, SandboxGameModel, SandboxViewModel]] =
2828
NonEmptyList(

indigo/sandbox/src/main/scala/com/example/sandbox/scenes/PerformerPhysicsScene.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,14 +125,16 @@ final case class ZombiePerformer(
125125

126126
collider.withVelocity(collider.velocity + (toTarget * acceleration))
127127

128-
def present(context: PerformerContext[Point], collider: Collider[PerformerId]): SceneNode =
128+
def present(context: PerformerContext[Point], collider: Collider[PerformerId]): Batch[SceneNode] =
129129
val color =
130130
index % 3 match
131131
case 0 => RGBA.Cyan
132132
case 1 => RGBA.Yellow
133133
case _ => RGBA.SlateGray
134134

135-
Shape.Circle(Circle(collider.position.toPoint, radius), Fill.Color(color), Stroke(1, RGBA.White))
135+
Batch(
136+
Shape.Circle(Circle(collider.position.toPoint, radius), Fill.Color(color), Stroke(1, RGBA.White))
137+
)
136138

137139
final case class ZombieTargetPerformer() extends Performer.Lead[Point]:
138140
def id: PerformerId = ZombieTargetPerformer.id

indigo/sandbox/src/main/scala/com/example/sandbox/scenes/PerformerScene.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,5 +229,7 @@ final case class Follower(
229229

230230
this.copy(position = newPosition)
231231

232-
def present(context: PerformerContext[Point]): SceneNode =
233-
Shape.Circle(Circle(position.toPoint, size), Fill.Color(RGBA.Green.withAlpha(alpha)), Stroke(2, RGBA.Black))
232+
def present(context: PerformerContext[Point]): Batch[SceneNode] =
233+
Batch(
234+
Shape.Circle(Circle(position.toPoint, size), Fill.Color(RGBA.Green.withAlpha(alpha)), Stroke(2, RGBA.Black))
235+
)

0 commit comments

Comments
 (0)