1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 21:47:25 +08:00

Merge pull request #1453 from smoogipoo/replay-rewinding

Implement the necessary interfaces to allow replay rewinding
This commit is contained in:
Dean Herbert 2017-11-11 10:34:44 +09:00 committed by GitHub
commit fd5113ac3c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
27 changed files with 253 additions and 171 deletions

@ -1 +1 @@
Subproject commit 5e26808ec77a8fd600cb1cdca3a4b2f62fd0c653 Subproject commit 1a563d7ce0834cede2ef587762f98fe580badf3c

@ -1 +1 @@
Subproject commit 1750ab8f6761ab35592fd46da71fbe0c141bfd93 Subproject commit a4418111f8ed2350a6fd46fe69258884f0757745

View File

@ -94,7 +94,7 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
protected override void UpdateState(ArmedState state) protected override void UpdateState(ArmedState state)
{ {
switch (State) switch (State.Value)
{ {
case ArmedState.Hit: case ArmedState.Hit:
AccentColour = Color4.Green; AccentColour = Color4.Green;

View File

@ -57,8 +57,10 @@ namespace osu.Game.Rulesets.Mania.UI
{ {
base.LoadComplete(); base.LoadComplete();
this.ScaleTo(2f, 600, Easing.OutQuint).FadeOut(500).Expire(); this.ScaleTo(2f, 600, Easing.OutQuint).FadeOut(500);
inner.FadeOut(250); inner.FadeOut(250);
Expire(true);
} }
} }
} }

View File

@ -14,6 +14,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
{ {
private const float width = 8; private const float width = 8;
public override bool RemoveWhenNotAlive => false;
public FollowPoint() public FollowPoint()
{ {
Origin = Anchor.Centre; Origin = Anchor.Centre;

View File

@ -52,9 +52,12 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Connections
} }
} }
public override bool RemoveCompletedTransforms => false;
private void update() private void update()
{ {
Clear(); Clear();
if (hitObjects == null) if (hitObjects == null)
return; return;

View File

@ -58,6 +58,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
}, },
ApproachCircle = new ApproachCircle ApproachCircle = new ApproachCircle
{ {
Alpha = 0,
Scale = new Vector2(4),
Colour = AccentColour, Colour = AccentColour,
} }
}; };
@ -82,21 +84,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
}); });
} }
protected override void UpdateInitialState()
{
base.UpdateInitialState();
// sane defaults
ring.Show();
circle.Show();
number.Show();
glow.Show();
ApproachCircle.Hide();
ApproachCircle.ScaleTo(new Vector2(4));
explode.Hide();
}
protected override void UpdatePreemptState() protected override void UpdatePreemptState()
{ {
base.UpdatePreemptState(); base.UpdatePreemptState();

View File

@ -23,12 +23,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
protected sealed override void UpdateState(ArmedState state) protected sealed override void UpdateState(ArmedState state)
{ {
FinishTransforms(); double transformTime = HitObject.StartTime - TIME_PREEMPT;
using (BeginAbsoluteSequence(HitObject.StartTime - TIME_PREEMPT, true)) base.ApplyTransformsAt(transformTime, true);
base.ClearTransformsAfter(transformTime, true);
using (BeginAbsoluteSequence(transformTime, true))
{ {
UpdateInitialState();
UpdatePreemptState(); UpdatePreemptState();
using (BeginDelayedSequence(TIME_PREEMPT + (Judgements.FirstOrDefault()?.TimeOffset ?? 0), true)) using (BeginDelayedSequence(TIME_PREEMPT + (Judgements.FirstOrDefault()?.TimeOffset ?? 0), true))
@ -36,11 +37,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
} }
} }
protected virtual void UpdateInitialState()
{
Hide();
}
protected virtual void UpdatePreemptState() protected virtual void UpdatePreemptState()
{ {
this.FadeIn(TIME_FADEIN); this.FadeIn(TIME_FADEIN);
@ -50,6 +46,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
} }
// Todo: At some point we need to move these to DrawableHitObject after ensuring that all other Rulesets apply
// transforms in the same way and don't rely on them not being cleared
public override void ClearTransformsAfter(double time, bool propagateChildren = false, string targetMember = null) { }
public override void ApplyTransformsAt(double time, bool propagateChildren = false) { }
private OsuInputManager osuActionInputManager; private OsuInputManager osuActionInputManager;
internal OsuInputManager OsuActionInputManager => osuActionInputManager ?? (osuActionInputManager = GetContainingInputManager() as OsuInputManager); internal OsuInputManager OsuActionInputManager => osuActionInputManager ?? (osuActionInputManager = GetContainingInputManager() as OsuInputManager);
} }

