mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 09:23:06 +08:00
Throw when getting a frame of an empty replay
This commit is contained in:
parent
4853ac802c
commit
d6d8ea5b6b
@ -204,27 +204,27 @@ namespace osu.Game.Tests.Visual.Gameplay
|
||||
return;
|
||||
}
|
||||
|
||||
if (replayHandler.NextFrame != null)
|
||||
{
|
||||
var lastFrame = replay.Frames.LastOrDefault();
|
||||
if (!replayHandler.HasFrames)
|
||||
return;
|
||||
|
||||
// this isn't perfect as we basically can't be aware of the rate-of-send here (the streamer is not sending data when not being moved).
|
||||
// in gameplay playback, the case where NextFrame is null would pause gameplay and handle this correctly; it's strictly a test limitation / best effort implementation.
|
||||
if (lastFrame != null)
|
||||
latency = Math.Max(latency, Time.Current - lastFrame.Time);
|
||||
var lastFrame = replay.Frames.LastOrDefault();
|
||||
|
||||
latencyDisplay.Text = $"latency: {latency:N1}";
|
||||
// this isn't perfect as we basically can't be aware of the rate-of-send here (the streamer is not sending data when not being moved).
|
||||
// in gameplay playback, the case where NextFrame is null would pause gameplay and handle this correctly; it's strictly a test limitation / best effort implementation.
|
||||
if (lastFrame != null)
|
||||
latency = Math.Max(latency, Time.Current - lastFrame.Time);
|
||||
|
||||
double proposedTime = Time.Current - latency + Time.Elapsed;
|
||||
latencyDisplay.Text = $"latency: {latency:N1}";
|
||||
|
||||
// this will either advance by one or zero frames.
|
||||
double? time = replayHandler.SetFrameFromTime(proposedTime);
|
||||
double proposedTime = Time.Current - latency + Time.Elapsed;
|
||||
|
||||
if (time == null)
|
||||
return;
|
||||
// this will either advance by one or zero frames.
|
||||
double? time = replayHandler.SetFrameFromTime(proposedTime);
|
||||
|
||||
manualClock.CurrentTime = time.Value;
|
||||
}
|
||||
if (time == null)
|
||||
return;
|
||||
|
||||
manualClock.CurrentTime = time.Value;
|
||||
}
|
||||
|
||||
[TearDownSteps]
|
||||
|
@ -32,8 +32,6 @@ namespace osu.Game.Input.Handlers
|
||||
|
||||
public override bool Initialize(GameHost host) => true;
|
||||
|
||||
public override bool IsActive => true;
|
||||
|
||||
public class ReplayState<T> : IInput
|
||||
where T : struct
|
||||
{
|
||||
|
@ -17,6 +17,8 @@ namespace osu.Game.Rulesets.Replays
|
||||
public abstract class FramedReplayInputHandler<TFrame> : ReplayInputHandler
|
||||
where TFrame : ReplayFrame
|
||||
{
|
||||
public override bool IsActive => HasFrames;
|
||||
|
||||
private readonly Replay replay;
|
||||
|
||||
protected List<ReplayFrame> Frames => replay.Frames;
|
||||
@ -25,7 +27,10 @@ namespace osu.Game.Rulesets.Replays
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!HasFrames || !currentFrameIndex.HasValue)
|
||||
if (!HasFrames)
|
||||
throw new InvalidOperationException($"Cannot get {nameof(CurrentFrame)} of the empty replay");
|
||||
|
||||
if (!currentFrameIndex.HasValue)
|
||||
return null;
|
||||
|
||||
return (TFrame)Frames[currentFrameIndex.Value];
|
||||
@ -37,7 +42,7 @@ namespace osu.Game.Rulesets.Replays
|
||||
get
|
||||
{
|
||||
if (!HasFrames)
|
||||
return null;
|
||||
throw new InvalidOperationException($"Cannot get {nameof(NextFrame)} of the empty replay");
|
||||
|
||||
if (!currentFrameIndex.HasValue)
|
||||
return currentDirection > 0 ? (TFrame)Frames[0] : null;
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -10,6 +11,7 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Input.StateChanges;
|
||||
using osu.Framework.Input.StateChanges.Events;
|
||||
using osu.Framework.Input.States;
|
||||
using osu.Game.Configuration;
|
||||
@ -100,6 +102,14 @@ namespace osu.Game.Rulesets.UI
|
||||
|
||||
#endregion
|
||||
|
||||
protected override List<IInput> GetPendingInputs()
|
||||
{
|
||||
if (replayInputHandler != null && !replayInputHandler.IsActive)
|
||||
return new List<IInput>();
|
||||
|
||||
return base.GetPendingInputs();
|
||||
}
|
||||
|
||||
#region Setting application (disables etc.)
|
||||
|
||||
private Bindable<bool> mouseDisabled;
|
||||
|
Loading…
Reference in New Issue
Block a user