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

Commit aee6155

Browse files
Fixed #905: Bug where performer physics models were updating too frequently
1 parent 8b5290f commit aee6155

1 file changed

Lines changed: 43 additions & 34 deletions

File tree

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

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import indigo.physics.*
44
import indigo.shared.Outcome
55
import indigo.shared.collections.Batch
66
import indigo.shared.datatypes.Vector2
7+
import indigo.shared.events.FrameTick
78
import indigo.shared.events.GlobalEvent
89
import indigo.shared.scenegraph.Layer
910
import indigo.shared.scenegraph.LayerKey
@@ -187,48 +188,56 @@ object StageManager:
187188
def update(
188189
context: SubSystemContext[?],
189190
model: ReferenceData
190-
): GlobalEvent => Outcome[Model[ReferenceData]] = e =>
191-
val ctx =
192-
PerformerContext(
193-
findById,
194-
findColliderById,
195-
model,
196-
context
197-
)
191+
): GlobalEvent => Outcome[Model[ReferenceData]] =
192+
case FrameTick =>
193+
val ctx =
194+
PerformerContext(
195+
findById,
196+
findColliderById,
197+
model,
198+
context
199+
)
198200

199-
val updatedPools =
200-
Batch.fromMap(pools).map((k, p) => p.update(context, model)(e).map(p => k -> p)).sequence
201+
val updatedPools =
202+
Batch.fromMap(pools).map((k, p) => p.update(context, model)(FrameTick).map(p => k -> p)).sequence
201203

202-
val updatedWorld =
203-
val physicalPerformers =
204-
updatedPools
205-
.map(
206-
_.map(_._2).flatMap(
207-
_.performers.filter(_.hasCollider)
204+
val updatedWorld =
205+
val physicalPerformers =
206+
updatedPools
207+
.map(
208+
_.map(_._2).flatMap(
209+
_.performers.filter(_.hasCollider)
210+
)
208211
)
209-
)
210212

211-
physicalPerformers
212-
.flatMap(
213-
_.foldLeft(world) { (w, p) =>
214-
w.modifyByTag(p.id) { c =>
215-
p match
216-
case p: Performer.Stunt[?] =>
217-
p.updateCollider(ctx, c)
213+
physicalPerformers
214+
.flatMap(
215+
_.foldLeft(world) { (w, p) =>
216+
w.modifyByTag(p.id) { c =>
217+
p match
218+
case p: Performer.Stunt[?] =>
219+
p.updateCollider(ctx, c)
218220

219-
case p: Performer.Lead[?] =>
220-
p.updateCollider(ctx, c)
221+
case p: Performer.Lead[?] =>
222+
p.updateCollider(ctx, c)
221223

222-
case _ =>
223-
c
224+
case _ =>
225+
c
226+
}
224227
}
225-
}
226-
.update(context.frame.time.delta)
227-
)
228+
.update(context.frame.time.delta)
229+
)
230+
231+
updatedWorld
232+
.combine(updatedPools)
233+
.map((nextWorld, nextModel) => this.copy(pools = nextModel.toMap, world = nextWorld))
234+
235+
case e =>
236+
val updatedPools =
237+
Batch.fromMap(pools).map((k, p) => p.update(context, model)(e).map(p => k -> p)).sequence
228238

229-
updatedWorld
230-
.combine(updatedPools)
231-
.map((nextWorld, nextModel) => this.copy(pools = nextModel.toMap, world = nextWorld))
239+
updatedPools
240+
.map(nextModel => this.copy(pools = nextModel.toMap))
232241

233242
def present(
234243
context: SubSystemContext[?],

0 commit comments

Comments
 (0)