View File

@ -18,9 +18,8 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
public double FadeInTime; public double FadeInTime;
public double FadeOutTime; public double FadeOutTime;
public override bool RemoveWhenNotAlive => false; public DrawableRepeatPoint(RepeatPoint repeatPoint, DrawableSlider drawableSlider)
: base(repeatPoint)
public DrawableRepeatPoint(RepeatPoint repeatPoint, DrawableSlider drawableSlider) : base(repeatPoint)
{ {
this.repeatPoint = repeatPoint; this.repeatPoint = repeatPoint;
this.drawableSlider = drawableSlider; this.drawableSlider = drawableSlider;
@ -28,6 +27,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Blending = BlendingMode.Additive; Blending = BlendingMode.Additive;
Origin = Anchor.Centre; Origin = Anchor.Centre;
Scale = new Vector2(0.5f);
Children = new Drawable[] Children = new Drawable[]
{ {
@ -51,12 +51,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
{ {
var animIn = Math.Min(150, repeatPoint.StartTime - FadeInTime); var animIn = Math.Min(150, repeatPoint.StartTime - FadeInTime);
this.Animate( this.FadeIn(animIn).ScaleTo(1.2f, animIn)
d => d.FadeIn(animIn), .Then()
d => d.ScaleTo(0.5f).ScaleTo(1.2f, animIn) .ScaleTo(1, 150, Easing.Out);
).Then(
d => d.ScaleTo(1, 150, Easing.Out)
);
} }
protected override void UpdateCurrentState(ArmedState state) protected override void UpdateCurrentState(ArmedState state)

View File

@ -43,7 +43,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
ball = new SliderBall(s) ball = new SliderBall(s)
{ {
Scale = new Vector2(s.Scale), Scale = new Vector2(s.Scale),
AccentColour = AccentColour AccentColour = AccentColour,
AlwaysPresent = true,
Alpha = 0
}, },
initialCircle = new DrawableHitCircle(new HitCircle initialCircle = new DrawableHitCircle(new HitCircle
{ {
@ -148,16 +150,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
} }
} }
protected override void UpdateInitialState()
{
base.UpdateInitialState();
body.Alpha = 1;
//we need to be present to handle input events. note that we still don't get enough events (we don't get a position if the mouse hasn't moved since the slider appeared).
ball.AlwaysPresent = true;
ball.Alpha = 0;
}
protected override void UpdateCurrentState(ArmedState state) protected override void UpdateCurrentState(ArmedState state)
{ {
ball.FadeIn(); ball.FadeIn();

View File

@ -20,8 +20,6 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
public bool Tracking; public bool Tracking;
public override bool RemoveWhenNotAlive => false;
public override bool DisplayJudgement => false; public override bool DisplayJudgement => false;
public DrawableSliderTick(SliderTick sliderTick) : base(sliderTick) public DrawableSliderTick(SliderTick sliderTick) : base(sliderTick)

View File

@ -101,14 +101,21 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
// If the current time is between the start and end of the slider, we should track mouse input regardless of the cursor position. // If the current time is between the start and end of the slider, we should track mouse input regardless of the cursor position.
public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => canCurrentlyTrack || base.ReceiveMouseInputAt(screenSpacePos); public override bool ReceiveMouseInputAt(Vector2 screenSpacePos) => canCurrentlyTrack || base.ReceiveMouseInputAt(screenSpacePos);
public override void ClearTransforms(bool propagateChildren = false, string targetMember = null)
{
// Consider the case of rewinding - children's transforms are handled internally, so propagating down
// any further will cause weirdness with the Tracking bool below. Let's not propagate further at this point.
base.ClearTransforms(false, targetMember);
}
private bool tracking; private bool tracking;
public bool Tracking public bool Tracking
{ {
get { return tracking; } get { return tracking; }
private set private set
{ {
if (value == tracking) return; if (value == tracking)
return;
tracking = value; tracking = value;
follow.ScaleTo(tracking ? 2.8f : 1, 300, Easing.OutQuint); follow.ScaleTo(tracking ? 2.8f : 1, 300, Easing.OutQuint);
@ -123,8 +130,10 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
base.Update(); base.Update();
// Make sure to use the base version of ReceiveMouseInputAt so that we correctly check the position. // Make sure to use the base version of ReceiveMouseInputAt so that we correctly check the position.
if (Time.Current < slider.EndTime) Tracking = canCurrentlyTrack
Tracking = canCurrentlyTrack && lastState != null && base.ReceiveMouseInputAt(lastState.Mouse.NativeState.Position) && ((Parent as DrawableSlider)?.OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false); && lastState != null
&& base.ReceiveMouseInputAt(lastState.Mouse.NativeState.Position)
&& ((Parent as DrawableSlider)?.OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false);
} }
public void UpdateProgress(double progress, int repeat) public void UpdateProgress(double progress, int repeat)

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
@ -61,6 +62,10 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables.Pieces
public void SetRotation(float currentRotation) public void SetRotation(float currentRotation)
{ {
// If we've gone back in time, it's fine to work with a fresh set of records for now
if (records.Count > 0 && Time.Current < records.Last().Time)
records.Clear();
if (records.Count > 0) if (records.Count > 0)
{ {
var record = records.Peek(); var record = records.Peek();

View File

@ -111,7 +111,7 @@ namespace osu.Game.Rulesets.Osu.Tests
h.Depth = depth++; h.Depth = depth++;
if (auto) if (auto)
h.State = ArmedState.Hit; h.State.Value = ArmedState.Hit;
playfieldContainer.Add(h); playfieldContainer.Add(h);
var proxyable = h as IDrawableHitObjectWithProxiedApproach; var proxyable = h as IDrawableHitObjectWithProxiedApproach;

View File

@ -1,8 +1,6 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Game.Rulesets.Objects.Drawables;
namespace osu.Game.Rulesets.Taiko.Judgements namespace osu.Game.Rulesets.Taiko.Judgements
{ {
public class TaikoStrongHitJudgement : TaikoJudgement public class TaikoStrongHitJudgement : TaikoJudgement
@ -11,9 +9,7 @@ namespace osu.Game.Rulesets.Taiko.Judgements
public TaikoStrongHitJudgement() public TaikoStrongHitJudgement()
{ {
base.Result = HitResult.Perfect; Final = true;
} }
public new HitResult Result => base.Result;
} }
} }

View File

@ -17,6 +17,11 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
/// </summary> /// </summary>
protected abstract TaikoAction[] HitActions { get; } protected abstract TaikoAction[] HitActions { get; }
/// <summary>
/// Whether a second hit is allowed to be processed. This occurs once this hit object has been hit successfully.
/// </summary>
protected bool SecondHitAllowed { get; private set; }
/// <summary> /// <summary>
/// Whether the last key pressed is a valid hit key. /// Whether the last key pressed is a valid hit key.
/// </summary> /// </summary>
@ -45,7 +50,15 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
if (!validKeyPressed) if (!validKeyPressed)
AddJudgement(new TaikoJudgement { Result = HitResult.Miss }); AddJudgement(new TaikoJudgement { Result = HitResult.Miss });
else if (hitOffset < HitObject.HitWindowGood) else if (hitOffset < HitObject.HitWindowGood)
AddJudgement(new TaikoJudgement { Result = hitOffset < HitObject.HitWindowGreat ? HitResult.Great : HitResult.Good }); {
AddJudgement(new TaikoJudgement
{
Result = hitOffset < HitObject.HitWindowGreat ? HitResult.Great : HitResult.Good,
Final = !HitObject.IsStrong
});
SecondHitAllowed = true;
}
else else
AddJudgement(new TaikoJudgement { Result = HitResult.Miss }); AddJudgement(new TaikoJudgement { Result = HitResult.Miss });
} }
@ -72,7 +85,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
var offset = !AllJudged ? 0 : Time.Current - HitObject.StartTime; var offset = !AllJudged ? 0 : Time.Current - HitObject.StartTime;
using (BeginDelayedSequence(HitObject.StartTime - Time.Current + offset, true)) using (BeginDelayedSequence(HitObject.StartTime - Time.Current + offset, true))
{ {
switch (State) switch (State.Value)
{ {
case ArmedState.Idle: case ArmedState.Idle:
this.Delay(HitObject.HitWindowMiss).Expire(); this.Delay(HitObject.HitWindowMiss).Expire();

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Judgements; using osu.Game.Rulesets.Taiko.Judgements;
namespace osu.Game.Rulesets.Taiko.Objects.Drawables namespace osu.Game.Rulesets.Taiko.Objects.Drawables
@ -24,27 +25,25 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
{ {
} }
private bool processedSecondHit;
public override bool AllJudged => processedSecondHit && base.AllJudged;
protected override void CheckForJudgements(bool userTriggered, double timeOffset) protected override void CheckForJudgements(bool userTriggered, double timeOffset)
{ {
if (!base.AllJudged) if (!SecondHitAllowed)
{ {
base.CheckForJudgements(userTriggered, timeOffset); base.CheckForJudgements(userTriggered, timeOffset);
return; return;
} }
if (!userTriggered) if (!userTriggered)
{
if (timeOffset > second_hit_window)
AddJudgement(new TaikoStrongHitJudgement { Result = HitResult.Miss });
return; return;
}
// If we get here, we're assured that the key pressed is the correct secondary key // If we get here, we're assured that the key pressed is the correct secondary key
if (Math.Abs(firstHitTime - Time.Current) < second_hit_window) if (Math.Abs(firstHitTime - Time.Current) < second_hit_window)
{ AddJudgement(new TaikoStrongHitJudgement { Result = HitResult.Great });
AddJudgement(new TaikoStrongHitJudgement());
processedSecondHit = true;
}
} }
public override bool OnReleased(TaikoAction action) public override bool OnReleased(TaikoAction action)
@ -56,8 +55,11 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
public override bool OnPressed(TaikoAction action) public override bool OnPressed(TaikoAction action)
{ {
if (AllJudged)
return false;
// Check if we've handled the first key // Check if we've handled the first key
if (!base.AllJudged) if (!SecondHitAllowed)
{ {
// First key hasn't been handled yet, attempt to handle it // First key hasn't been handled yet, attempt to handle it
bool handled = base.OnPressed(action); bool handled = base.OnPressed(action);
@ -72,10 +74,6 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
return handled; return handled;
} }
// If we've already hit the second key, don't handle this object any further
if (processedSecondHit)
return false;
// Don't handle represses of the first key // Don't handle represses of the first key
if (firstHitAction == action) if (firstHitAction == action)
return false; return false;

View File

@ -244,7 +244,12 @@ namespace osu.Game.Rulesets.Taiko.UI
if (judgedObject.X >= -0.05f && judgedObject is DrawableHit) if (judgedObject.X >= -0.05f && judgedObject is DrawableHit)
{ {
// If we're far enough away from the left stage, we should bring outselves in front of it // If we're far enough away from the left stage, we should bring outselves in front of it
topLevelHitContainer.Add(judgedObject.CreateProxy()); // Todo: The following try-catch is temporary for replay rewinding support
try
{
topLevelHitContainer.Add(judgedObject.CreateProxy());
}
catch { }
} }
hitExplosionContainer.Add(new HitExplosion(judgedObject, isRim)); hitExplosionContainer.Add(new HitExplosion(judgedObject, isRim));

View File

@ -6,6 +6,7 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.MathUtils; using osu.Framework.MathUtils;
using OpenTK; using OpenTK;
using OpenTK.Graphics; using OpenTK.Graphics;
using osu.Framework.Graphics.Transforms;
namespace osu.Game.Graphics.Sprites namespace osu.Game.Graphics.Sprites
{ {
@ -40,4 +41,23 @@ namespace osu.Game.Graphics.Sprites
return base.CreateFallbackCharacterDrawable(); return base.CreateFallbackCharacterDrawable();
} }
} }
public static class OsuSpriteTextTransformExtensions
{
/// <summary>
/// Sets <see cref="OsuSpriteText.Text"/> to a new value after a duration.
/// </summary>
/// <returns>A <see cref="TransformSequence{T}"/> to which further transforms can be added.</returns>
public static TransformSequence<T> TransformTextTo<T>(this T spriteText, string newText, double duration = 0, Easing easing = Easing.None)
where T : OsuSpriteText
=> spriteText.TransformTo(nameof(OsuSpriteText.Text), newText, duration, easing);
/// <summary>
/// Sets <see cref="OsuSpriteText.Text"/> to a new value after a duration.
/// </summary>
/// <returns>A <see cref="TransformSequence{T}"/> to which further transforms can be added.</returns>
public static TransformSequence<T> TransformTextTo<T>(this TransformSequence<T> t, string newText, double duration = 0, Easing easing = Easing.None)
where T : OsuSpriteText
=> t.Append(o => o.TransformTextTo(newText, duration, easing));
}
} }

View File

@ -83,7 +83,7 @@ namespace osu.Game.Rulesets.Judgements
break; break;
} }
Expire(); Expire(true);
} }
} }
} }

View File

@ -17,8 +17,26 @@ namespace osu.Game.Rulesets.Judgements
/// </summary> /// </summary>
public virtual HitResult MaxResult => HitResult.Perfect; public virtual HitResult MaxResult => HitResult.Perfect;
/// <summary>
/// The combo prior to this judgement occurring.
/// </summary>
internal int ComboAtJudgement;
/// <summary>
/// The highest combo achieved prior to this judgement occurring.
/// </summary>
internal int HighestComboAtJudgement;
/// <summary>
/// Whether a successful hit occurred.
/// </summary>
public bool IsHit => Result > HitResult.Miss; public bool IsHit => Result > HitResult.Miss;
/// <summary>
/// Whether this judgement is the final judgement for the hit object.
/// </summary>
public bool Final = true;
/// <summary> /// <summary>
/// The offset from a perfect hit at which this judgement occurred. /// The offset from a perfect hit at which this judgement occurred.
/// Populated when added via <see cref="DrawableHitObject{TObject}.AddJudgement"/>. /// Populated when added via <see cref="DrawableHitObject{TObject}.AddJudgement"/>.

View File

@ -13,6 +13,7 @@ using OpenTK.Graphics;
using osu.Game.Audio; using osu.Game.Audio;
using System.Linq; using System.Linq;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Framework.Configuration;
namespace osu.Game.Rulesets.Objects.Drawables namespace osu.Game.Rulesets.Objects.Drawables
{ {
@ -30,6 +31,9 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </summary> /// </summary>
public virtual bool DisplayJudgement => true; public virtual bool DisplayJudgement => true;
public override bool RemoveCompletedTransforms => false;
public override bool RemoveWhenNotAlive => false;
protected DrawableHitObject(HitObject hitObject) protected DrawableHitObject(HitObject hitObject)
{ {
HitObject = hitObject; HitObject = hitObject;
@ -40,6 +44,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
where TObject : HitObject where TObject : HitObject
{ {
public event Action<DrawableHitObject, Judgement> OnJudgement; public event Action<DrawableHitObject, Judgement> OnJudgement;
public event Action<DrawableHitObject, Judgement> OnJudgementRemoved;
public new readonly TObject HitObject; public new readonly TObject HitObject;
@ -56,31 +61,42 @@ namespace osu.Game.Rulesets.Objects.Drawables
protected List<SampleChannel> Samples = new List<SampleChannel>(); protected List<SampleChannel> Samples = new List<SampleChannel>();
public readonly Bindable<ArmedState> State = new Bindable<ArmedState>();
protected DrawableHitObject(TObject hitObject) protected DrawableHitObject(TObject hitObject)
: base(hitObject) : base(hitObject)
{ {
HitObject = hitObject; HitObject = hitObject;
} }
private ArmedState state; [BackgroundDependencyLoader]
public ArmedState State private void load(AudioManager audio)
{ {
get { return state; } foreach (SampleInfo sample in HitObject.Samples)
set
{ {
if (state == value) SampleChannel channel = audio.Sample.Get($@"Gameplay/{sample.Bank}-{sample.Name}");
return;
state = value;
if (!IsLoaded) if (channel == null)
return; continue;
channel.Volume.Value = sample.Volume;
Samples.Add(channel);
}
}
protected override void LoadComplete()
{
base.LoadComplete();
State.ValueChanged += state =>
{
UpdateState(state); UpdateState(state);
if (State == ArmedState.Hit) if (State == ArmedState.Hit)
PlaySamples(); PlaySamples();
} };
State.TriggerChange();
} }
protected void PlaySamples() protected void PlaySamples()
@ -88,21 +104,13 @@ namespace osu.Game.Rulesets.Objects.Drawables
Samples.ForEach(s => s?.Play()); Samples.ForEach(s => s?.Play());
} }
protected override void LoadComplete()
{
base.LoadComplete();
//force application of the state that was set before we loaded.
UpdateState(State);
}
private bool hasJudgementResult;
private bool judgementOccurred; private bool judgementOccurred;
private bool judgementFinalized => judgements.LastOrDefault()?.Final == true;
/// <summary> /// <summary>
/// Whether this <see cref="DrawableHitObject"/> and all of its nested <see cref="DrawableHitObject"/>s have been judged. /// Whether this <see cref="DrawableHitObject"/> and all of its nested <see cref="DrawableHitObject"/>s have been judged.
/// </summary> /// </summary>
public virtual bool AllJudged => (!ProvidesJudgement || hasJudgementResult) && (NestedHitObjects?.All(h => h.AllJudged) ?? true); public bool AllJudged => (!ProvidesJudgement || judgementFinalized) && (NestedHitObjects?.All(h => h.AllJudged) ?? true);
/// <summary> /// <summary>
/// Notifies that a new judgement has occurred for this <see cref="DrawableHitObject"/>. /// Notifies that a new judgement has occurred for this <see cref="DrawableHitObject"/>.
@ -110,7 +118,6 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// <param name="judgement">The <see cref="Judgement"/>.</param> /// <param name="judgement">The <see cref="Judgement"/>.</param>
protected void AddJudgement(Judgement judgement) protected void AddJudgement(Judgement judgement)
{ {
hasJudgementResult = judgement.Result >= HitResult.Miss;
judgementOccurred = true; judgementOccurred = true;
// Ensure that the judgement is given a valid time offset, because this may not get set by the caller // Ensure that the judgement is given a valid time offset, because this may not get set by the caller
@ -124,10 +131,10 @@ namespace osu.Game.Rulesets.Objects.Drawables
case HitResult.None: case HitResult.None:
break; break;
case HitResult.Miss: case HitResult.Miss:
State = ArmedState.Miss; State.Value = ArmedState.Miss;
break; break;
default: default:
State = ArmedState.Hit; State.Value = ArmedState.Hit;
break; break;
} }
@ -152,7 +159,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
judgementOccurred |= d.UpdateJudgement(userTriggered); judgementOccurred |= d.UpdateJudgement(userTriggered);
} }
if (!ProvidesJudgement || hasJudgementResult || judgementOccurred) if (!ProvidesJudgement || judgementFinalized || judgementOccurred)
return judgementOccurred; return judgementOccurred;
var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime; var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime;
@ -170,6 +177,25 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// implies that this check occurred after the end time of <see cref="HitObject"/>. </param> /// implies that this check occurred after the end time of <see cref="HitObject"/>. </param>
protected virtual void CheckForJudgements(bool userTriggered, double timeOffset) { } protected virtual void CheckForJudgements(bool userTriggered, double timeOffset) { }
protected override void Update()
{
base.Update();
var endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime;
while (judgements.Count > 0)
{
var lastJudgement = judgements[judgements.Count - 1];
if (lastJudgement.TimeOffset + endTime <= Time.Current)
break;
judgements.RemoveAt(judgements.Count - 1);
State.Value = ArmedState.Idle;
OnJudgementRemoved?.Invoke(this, lastJudgement);
}
}
protected override void UpdateAfterChildren() protected override void UpdateAfterChildren()
{ {
base.UpdateAfterChildren(); base.UpdateAfterChildren();
@ -177,21 +203,6 @@ namespace osu.Game.Rulesets.Objects.Drawables
UpdateJudgement(false); UpdateJudgement(false);
} }
[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
foreach (SampleInfo sample in HitObject.Samples)
{
SampleChannel channel = audio.Sample.Get($@"Gameplay/{sample.Bank}-{sample.Name}");
if (channel == null)
continue;
channel.Volume.Value = sample.Volume;
Samples.Add(channel);
}
}
private List<DrawableHitObject<TObject>> nestedHitObjects; private List<DrawableHitObject<TObject>> nestedHitObjects;
protected IEnumerable<DrawableHitObject<TObject>> NestedHitObjects => nestedHitObjects; protected IEnumerable<DrawableHitObject<TObject>> NestedHitObjects => nestedHitObjects;

View File

@ -104,7 +104,13 @@ namespace osu.Game.Rulesets.Replays
{ {
//if we changed frames, we want to execute once *exactly* on the frame's time. //if we changed frames, we want to execute once *exactly* on the frame's time.
if (currentDirection == time.CompareTo(NextFrame.Time) && advanceFrame()) if (currentDirection == time.CompareTo(NextFrame.Time) && advanceFrame())
{
// If going backwards, we need to execute once _before_ the frame time to reverse any judgements
// that would occur as a result of this frame in forward playback
if (currentDirection == -1)
return currentTime = CurrentFrame.Time - 1;
return currentTime = CurrentFrame.Time; 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. //if we didn't change frames, we need to ensure we are allowed to run frames in between, else return null.
if (inImportantSection) if (inImportantSection)

View File

@ -174,6 +174,7 @@ namespace osu.Game.Rulesets.Scoring
private double maxBaseScore; private double maxBaseScore;
private double rollingMaxBaseScore; private double rollingMaxBaseScore;
private double baseScore; private double baseScore;
private double bonusScore;
protected ScoreProcessor() protected ScoreProcessor()
{ {
@ -184,6 +185,7 @@ namespace osu.Game.Rulesets.Scoring
Debug.Assert(base_portion + combo_portion == 1.0); Debug.Assert(base_portion + combo_portion == 1.0);
rulesetContainer.OnJudgement += AddJudgement; rulesetContainer.OnJudgement += AddJudgement;
rulesetContainer.OnJudgementRemoved += RemoveJudgement;
SimulateAutoplay(rulesetContainer.Beatmap); SimulateAutoplay(rulesetContainer.Beatmap);
Reset(true); Reset(true);
@ -212,14 +214,26 @@ namespace osu.Game.Rulesets.Scoring
protected void AddJudgement(Judgement judgement) protected void AddJudgement(Judgement judgement)
{ {
OnNewJudgement(judgement); OnNewJudgement(judgement);
NotifyNewJudgement(judgement); updateScore();
NotifyNewJudgement(judgement);
UpdateFailed(); UpdateFailed();
} }
protected void RemoveJudgement(Judgement judgement)
{
OnJudgementRemoved(judgement);
updateScore();
}
/// <summary>
/// Applies a judgement.
/// </summary>
/// <param name="judgement">The judgement to apply/</param>
protected virtual void OnNewJudgement(Judgement judgement) protected virtual void OnNewJudgement(Judgement judgement)
{ {
double bonusScore = 0; judgement.ComboAtJudgement = Combo;
judgement.HighestComboAtJudgement = HighestCombo;
if (judgement.AffectsCombo) if (judgement.AffectsCombo)
{ {
@ -242,7 +256,30 @@ namespace osu.Game.Rulesets.Scoring
} }
else if (judgement.IsHit) else if (judgement.IsHit)
bonusScore += judgement.NumericResult; bonusScore += judgement.NumericResult;
}
/// <summary>
/// Removes a judgement. This should reverse everything in <see cref="OnNewJudgement(Judgement)"/>.
/// </summary>
/// <param name="judgement">The judgement to remove.</param>
protected virtual void OnJudgementRemoved(Judgement judgement)
{
Combo.Value = judgement.ComboAtJudgement;
HighestCombo.Value = judgement.HighestComboAtJudgement;
if (judgement.AffectsCombo)
{
baseScore -= judgement.NumericResult;
rollingMaxBaseScore -= judgement.MaxNumericResult;
Hits--;
}
else if (judgement.IsHit)
bonusScore -= judgement.NumericResult;
}
private void updateScore()
{
if (rollingMaxBaseScore != 0) if (rollingMaxBaseScore != 0)
Accuracy.Value = baseScore / rollingMaxBaseScore; Accuracy.Value = baseScore / rollingMaxBaseScore;
@ -271,6 +308,7 @@ namespace osu.Game.Rulesets.Scoring
Hits = 0; Hits = 0;
baseScore = 0; baseScore = 0;
rollingMaxBaseScore = 0; rollingMaxBaseScore = 0;
bonusScore = 0;
} }
} }

View File

@ -104,6 +104,7 @@ namespace osu.Game.Rulesets.UI
where TObject : HitObject where TObject : HitObject
{ {
public event Action<Judgement> OnJudgement; public event Action<Judgement> OnJudgement;
public event Action<Judgement> OnJudgementRemoved;
/// <summary> /// <summary>
/// The Beatmap /// The Beatmap
@ -241,6 +242,8 @@ namespace osu.Game.Rulesets.UI
OnJudgement?.Invoke(j); OnJudgement?.Invoke(j);
}; };
drawableObject.OnJudgementRemoved += (d, j) => { OnJudgementRemoved?.Invoke(j); };
Playfield.Add(drawableObject); Playfield.Add(drawableObject);
} }

View File

@ -7,6 +7,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using System.Collections.Generic; using System.Collections.Generic;
using osu.Framework.Graphics.UserInterface;
namespace osu.Game.Screens.Play.BreaksOverlay namespace osu.Game.Screens.Play.BreaksOverlay
{ {
@ -30,6 +31,8 @@ namespace osu.Game.Screens.Play.BreaksOverlay
} }
} }
public override bool RemoveCompletedTransforms => false;
private readonly bool letterboxing; private readonly bool letterboxing;
private readonly LetterboxOverlay letterboxOverlay; private readonly LetterboxOverlay letterboxOverlay;
private readonly Container remainingTimeAdjustmentBox; private readonly Container remainingTimeAdjustmentBox;
@ -101,38 +104,41 @@ namespace osu.Game.Screens.Play.BreaksOverlay
if (!b.HasEffect) if (!b.HasEffect)
continue; continue;
using (BeginAbsoluteSequence(b.StartTime, true))
{
remainingTimeAdjustmentBox
.ResizeWidthTo(remaining_time_container_max_size, fade_duration, Easing.OutQuint)
.Delay(b.Duration - fade_duration)
.ResizeWidthTo(0);
remainingTimeBox
.ResizeWidthTo(0, b.Duration - fade_duration)
.Then()
.ResizeWidthTo(1);
remainingTimeCounter.CountTo(b.Duration).CountTo(0, b.Duration);
}
using (BeginAbsoluteSequence(b.StartTime)) using (BeginAbsoluteSequence(b.StartTime))
{ {
Schedule(() => onBreakIn(b)); Schedule(showBreak);
using (BeginDelayedSequence(b.Duration - fade_duration)) using (BeginDelayedSequence(b.Duration - fade_duration))
Schedule(onBreakOut); Schedule(hideBreak);
} }
} }
} }
private void onBreakIn(BreakPeriod b) private void showBreak()
{ {
if (letterboxing) if (letterboxing)
letterboxOverlay.Show(); letterboxOverlay.Show();
remainingTimeAdjustmentBox
.ResizeWidthTo(remaining_time_container_max_size, fade_duration, Easing.OutQuint)
.Delay(b.Duration - fade_duration)
.ResizeWidthTo(0);
remainingTimeBox
.ResizeWidthTo(0, b.Duration - fade_duration)
.Then()
.ResizeWidthTo(1);
remainingTimeCounter.StartCounting(b.EndTime);
remainingTimeCounter.Show(); remainingTimeCounter.Show();
info.Show(); info.Show();
arrowsOverlay.Show(); arrowsOverlay.Show();
} }
private void onBreakOut() private void hideBreak()
{ {
if (letterboxing) if (letterboxing)
letterboxOverlay.Hide(); letterboxOverlay.Hide();

View File

@ -1,65 +1,37 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using System; using System;
using osu.Game.Beatmaps.Timing; using osu.Game.Beatmaps.Timing;
using osu.Framework.Graphics.UserInterface;
namespace osu.Game.Screens.Play.BreaksOverlay namespace osu.Game.Screens.Play.BreaksOverlay
{ {
public class RemainingTimeCounter : VisibilityContainer public class RemainingTimeCounter : Counter
{ {
private const double fade_duration = BreakPeriod.MIN_BREAK_DURATION / 2; private const double fade_duration = BreakPeriod.MIN_BREAK_DURATION / 2;
private readonly OsuSpriteText counter; private readonly OsuSpriteText counter;
private int? previousSecond;
private double endTime;
private bool isCounting;
public RemainingTimeCounter() public RemainingTimeCounter()
{ {
AutoSizeAxes = Axes.Both; AutoSizeAxes = Axes.Both;
Child = counter = new OsuSpriteText InternalChild = counter = new OsuSpriteText
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
TextSize = 33, TextSize = 33,
Font = "Venera", Font = "Venera",
}; };
Alpha = 0;
} }
public void StartCounting(double endTime) protected override void OnCountChanged(double count) => counter.Text = ((int)Math.Ceiling(count / 1000)).ToString();
{
this.endTime = endTime;
isCounting = true;
}
protected override void Update() public override void Show() => this.FadeIn(fade_duration);
{ public override void Hide() => this.FadeOut(fade_duration);
base.Update();
if (isCounting)
{
var currentTime = Clock.CurrentTime;
if (currentTime < endTime)
{
int currentSecond = (int)Math.Ceiling((endTime - Clock.CurrentTime) / 1000.0);
if (currentSecond != previousSecond)
{
counter.Text = currentSecond.ToString();
previousSecond = currentSecond;
}
}
else isCounting = false;
}
}
protected override void PopIn() => this.FadeIn(fade_duration);
protected override void PopOut() => this.FadeOut(fade_duration);
} }
} }