From f9300c821340fbbd186eefbe8bc4ee7ef6454bd7 Mon Sep 17 00:00:00 2001 From: Mike Lester Date: Wed, 11 Dec 2024 09:05:10 +0200 Subject: [PATCH] Fix LoopMode.Repeat implementation to support domains larger than double the original This matches the original C++ implementation. The situation I was seeing was: LoopMode: Repeat, StartFrame: 0, EndFrame: 2, `applyLoopMode(22.1)` should return `0.1` but would instead return `20.1` --- src/Common/JSYSTEM/J3D/J3DGraphAnimator.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Common/JSYSTEM/J3D/J3DGraphAnimator.ts b/src/Common/JSYSTEM/J3D/J3DGraphAnimator.ts index 4761a13f8..83ab7fabb 100644 --- a/src/Common/JSYSTEM/J3D/J3DGraphAnimator.ts +++ b/src/Common/JSYSTEM/J3D/J3DGraphAnimator.ts @@ -123,10 +123,14 @@ export class J3DFrameCtrl { if (timeInFrames >= this.endFrame) return this.startFrame; } else if (this.loopMode === LoopMode.Repeat) { - if (timeInFrames >= this.endFrame) - return timeInFrames - (this.endFrame - this.repeatStartFrame); - if (timeInFrames < this.startFrame) - return timeInFrames + (this.repeatStartFrame - this.startFrame); + while (timeInFrames >= this.endFrame) { + if (this.endFrame - this.repeatStartFrame <= 0.0) { break; } + timeInFrames -= (this.endFrame - this.repeatStartFrame); + } + while (timeInFrames < this.startFrame) { + if (this.repeatStartFrame - this.startFrame <= 0.0) { break; } + timeInFrames += (this.repeatStartFrame - this.startFrame); + } } else if (this.loopMode === LoopMode.MirroredOnce) { if (timeInFrames >= this.endFrame) return this.endFrame - (timeInFrames - this.endFrame);