From 809828f0ba68244bbff5f2afe3e5a652c2f32100 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 6 Mar 2017 14:18:44 +0900 Subject: [PATCH] Improve NextFrame. --- osu.Game/Modes/LegacyReplay.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Game/Modes/LegacyReplay.cs b/osu.Game/Modes/LegacyReplay.cs index 0ed63b309e..c558280cb0 100644 --- a/osu.Game/Modes/LegacyReplay.cs +++ b/osu.Game/Modes/LegacyReplay.cs @@ -54,19 +54,22 @@ namespace osu.Game.Modes public class LegacyReplayInputHandler : ReplayInputHandler { private readonly List replayContent; - int currentFrameIndex; public LegacyReplayFrame CurrentFrame => !hasFrames ? null : replayContent[currentFrameIndex]; - public LegacyReplayFrame NextFrame => !hasFrames ? null : replayContent[MathHelper.Clamp(currentDirection > 0 ? currentFrameIndex + 1 : currentFrameIndex - 1, 0, replayContent.Count - 1)]; + public LegacyReplayFrame NextFrame => !hasFrames ? null : replayContent[nextFrameIndex]; + + int currentFrameIndex; + + private int nextFrameIndex => MathHelper.Clamp(currentFrameIndex + (currentDirection > 0 ? 1 : -1), 0, replayContent.Count - 1); public LegacyReplayInputHandler(List replayContent) { this.replayContent = replayContent; } - private bool nextFrame() + private bool advanceFrame() { - int newFrame = MathHelper.Clamp(currentFrameIndex + (currentDirection > 0 ? 1 : -1), 0, replayContent.Count - 1); + int newFrame = nextFrameIndex; //ensure we aren't at an extent. if (newFrame == currentFrameIndex) return false; @@ -158,7 +161,7 @@ namespace osu.Game.Modes if (hasFrames) { //if we changed frames, we want to execute once *exactly* on the frame's time. - if (currentDirection == time.CompareTo(NextFrame.Time) && nextFrame()) + if (currentDirection == time.CompareTo(NextFrame.Time) && advanceFrame()) return currentTime = CurrentFrame.Time; //if we didn't change frames, we need to ensure we are allowed to run frames in between, else return null.