1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 01:42:55 +08:00

Make FramedReplayInputHandler.CurrentTime non-null

This commit is contained in:
ekrctb 2021-04-16 12:31:32 +09:00
parent 936bde28a3
commit 84bc81a6de
5 changed files with 11 additions and 22 deletions

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Input.StateChanges;
using osu.Framework.Utils;
@ -30,9 +29,7 @@ namespace osu.Game.Rulesets.EmptyFreeform.Replays
if (frame == null)
return Vector2.Zero;
Debug.Assert(CurrentTime != null);
return Interpolation.ValueAt(CurrentTime.Value, frame.Position, NextFrame.Position, frame.Time, NextFrame.Time);
return Interpolation.ValueAt(CurrentTime, frame.Position, NextFrame.Position, frame.Time, NextFrame.Time);
}
}

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Diagnostics;
using osu.Framework.Input.StateChanges;
using osu.Framework.Utils;
using osu.Game.Replays;
@ -29,9 +28,7 @@ namespace osu.Game.Rulesets.Pippidon.Replays
if (frame == null)
return Vector2.Zero;
Debug.Assert(CurrentTime != null);
return NextFrame != null ? Interpolation.ValueAt(CurrentTime.Value, frame.Position, NextFrame.Position, frame.Time, NextFrame.Time) : frame.Position;
return NextFrame != null ? Interpolation.ValueAt(CurrentTime, frame.Position, NextFrame.Position, frame.Time, NextFrame.Time) : frame.Position;
}
}

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Input.StateChanges;
using osu.Framework.Utils;
@ -29,9 +28,7 @@ namespace osu.Game.Rulesets.Catch.Replays
if (frame == null)
return null;
Debug.Assert(CurrentTime != null);
return NextFrame != null ? Interpolation.ValueAt(CurrentTime.Value, frame.Position, NextFrame.Position, frame.Time, NextFrame.Time) : frame.Position;
return NextFrame != null ? Interpolation.ValueAt(CurrentTime, frame.Position, NextFrame.Position, frame.Time, NextFrame.Time) : frame.Position;
}
}

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Input.StateChanges;
using osu.Framework.Utils;
@ -30,9 +29,7 @@ namespace osu.Game.Rulesets.Osu.Replays
if (frame == null)
return null;
Debug.Assert(CurrentTime != null);
return NextFrame != null ? Interpolation.ValueAt(CurrentTime.Value, frame.Position, NextFrame.Position, frame.Time, NextFrame.Time) : frame.Position;
return NextFrame != null ? Interpolation.ValueAt(CurrentTime, frame.Position, NextFrame.Position, frame.Time, NextFrame.Time) : frame.Position;
}
}

View File

@ -1,6 +1,8 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable enable
using System;
using System.Collections.Generic;
using JetBrains.Annotations;
@ -32,7 +34,7 @@ namespace osu.Game.Rulesets.Replays
/// </summary>
/// <remarks>Returns null if the current time is strictly before the first frame.</remarks>
/// <exception cref="InvalidOperationException">The replay is empty.</exception>
public TFrame CurrentFrame
public TFrame? CurrentFrame
{
get
{
@ -49,7 +51,7 @@ namespace osu.Game.Rulesets.Replays
/// </summary>
/// <remarks>Returns null if the current frame is the last frame.</remarks>
/// <exception cref="InvalidOperationException">The replay is empty.</exception>
public TFrame NextFrame
public TFrame? NextFrame
{
get
{
@ -69,8 +71,7 @@ namespace osu.Game.Rulesets.Replays
// This input handler should be enabled only if there is at least one replay frame.
public override bool IsActive => HasFrames;
// Can make it non-null but that is a breaking change.
protected double? CurrentTime { get; private set; }
protected double CurrentTime { get; private set; }
protected virtual double AllowedImportantTimeSpan => sixty_frame_time * 1.2;
@ -101,7 +102,7 @@ namespace osu.Game.Rulesets.Replays
return false;
return IsImportant(CurrentFrame) && // a button is in a pressed state
Math.Abs(CurrentTime - NextFrame.Time ?? 0) <= AllowedImportantTimeSpan; // the next frame is within an allowable time span
Math.Abs(CurrentTime - NextFrame?.Time ?? 0) <= AllowedImportantTimeSpan; // the next frame is within an allowable time span
}
}
@ -151,7 +152,7 @@ namespace osu.Game.Rulesets.Replays
CurrentTime = Math.Clamp(time, frameStart, frameEnd);
// In an important section, a mid-frame time cannot be used and a null is returned instead.
return inImportantSection && frameStart < time && time < frameEnd ? null : CurrentTime;
return inImportantSection && frameStart < time && time < frameEnd ? null : (double?)CurrentTime;
}
private double getFrameTime(int index)