diff --git a/osu-framework b/osu-framework index 3931f8e358..415884e7e1 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 3931f8e358365b1853a76e1d141fcf4c929a2143 +Subproject commit 415884e7e19f9062a4fac457a7ce19b566fa2ee7 diff --git a/osu.Desktop.VisualTests/Tests/TestCaseTaikoPlayfield.cs b/osu.Desktop.VisualTests/Tests/TestCaseTaikoPlayfield.cs index 3343918363..49c2ee3997 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseTaikoPlayfield.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseTaikoPlayfield.cs @@ -58,7 +58,6 @@ namespace osu.Desktop.VisualTests.Tests Result = HitResult.Hit, TaikoResult = hitResult, TimeOffset = 0, - ComboAtHit = 1, SecondHit = RNG.Next(10) == 0 } }); @@ -71,8 +70,7 @@ namespace osu.Desktop.VisualTests.Tests Judgement = new TaikoJudgement { Result = HitResult.Miss, - TimeOffset = 0, - ComboAtHit = 0 + TimeOffset = 0 } }); } diff --git a/osu.Game.Modes.Catch/Scoring/CatchScoreProcessor.cs b/osu.Game.Modes.Catch/Scoring/CatchScoreProcessor.cs index 766a492bf4..1b9bedf7fb 100644 --- a/osu.Game.Modes.Catch/Scoring/CatchScoreProcessor.cs +++ b/osu.Game.Modes.Catch/Scoring/CatchScoreProcessor.cs @@ -19,7 +19,7 @@ namespace osu.Game.Modes.Catch.Scoring { } - protected override void OnNewJugement(CatchJudgement judgement) + protected override void OnNewJudgement(CatchJudgement judgement) { } } diff --git a/osu.Game.Modes.Mania/Scoring/ManiaScoreProcessor.cs b/osu.Game.Modes.Mania/Scoring/ManiaScoreProcessor.cs index c6b223af6d..0f87030e25 100644 --- a/osu.Game.Modes.Mania/Scoring/ManiaScoreProcessor.cs +++ b/osu.Game.Modes.Mania/Scoring/ManiaScoreProcessor.cs @@ -19,7 +19,7 @@ namespace osu.Game.Modes.Mania.Scoring { } - protected override void OnNewJugement(ManiaJudgement judgement) + protected override void OnNewJudgement(ManiaJudgement judgement) { } } diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs index dcc25a997a..68c5ec0a45 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs @@ -38,7 +38,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables Colour = AccentColour, Hit = () => { - if (Judgement.Result.HasValue) return false; + if (Judgement.Result != HitResult.None) return false; Judgement.PositionOffset = Vector2.Zero; //todo: set to correct value UpdateJudgement(true); diff --git a/osu.Game.Modes.Osu/OsuAutoReplay.cs b/osu.Game.Modes.Osu/OsuAutoReplay.cs index 86985c834a..ae85bd72d8 100644 --- a/osu.Game.Modes.Osu/OsuAutoReplay.cs +++ b/osu.Game.Modes.Osu/OsuAutoReplay.cs @@ -11,10 +11,11 @@ using System.Collections.Generic; using System.Diagnostics; using osu.Framework.Graphics; using osu.Game.Modes.Objects.Types; +using osu.Game.Modes.Replays; namespace osu.Game.Modes.Osu { - public class OsuAutoReplay : LegacyReplay + public class OsuAutoReplay : Replay { private static readonly Vector2 spinner_centre = new Vector2(256, 192); @@ -29,17 +30,20 @@ namespace osu.Game.Modes.Osu createAutoReplay(); } - private class LegacyReplayFrameComparer : IComparer + private class ReplayFrameComparer : IComparer { - public int Compare(LegacyReplayFrame f1, LegacyReplayFrame f2) + public int Compare(ReplayFrame f1, ReplayFrame f2) { + if (f1 == null) throw new NullReferenceException($@"{nameof(f1)} cannot be null"); + if (f2 == null) throw new NullReferenceException($@"{nameof(f2)} cannot be null"); + return f1.Time.CompareTo(f2.Time); } } - private static readonly IComparer replay_frame_comparer = new LegacyReplayFrameComparer(); + private static readonly IComparer replay_frame_comparer = new ReplayFrameComparer(); - private int findInsertionIndex(LegacyReplayFrame frame) + private int findInsertionIndex(ReplayFrame frame) { int index = Frames.BinarySearch(frame, replay_frame_comparer); @@ -59,7 +63,7 @@ namespace osu.Game.Modes.Osu return index; } - private void addFrameToReplay(LegacyReplayFrame frame) => Frames.Insert(findInsertionIndex(frame), frame); + private void addFrameToReplay(ReplayFrame frame) => Frames.Insert(findInsertionIndex(frame), frame); private static Vector2 circlePosition(double t, double radius) => new Vector2((float)(Math.Cos(t) * radius), (float)(Math.Sin(t) * radius)); @@ -74,9 +78,9 @@ namespace osu.Game.Modes.Osu EasingTypes preferredEasing = DelayedMovements ? EasingTypes.InOutCubic : EasingTypes.Out; - addFrameToReplay(new LegacyReplayFrame(-100000, 256, 500, LegacyButtonState.None)); - addFrameToReplay(new LegacyReplayFrame(beatmap.HitObjects[0].StartTime - 1500, 256, 500, LegacyButtonState.None)); - addFrameToReplay(new LegacyReplayFrame(beatmap.HitObjects[0].StartTime - 1000, 256, 192, LegacyButtonState.None)); + addFrameToReplay(new ReplayFrame(-100000, 256, 500, ReplayButtonState.None)); + addFrameToReplay(new ReplayFrame(beatmap.HitObjects[0].StartTime - 1500, 256, 500, ReplayButtonState.None)); + addFrameToReplay(new ReplayFrame(beatmap.HitObjects[0].StartTime - 1000, 256, 192, ReplayButtonState.None)); // We are using ApplyModsToRate and not ApplyModsToTime to counteract the speed up / slow down from HalfTime / DoubleTime so that we remain at a constant framerate of 60 fps. float frameDelay = (float)applyModsToRate(1000.0 / 60.0); @@ -106,18 +110,18 @@ namespace osu.Game.Modes.Osu //Make the cursor stay at a hitObject as long as possible (mainly for autopilot). if (h.StartTime - h.HitWindowFor(OsuScoreResult.Miss) > endTime + h.HitWindowFor(OsuScoreResult.Hit50) + 50) { - if (!(last is Spinner) && h.StartTime - endTime < 1000) addFrameToReplay(new LegacyReplayFrame(endTime + h.HitWindowFor(OsuScoreResult.Hit50), last.EndPosition.X, last.EndPosition.Y, LegacyButtonState.None)); - if (!(h is Spinner)) addFrameToReplay(new LegacyReplayFrame(h.StartTime - h.HitWindowFor(OsuScoreResult.Miss), h.Position.X, h.Position.Y, LegacyButtonState.None)); + if (!(last is Spinner) && h.StartTime - endTime < 1000) addFrameToReplay(new ReplayFrame(endTime + h.HitWindowFor(OsuScoreResult.Hit50), last.EndPosition.X, last.EndPosition.Y, ReplayButtonState.None)); + if (!(h is Spinner)) addFrameToReplay(new ReplayFrame(h.StartTime - h.HitWindowFor(OsuScoreResult.Miss), h.Position.X, h.Position.Y, ReplayButtonState.None)); } else if (h.StartTime - h.HitWindowFor(OsuScoreResult.Hit50) > endTime + h.HitWindowFor(OsuScoreResult.Hit50) + 50) { - if (!(last is Spinner) && h.StartTime - endTime < 1000) addFrameToReplay(new LegacyReplayFrame(endTime + h.HitWindowFor(OsuScoreResult.Hit50), last.EndPosition.X, last.EndPosition.Y, LegacyButtonState.None)); - if (!(h is Spinner)) addFrameToReplay(new LegacyReplayFrame(h.StartTime - h.HitWindowFor(OsuScoreResult.Hit50), h.Position.X, h.Position.Y, LegacyButtonState.None)); + if (!(last is Spinner) && h.StartTime - endTime < 1000) addFrameToReplay(new ReplayFrame(endTime + h.HitWindowFor(OsuScoreResult.Hit50), last.EndPosition.X, last.EndPosition.Y, ReplayButtonState.None)); + if (!(h is Spinner)) addFrameToReplay(new ReplayFrame(h.StartTime - h.HitWindowFor(OsuScoreResult.Hit50), h.Position.X, h.Position.Y, ReplayButtonState.None)); } else if (h.StartTime - h.HitWindowFor(OsuScoreResult.Hit100) > endTime + h.HitWindowFor(OsuScoreResult.Hit100) + 50) { - if (!(last is Spinner) && h.StartTime - endTime < 1000) addFrameToReplay(new LegacyReplayFrame(endTime + h.HitWindowFor(OsuScoreResult.Hit100), last.EndPosition.X, last.EndPosition.Y, LegacyButtonState.None)); - if (!(h is Spinner)) addFrameToReplay(new LegacyReplayFrame(h.StartTime - h.HitWindowFor(OsuScoreResult.Hit100), h.Position.X, h.Position.Y, LegacyButtonState.None)); + if (!(last is Spinner) && h.StartTime - endTime < 1000) addFrameToReplay(new ReplayFrame(endTime + h.HitWindowFor(OsuScoreResult.Hit100), last.EndPosition.X, last.EndPosition.Y, ReplayButtonState.None)); + if (!(h is Spinner)) addFrameToReplay(new ReplayFrame(h.StartTime - h.HitWindowFor(OsuScoreResult.Hit100), h.Position.X, h.Position.Y, ReplayButtonState.None)); } } @@ -173,13 +177,13 @@ namespace osu.Game.Modes.Osu // Do some nice easing for cursor movements if (Frames.Count > 0) { - LegacyReplayFrame lastFrame = Frames[Frames.Count - 1]; + ReplayFrame lastFrame = Frames[Frames.Count - 1]; // Wait until Auto could "see and react" to the next note. double waitTime = h.StartTime - Math.Max(0.0, DrawableOsuHitObject.TIME_PREEMPT - reactionTime); if (waitTime > lastFrame.Time) { - lastFrame = new LegacyReplayFrame(waitTime, lastFrame.MouseX, lastFrame.MouseY, lastFrame.ButtonState); + lastFrame = new ReplayFrame(waitTime, lastFrame.MouseX, lastFrame.MouseY, lastFrame.ButtonState); addFrameToReplay(lastFrame); } @@ -196,7 +200,7 @@ namespace osu.Game.Modes.Osu for (double time = lastFrame.Time + frameDelay; time < h.StartTime; time += frameDelay) { Vector2 currentPosition = Interpolation.ValueAt(time, lastPosition, targetPosition, lastFrame.Time, h.StartTime, easing); - addFrameToReplay(new LegacyReplayFrame((int)time, currentPosition.X, currentPosition.Y, lastFrame.ButtonState)); + addFrameToReplay(new ReplayFrame((int)time, currentPosition.X, currentPosition.Y, lastFrame.ButtonState)); } buttonIndex = 0; @@ -207,12 +211,12 @@ namespace osu.Game.Modes.Osu } } - LegacyButtonState button = buttonIndex % 2 == 0 ? LegacyButtonState.Left1 : LegacyButtonState.Right1; + ReplayButtonState button = buttonIndex % 2 == 0 ? ReplayButtonState.Left1 : ReplayButtonState.Right1; double hEndTime = (h as IHasEndTime)?.EndTime ?? h.StartTime; - LegacyReplayFrame newFrame = new LegacyReplayFrame(h.StartTime, targetPosition.X, targetPosition.Y, button); - LegacyReplayFrame endFrame = new LegacyReplayFrame(hEndTime + endDelay, h.EndPosition.X, h.EndPosition.Y, LegacyButtonState.None); + ReplayFrame newFrame = new ReplayFrame(h.StartTime, targetPosition.X, targetPosition.Y, button); + ReplayFrame endFrame = new ReplayFrame(hEndTime + endDelay, h.EndPosition.X, h.EndPosition.Y, ReplayButtonState.None); // Decrement because we want the previous frame, not the next one int index = findInsertionIndex(newFrame) - 1; @@ -220,19 +224,19 @@ namespace osu.Game.Modes.Osu // Do we have a previous frame? No need to check for < replay.Count since we decremented! if (index >= 0) { - LegacyReplayFrame previousFrame = Frames[index]; + ReplayFrame previousFrame = Frames[index]; var previousButton = previousFrame.ButtonState; // If a button is already held, then we simply alternate - if (previousButton != LegacyButtonState.None) + if (previousButton != ReplayButtonState.None) { - Debug.Assert(previousButton != (LegacyButtonState.Left1 | LegacyButtonState.Right1)); + Debug.Assert(previousButton != (ReplayButtonState.Left1 | ReplayButtonState.Right1)); // Force alternation if we have the same button. Otherwise we can just keep the naturally to us assigned button. if (previousButton == button) { - button = (LegacyButtonState.Left1 | LegacyButtonState.Right1) & ~button; - newFrame.SetButtonStates(button); + button = (ReplayButtonState.Left1 | ReplayButtonState.Right1) & ~button; + newFrame.ButtonState = button; } // We always follow the most recent slider / spinner, so remove any other frames that occur while it exists. @@ -246,7 +250,7 @@ namespace osu.Game.Modes.Osu { // Don't affect frames which stop pressing a button! if (j < Frames.Count - 1 || Frames[j].ButtonState == previousButton) - Frames[j].SetButtonStates(button); + Frames[j].ButtonState = button; } } } @@ -270,13 +274,13 @@ namespace osu.Game.Modes.Osu t = applyModsToTime(j - h.StartTime) * spinnerDirection; Vector2 pos = spinner_centre + circlePosition(t / 20 + angle, spin_radius); - addFrameToReplay(new LegacyReplayFrame((int)j, pos.X, pos.Y, button)); + addFrameToReplay(new ReplayFrame((int)j, pos.X, pos.Y, button)); } t = applyModsToTime(s.EndTime - h.StartTime) * spinnerDirection; Vector2 endPosition = spinner_centre + circlePosition(t / 20 + angle, spin_radius); - addFrameToReplay(new LegacyReplayFrame(s.EndTime, endPosition.X, endPosition.Y, button)); + addFrameToReplay(new ReplayFrame(s.EndTime, endPosition.X, endPosition.Y, button)); endFrame.MouseX = endPosition.X; endFrame.MouseY = endPosition.Y; @@ -288,10 +292,10 @@ namespace osu.Game.Modes.Osu for (double j = frameDelay; j < s.Duration; j += frameDelay) { Vector2 pos = s.PositionAt(j / s.Duration); - addFrameToReplay(new LegacyReplayFrame(h.StartTime + j, pos.X, pos.Y, button)); + addFrameToReplay(new ReplayFrame(h.StartTime + j, pos.X, pos.Y, button)); } - addFrameToReplay(new LegacyReplayFrame(s.EndTime, s.EndPosition.X, s.EndPosition.Y, button)); + addFrameToReplay(new ReplayFrame(s.EndTime, s.EndPosition.X, s.EndPosition.Y, button)); } // We only want to let go of our button if we are at the end of the current replay. Otherwise something is still going on after us so we need to keep the button pressed! diff --git a/osu.Game.Modes.Osu/Scoring/OsuScoreProcessor.cs b/osu.Game.Modes.Osu/Scoring/OsuScoreProcessor.cs index b71e7dbadd..0bd587e8ea 100644 --- a/osu.Game.Modes.Osu/Scoring/OsuScoreProcessor.cs +++ b/osu.Game.Modes.Osu/Scoring/OsuScoreProcessor.cs @@ -28,7 +28,7 @@ namespace osu.Game.Modes.Osu.Scoring Accuracy.Value = 1; } - protected override void OnNewJugement(OsuJudgement judgement) + protected override void OnNewJudgement(OsuJudgement judgement) { if (judgement != null) { diff --git a/osu.Game.Modes.Taiko/Beatmaps/TaikoBeatmapConverter.cs b/osu.Game.Modes.Taiko/Beatmaps/TaikoBeatmapConverter.cs index 1fc2db53fa..cc361628a3 100644 --- a/osu.Game.Modes.Taiko/Beatmaps/TaikoBeatmapConverter.cs +++ b/osu.Game.Modes.Taiko/Beatmaps/TaikoBeatmapConverter.cs @@ -44,7 +44,10 @@ namespace osu.Game.Modes.Taiko.Beatmaps IHasRepeats repeatsData = original as IHasRepeats; IHasEndTime endTimeData = original as IHasEndTime; - bool strong = ((original.Sample?.Type ?? SampleType.None) & SampleType.Finish) > 0; + // Old osu! used hit sounding to determine various hit type information + SampleType sample = original.Sample?.Type ?? SampleType.None; + + bool strong = (sample & SampleType.Finish) > 0; if (distanceData != null) { @@ -71,11 +74,23 @@ namespace osu.Game.Modes.Taiko.Beatmaps }; } - return new Hit + bool isCentre = (sample & ~(SampleType.Finish | SampleType.Normal)) == 0; + + if (isCentre) + { + return new CentreHit + { + StartTime = original.StartTime, + Sample = original.Sample, + IsStrong = strong + }; + } + + return new RimHit { StartTime = original.StartTime, Sample = original.Sample, - IsStrong = strong + IsStrong = strong, }; } } diff --git a/osu.Game.Modes.Taiko/Judgements/TaikoJudgement.cs b/osu.Game.Modes.Taiko/Judgements/TaikoJudgement.cs index e50a685e24..f4745730db 100644 --- a/osu.Game.Modes.Taiko/Judgements/TaikoJudgement.cs +++ b/osu.Game.Modes.Taiko/Judgements/TaikoJudgement.cs @@ -22,7 +22,7 @@ namespace osu.Game.Modes.Taiko.Judgements /// The result value for the combo portion of the score. /// public int ResultValueForScore => NumericResultForScore(TaikoResult); - + /// /// The result value for the accuracy portion of the score. /// @@ -32,7 +32,7 @@ namespace osu.Game.Modes.Taiko.Judgements /// The maximum result value for the combo portion of the score. /// public int MaxResultValueForScore => NumericResultForScore(MAX_HIT_RESULT); - + /// /// The maximum result value for the accuracy portion of the score. /// @@ -45,7 +45,7 @@ namespace osu.Game.Modes.Taiko.Judgements /// /// Whether this Judgement has a secondary hit in the case of finishers. /// - public bool SecondHit; + public virtual bool SecondHit { get; set; } /// /// Computes the numeric result value for the combo portion of the score. diff --git a/osu.Game.Modes.Taiko/Judgements/TaikoStrongHitJudgement.cs b/osu.Game.Modes.Taiko/Judgements/TaikoStrongHitJudgement.cs new file mode 100644 index 0000000000..ee978d0026 --- /dev/null +++ b/osu.Game.Modes.Taiko/Judgements/TaikoStrongHitJudgement.cs @@ -0,0 +1,25 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Modes.Judgements; + +namespace osu.Game.Modes.Taiko.Judgements +{ + public class TaikoStrongHitJudgement : TaikoJudgement, IPartialJudgement + { + public bool Changed { get; set; } + + public override bool SecondHit + { + get { return base.SecondHit; } + set + { + if (base.SecondHit == value) + return; + base.SecondHit = value; + + Changed = true; + } + } + } +} diff --git a/osu.Game.Modes.Taiko/Mods/TaikoMod.cs b/osu.Game.Modes.Taiko/Mods/TaikoMod.cs index c929ebffdd..422f0ec250 100644 --- a/osu.Game.Modes.Taiko/Mods/TaikoMod.cs +++ b/osu.Game.Modes.Taiko/Mods/TaikoMod.cs @@ -1,7 +1,12 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Game.Beatmaps; using osu.Game.Modes.Mods; +using osu.Game.Modes.Scoring; +using osu.Game.Modes.Taiko.Objects; +using osu.Game.Modes.Taiko.Replays; +using osu.Game.Users; namespace osu.Game.Modes.Taiko.Mods { @@ -61,4 +66,13 @@ namespace osu.Game.Modes.Taiko.Mods { } + + public class TaikoModAutoplay : ModAutoplay + { + protected override Score CreateReplayScore(Beatmap beatmap) => new Score + { + User = new User { Username = "mekkadosu!" }, + Replay = new TaikoAutoReplay(beatmap) + }; + } } diff --git a/osu.Game.Modes.Taiko/Objects/CentreHit.cs b/osu.Game.Modes.Taiko/Objects/CentreHit.cs new file mode 100644 index 0000000000..258112f045 --- /dev/null +++ b/osu.Game.Modes.Taiko/Objects/CentreHit.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Modes.Taiko.Objects +{ + public class CentreHit : Hit + { + } +} diff --git a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableDrumRollTick.cs b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableDrumRollTick.cs index 11a4b56930..b7509bc51d 100644 --- a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableDrumRollTick.cs +++ b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableDrumRollTick.cs @@ -99,7 +99,7 @@ namespace osu.Game.Modes.Taiko.Objects.Drawable protected override bool HandleKeyPress(Key key) { - return !Judgement.Result.HasValue && UpdateJudgement(true); + return Judgement.Result == HitResult.None && UpdateJudgement(true); } } } diff --git a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs index ae328fe9ca..c8a7355e3c 100644 --- a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs +++ b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableHit.cs @@ -68,7 +68,7 @@ namespace osu.Game.Modes.Taiko.Objects.Drawable protected override bool HandleKeyPress(Key key) { - if (Judgement.Result.HasValue) + if (Judgement.Result != HitResult.None) return false; validKeyPressed = HitKeys.Contains(key); diff --git a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableStrongHit.cs b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableStrongHit.cs index 5e225e1dce..a6cb6ae7fa 100644 --- a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableStrongHit.cs +++ b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableStrongHit.cs @@ -5,6 +5,8 @@ using OpenTK.Input; using System; using System.Linq; using osu.Framework.Input; +using osu.Game.Modes.Objects.Drawables; +using osu.Game.Modes.Taiko.Judgements; namespace osu.Game.Modes.Taiko.Objects.Drawable { @@ -25,9 +27,11 @@ namespace osu.Game.Modes.Taiko.Objects.Drawable { } + protected override TaikoJudgement CreateJudgement() => new TaikoStrongHitJudgement(); + protected override void CheckJudgement(bool userTriggered) { - if (!Judgement.Result.HasValue) + if (Judgement.Result == HitResult.None) { base.CheckJudgement(userTriggered); return; @@ -45,7 +49,7 @@ namespace osu.Game.Modes.Taiko.Objects.Drawable protected override bool HandleKeyPress(Key key) { // Check if we've handled the first key - if (!Judgement.Result.HasValue) + if (Judgement.Result == HitResult.None) { // First key hasn't been handled yet, attempt to handle it bool handled = base.HandleKeyPress(key); diff --git a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableSwell.cs b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableSwell.cs index d789d12c90..ccd6380542 100644 --- a/osu.Game.Modes.Taiko/Objects/Drawable/DrawableSwell.cs +++ b/osu.Game.Modes.Taiko/Objects/Drawable/DrawableSwell.cs @@ -219,7 +219,7 @@ namespace osu.Game.Modes.Taiko.Objects.Drawable protected override bool HandleKeyPress(Key key) { - if (Judgement.Result.HasValue) + if (Judgement.Result != HitResult.None) return false; // Don't handle keys before the swell starts diff --git a/osu.Game.Modes.Taiko/Objects/Drawable/Pieces/CirclePiece.cs b/osu.Game.Modes.Taiko/Objects/Drawable/Pieces/CirclePiece.cs index 52dad28d31..d51c06bcad 100644 --- a/osu.Game.Modes.Taiko/Objects/Drawable/Pieces/CirclePiece.cs +++ b/osu.Game.Modes.Taiko/Objects/Drawable/Pieces/CirclePiece.cs @@ -19,7 +19,7 @@ namespace osu.Game.Modes.Taiko.Objects.Drawable.Pieces /// a rounded (_[-Width-]_) figure such that a regular "circle" is the result of a parent with Width = 0. /// /// - public class CirclePiece : Container, IAccented + public class CirclePiece : Container, IHasAccentColour { public const float SYMBOL_SIZE = TaikoHitObject.CIRCLE_RADIUS * 2f * 0.45f; public const float SYMBOL_BORDER = 8; diff --git a/osu.Game.Modes.Taiko/Objects/RimHit.cs b/osu.Game.Modes.Taiko/Objects/RimHit.cs new file mode 100644 index 0000000000..aae93ec10d --- /dev/null +++ b/osu.Game.Modes.Taiko/Objects/RimHit.cs @@ -0,0 +1,9 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +namespace osu.Game.Modes.Taiko.Objects +{ + public class RimHit : Hit + { + } +} diff --git a/osu.Game.Modes.Taiko/Replays/TaikoAutoReplay.cs b/osu.Game.Modes.Taiko/Replays/TaikoAutoReplay.cs new file mode 100644 index 0000000000..c8a93c9068 --- /dev/null +++ b/osu.Game.Modes.Taiko/Replays/TaikoAutoReplay.cs @@ -0,0 +1,121 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Game.Beatmaps; +using osu.Game.Modes.Objects.Types; +using osu.Game.Modes.Taiko.Objects; +using osu.Game.Modes.Replays; + +namespace osu.Game.Modes.Taiko.Replays +{ + public class TaikoAutoReplay : Replay + { + private readonly Beatmap beatmap; + + public TaikoAutoReplay(Beatmap beatmap) + { + this.beatmap = beatmap; + + createAutoReplay(); + } + + private void createAutoReplay() + { + bool hitButton = true; + + Frames.Add(new ReplayFrame(-100000, 320, 240, ReplayButtonState.None)); + Frames.Add(new ReplayFrame(beatmap.HitObjects[0].StartTime - 1000, 320, 240, ReplayButtonState.None)); + + for (int i = 0; i < beatmap.HitObjects.Count; i++) + { + TaikoHitObject h = beatmap.HitObjects[i]; + + ReplayButtonState button; + + IHasEndTime endTimeData = h as IHasEndTime; + double endTime = endTimeData?.EndTime ?? h.StartTime; + + Swell swell = h as Swell; + DrumRoll drumRoll = h as DrumRoll; + Hit hit = h as Hit; + + if (swell != null) + { + int d = 0; + int count = 0; + int req = swell.RequiredHits; + double hitRate = swell.Duration / req; + for (double j = h.StartTime; j < endTime; j += hitRate) + { + switch (d) + { + default: + button = ReplayButtonState.Left1; + break; + case 1: + button = ReplayButtonState.Right1; + break; + case 2: + button = ReplayButtonState.Left2; + break; + case 3: + button = ReplayButtonState.Right2; + break; + } + + Frames.Add(new ReplayFrame(j, 0, 0, button)); + d = (d + 1) % 4; + if (++count > req) + break; + } + } + else if (drumRoll != null) + { + double delay = drumRoll.TickTimeDistance; + + double time = drumRoll.StartTime; + + for (int j = 0; j < drumRoll.TotalTicks; j++) + { + Frames.Add(new ReplayFrame((int)time, 0, 0, hitButton ? ReplayButtonState.Left1 : ReplayButtonState.Left2)); + time += delay; + hitButton = !hitButton; + } + } + else if (hit != null) + { + if (hit is CentreHit) + { + if (h.IsStrong) + button = ReplayButtonState.Right1 | ReplayButtonState.Right2; + else + button = hitButton ? ReplayButtonState.Right1 : ReplayButtonState.Right2; + } + else + { + if (h.IsStrong) + button = ReplayButtonState.Left1 | ReplayButtonState.Left2; + else + button = hitButton ? ReplayButtonState.Left1 : ReplayButtonState.Left2; + } + + Frames.Add(new ReplayFrame(h.StartTime, 0, 0, button)); + } + else + throw new Exception("Unknown hit object type."); + + Frames.Add(new ReplayFrame(endTime + 1, 0, 0, ReplayButtonState.None)); + + if (i < beatmap.HitObjects.Count - 1) + { + double waitTime = beatmap.HitObjects[i + 1].StartTime - 1000; + if (waitTime > endTime) + Frames.Add(new ReplayFrame(waitTime, 0, 0, ReplayButtonState.None)); + } + + hitButton = !hitButton; + } + } + } +} \ No newline at end of file diff --git a/osu.Game.Modes.Taiko/Replays/TaikoFramedReplayInputHandler.cs b/osu.Game.Modes.Taiko/Replays/TaikoFramedReplayInputHandler.cs new file mode 100644 index 0000000000..44fca4abe7 --- /dev/null +++ b/osu.Game.Modes.Taiko/Replays/TaikoFramedReplayInputHandler.cs @@ -0,0 +1,37 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Modes.Replays; +using System.Collections.Generic; +using osu.Framework.Input; +using OpenTK.Input; + +namespace osu.Game.Modes.Taiko.Replays +{ + internal class TaikoFramedReplayInputHandler : FramedReplayInputHandler + { + public TaikoFramedReplayInputHandler(Replay replay) + : base(replay) + { + } + + public override List GetPendingStates() + { + var keys = new List(); + + if (CurrentFrame?.MouseRight1 == true) + keys.Add(Key.F); + if (CurrentFrame?.MouseRight2 == true) + keys.Add(Key.J); + if (CurrentFrame?.MouseLeft1 == true) + keys.Add(Key.D); + if (CurrentFrame?.MouseLeft2 == true) + keys.Add(Key.K); + + return new List + { + new InputState { Keyboard = new ReplayKeyboardState(keys) } + }; + } + } +} diff --git a/osu.Game.Modes.Taiko/Scoring/TaikoScoreProcessor.cs b/osu.Game.Modes.Taiko/Scoring/TaikoScoreProcessor.cs index 2ab31c5efb..fa7e18cadb 100644 --- a/osu.Game.Modes.Taiko/Scoring/TaikoScoreProcessor.cs +++ b/osu.Game.Modes.Taiko/Scoring/TaikoScoreProcessor.cs @@ -96,9 +96,9 @@ namespace osu.Game.Modes.Taiko.Scoring /// /// The multiple of the original score added to the combo portion of the score - /// for correctly hitting an accented hit object with both keys. + /// for correctly hitting a strong hit object with both keys. /// - private double accentedHitScale; + private double strongHitScale; private double hpIncreaseTick; private double hpIncreaseGreat; @@ -128,12 +128,12 @@ namespace osu.Game.Modes.Taiko.Scoring hpIncreaseGood = hpMultiplierNormal * hp_hit_good; hpIncreaseMiss = BeatmapDifficulty.DifficultyRange(beatmap.BeatmapInfo.Difficulty.DrainRate, hp_miss_min, hp_miss_mid, hp_miss_max); - var accentedHits = beatmap.HitObjects.FindAll(o => o is Hit && o.IsStrong); + var strongHits = beatmap.HitObjects.FindAll(o => o is Hit && o.IsStrong); // This is a linear function that awards: - // 10 times bonus points for hitting an accented hit object with both keys with 30 accented hit objects in the map - // 3 times bonus points for hitting an accented hit object with both keys with 120 accented hit objects in the map - accentedHitScale = -7d / 90d * MathHelper.Clamp(accentedHits.Count, 30, 120) + 111d / 9d; + // 10 times bonus points for hitting a strong hit object with both keys with 30 strong hit objects in the map + // 3 times bonus points for hitting a strong hit object with both keys with 120 strong hit objects in the map + strongHitScale = -7d / 90d * MathHelper.Clamp(strongHits.Count, 30, 120) + 111d / 9d; foreach (var obj in beatmap.HitObjects) { @@ -179,7 +179,7 @@ namespace osu.Game.Modes.Taiko.Scoring maxComboPortion = comboPortion; } - protected override void OnNewJugement(TaikoJudgement judgement) + protected override void OnNewJudgement(TaikoJudgement judgement) { bool isTick = judgement is TaikoDrumRollTickJudgement; @@ -187,29 +187,12 @@ namespace osu.Game.Modes.Taiko.Scoring if (!isTick) totalHits++; + // Apply combo changes, must be done before the hit score is added + if (!isTick && judgement.Result == HitResult.Hit) + Combo.Value++; + // Apply score changes - if (judgement.Result == HitResult.Hit) - { - double baseValue = judgement.ResultValueForScore; - - // Add bonus points for hitting an accented hit object with the second key - if (judgement.SecondHit) - baseValue += baseValue * accentedHitScale; - - // Add score to portions - if (isTick) - bonusScore += baseValue; - else - { - Combo.Value++; - - // A relevance factor that needs to be applied to make higher combos more relevant - // Value is capped at 400 combo - double comboRelevance = Math.Min(Math.Log(400, combo_base), Math.Max(0.5, Math.Log(Combo.Value, combo_base))); - - comboPortion += baseValue * comboRelevance; - } - } + addHitScore(judgement); // Apply HP changes switch (judgement.Result) @@ -235,7 +218,43 @@ namespace osu.Game.Modes.Taiko.Scoring break; } - // Compute the new score + accuracy + calculateScore(); + } + + protected override void OnJudgementChanged(TaikoJudgement judgement) + { + // Apply score changes + addHitScore(judgement); + + calculateScore(); + } + + private void addHitScore(TaikoJudgement judgement) + { + if (judgement.Result != HitResult.Hit) + return; + + double baseValue = judgement.ResultValueForScore; + + // Add increased score for hitting a strong hit object with the second key + if (judgement.SecondHit) + baseValue *= strongHitScale; + + // Add score to portions + if (judgement is TaikoDrumRollTickJudgement) + bonusScore += baseValue; + else + { + // A relevance factor that needs to be applied to make higher combos more relevant + // Value is capped at 400 combo + double comboRelevance = Math.Min(Math.Log(400, combo_base), Math.Max(0.5, Math.Log(Combo.Value, combo_base))); + + comboPortion += baseValue * comboRelevance; + } + } + + private void calculateScore() + { int scoreForAccuracy = 0; int maxScoreForAccuracy = 0; diff --git a/osu.Game.Modes.Taiko/TaikoRuleset.cs b/osu.Game.Modes.Taiko/TaikoRuleset.cs index ce7e756e30..1b3c3fc0eb 100644 --- a/osu.Game.Modes.Taiko/TaikoRuleset.cs +++ b/osu.Game.Modes.Taiko/TaikoRuleset.cs @@ -65,7 +65,7 @@ namespace osu.Game.Modes.Taiko { Mods = new Mod[] { - new ModAutoplay(), + new TaikoModAutoplay(), new ModCinema(), }, }, diff --git a/osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs b/osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs index 3266b5c030..e70e2d3811 100644 --- a/osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs +++ b/osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs @@ -3,10 +3,12 @@ using osu.Game.Beatmaps; using osu.Game.Modes.Objects.Drawables; +using osu.Game.Modes.Replays; using osu.Game.Modes.Scoring; using osu.Game.Modes.Taiko.Beatmaps; using osu.Game.Modes.Taiko.Judgements; using osu.Game.Modes.Taiko.Objects; +using osu.Game.Modes.Taiko.Replays; using osu.Game.Modes.Taiko.Scoring; using osu.Game.Modes.UI; @@ -28,5 +30,7 @@ namespace osu.Game.Modes.Taiko.UI protected override Playfield CreatePlayfield() => new TaikoPlayfield(); protected override DrawableHitObject GetVisualRepresentation(TaikoHitObject h) => null; + + protected override FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new TaikoFramedReplayInputHandler(replay); } } diff --git a/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj b/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj index 5afce57071..f3f93d720a 100644 --- a/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj +++ b/osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj @@ -50,8 +50,10 @@ + + @@ -71,7 +73,10 @@ + + + diff --git a/osu.Game/Database/ScoreDatabase.cs b/osu.Game/Database/ScoreDatabase.cs index 096c0dcc29..5ce3ff273e 100644 --- a/osu.Game/Database/ScoreDatabase.cs +++ b/osu.Game/Database/ScoreDatabase.cs @@ -101,7 +101,7 @@ namespace osu.Game.Database using (var lzma = new LzmaStream(properties, replayInStream, compressedSize, outSize)) using (var reader = new StreamReader(lzma)) - score.Replay = score.CreateLegacyReplayFrom(reader); + score.Replay = score.CreateReplay(reader); } } diff --git a/osu.Game/Graphics/IAccented.cs b/osu.Game/Graphics/IHasAccentColour.cs similarity index 59% rename from osu.Game/Graphics/IAccented.cs rename to osu.Game/Graphics/IHasAccentColour.cs index 6f0f107f3c..f959bc8760 100644 --- a/osu.Game/Graphics/IAccented.cs +++ b/osu.Game/Graphics/IHasAccentColour.cs @@ -12,25 +12,23 @@ namespace osu.Game.Graphics /// The accent colour is used to colorize various objects inside a drawable /// without colorizing the drawable itself. /// - public interface IAccented : IDrawable + public interface IHasAccentColour : IDrawable { Color4 AccentColour { get; set; } } - public static class AccentedExtensions + public static class AccentedColourExtensions { /// /// Tweens the accent colour of a drawable to another colour. /// - /// The type of drawable. - /// The drawable to apply the accent colour to. + /// The drawable to apply the accent colour to. /// The new accent colour. /// The tween duration. /// The tween easing. - public static void FadeAccent(this TDrawable drawable, Color4 newColour, double duration = 0, EasingTypes easing = EasingTypes.None) - where TDrawable : Drawable, IAccented + public static void FadeAccent(this IHasAccentColour accentedDrawable, Color4 newColour, double duration = 0, EasingTypes easing = EasingTypes.None) { - drawable.TransformTo(drawable.AccentColour, newColour, duration, easing, new TransformAccent()); + accentedDrawable.TransformTo(accentedDrawable.AccentColour, newColour, duration, easing, new TransformAccent()); } } } diff --git a/osu.Game/Graphics/Transforms/TransformAccent.cs b/osu.Game/Graphics/Transforms/TransformAccent.cs index 7f40a0a016..406d1ea9eb 100644 --- a/osu.Game/Graphics/Transforms/TransformAccent.cs +++ b/osu.Game/Graphics/Transforms/TransformAccent.cs @@ -29,7 +29,7 @@ namespace osu.Game.Graphics.Transforms { base.Apply(d); - var accented = d as IAccented; + var accented = d as IHasAccentColour; if (accented != null) accented.AccentColour = CurrentValue; } diff --git a/osu.Game/Modes/Judgements/IPartialJudgement.cs b/osu.Game/Modes/Judgements/IPartialJudgement.cs new file mode 100644 index 0000000000..2ca1ffce4d --- /dev/null +++ b/osu.Game/Modes/Judgements/IPartialJudgement.cs @@ -0,0 +1,26 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Modes.Objects.Drawables; +using osu.Game.Modes.Scoring; + +namespace osu.Game.Modes.Judgements +{ + /// + /// Inidicates that the judgement this is attached to is a partial judgement and the scoring value may change. + /// + /// This judgement will be continually processed by + /// unless the result is a miss and will trigger a full re-process of the when changed. + /// + /// + public interface IPartialJudgement + { + /// + /// Indicates that this partial judgement has changed and requires a full re-process of the . + /// + /// This is set to false once the judgement has been re-processed. + /// + /// + bool Changed { get; set; } + } +} diff --git a/osu.Game/Modes/Judgements/Judgement.cs b/osu.Game/Modes/Judgements/Judgement.cs index d916fc15de..677ec8bca9 100644 --- a/osu.Game/Modes/Judgements/Judgement.cs +++ b/osu.Game/Modes/Judgements/Judgement.cs @@ -10,7 +10,7 @@ namespace osu.Game.Modes.Judgements /// /// Whether this judgement is the result of a hit or a miss. /// - public HitResult? Result; + public HitResult Result; /// /// The offset at which this judgement occurred. @@ -20,7 +20,7 @@ namespace osu.Game.Modes.Judgements /// /// The combo after this judgement was processed. /// - public ulong? ComboAtHit; + public int ComboAtHit; /// /// The string representation for the result achieved. diff --git a/osu.Game/Modes/LegacyReplay.cs b/osu.Game/Modes/LegacyReplay.cs deleted file mode 100644 index d57d4a15d2..0000000000 --- a/osu.Game/Modes/LegacyReplay.cs +++ /dev/null @@ -1,268 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using System; -using System.Collections.Generic; -using System.IO; -using osu.Framework.Extensions.IEnumerableExtensions; -using osu.Framework.Input; -using osu.Framework.MathUtils; -using osu.Game.Input.Handlers; -using osu.Game.IO.Legacy; -using OpenTK; -using OpenTK.Input; -using KeyboardState = osu.Framework.Input.KeyboardState; -using MouseState = osu.Framework.Input.MouseState; - -namespace osu.Game.Modes -{ - public class LegacyReplay : Replay - { - protected List Frames = new List(); - - protected LegacyReplay() - { - - } - - public LegacyReplay(StreamReader reader) - { - float lastTime = 0; - - foreach (var l in reader.ReadToEnd().Split(',')) - { - var split = l.Split('|'); - - if (split.Length < 4 || float.Parse(split[0]) < 0) continue; - - lastTime += float.Parse(split[0]); - - Frames.Add(new LegacyReplayFrame( - lastTime, - float.Parse(split[1]), - 384 - float.Parse(split[2]), - (LegacyButtonState)int.Parse(split[3]) - )); - } - } - - public override ReplayInputHandler CreateInputHandler() => new LegacyReplayInputHandler(Frames); - - /// - /// The ReplayHandler will take a replay and handle the propagation of updates to the input stack. - /// It handles logic of any frames which *must* be executed. - /// - protected class LegacyReplayInputHandler : ReplayInputHandler - { - private readonly List replayContent; - - public LegacyReplayFrame CurrentFrame => !hasFrames ? null : replayContent[currentFrameIndex]; - public LegacyReplayFrame NextFrame => !hasFrames ? null : replayContent[nextFrameIndex]; - - private 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 advanceFrame() - { - int newFrame = nextFrameIndex; - - //ensure we aren't at an extent. - if (newFrame == currentFrameIndex) return false; - - currentFrameIndex = newFrame; - return true; - } - - public void SetPosition(Vector2 pos) - { - } - - private Vector2? position - { - get - { - if (!hasFrames) - return null; - - return Interpolation.ValueAt(currentTime, CurrentFrame.Position, NextFrame.Position, CurrentFrame.Time, NextFrame.Time); - } - } - - public override List GetPendingStates() - { - var buttons = new HashSet(); - if (CurrentFrame?.MouseLeft ?? false) - buttons.Add(MouseButton.Left); - if (CurrentFrame?.MouseRight ?? false) - buttons.Add(MouseButton.Right); - - return new List - { - new InputState - { - Mouse = new ReplayMouseState(ToScreenSpace(position ?? Vector2.Zero), buttons), - Keyboard = new ReplayKeyboardState(new List()) - } - }; - } - - public bool AtLastFrame => currentFrameIndex == replayContent.Count - 1; - public bool AtFirstFrame => currentFrameIndex == 0; - - public Vector2 Size => new Vector2(512, 384); - - private const double sixty_frame_time = 1000.0 / 60; - - private double currentTime; - private int currentDirection; - - /// - /// When set, we will ensure frames executed by nested drawables are frame-accurate to replay data. - /// Disabling this can make replay playback smoother (useful for autoplay, currently). - /// - public bool FrameAccuratePlayback = true; - - private bool hasFrames => replayContent.Count > 0; - - private bool inImportantSection => - FrameAccuratePlayback && - //a button is in a pressed state - (currentDirection > 0 ? CurrentFrame : NextFrame)?.ButtonState > LegacyButtonState.None && - //the next frame is within an allowable time span - Math.Abs(currentTime - NextFrame?.Time ?? 0) <= sixty_frame_time * 1.2; - - /// - /// Update the current frame based on an incoming time value. - /// There are cases where we return a "must-use" time value that is different from the input. - /// This is to ensure accurate playback of replay data. - /// - /// The time which we should use for finding the current frame. - /// The usable time value. If null, we should not advance time as we do not have enough data. - public override double? SetFrameFromTime(double time) - { - currentDirection = time.CompareTo(currentTime); - if (currentDirection == 0) currentDirection = 1; - - if (hasFrames) - { - //if we changed frames, we want to execute once *exactly* on the frame's time. - 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. - if (inImportantSection) - return null; - } - - return currentTime = time; - } - - protected class ReplayMouseState : MouseState - { - public ReplayMouseState(Vector2 position, IEnumerable list) - { - Position = position; - list.ForEach(b => PressedButtons.Add(b)); - } - } - - protected class ReplayKeyboardState : KeyboardState - { - public ReplayKeyboardState(List keys) - { - Keys = keys; - } - } - } - - [Flags] - protected enum LegacyButtonState - { - None = 0, - Left1 = 1, - Right1 = 2, - Left2 = 4, - Right2 = 8, - Smoke = 16 - } - - protected class LegacyReplayFrame - { - public Vector2 Position => new Vector2(MouseX, MouseY); - - public float MouseX; - public float MouseY; - public bool MouseLeft; - public bool MouseRight; - public bool MouseLeft1; - public bool MouseRight1; - public bool MouseLeft2; - public bool MouseRight2; - public LegacyButtonState ButtonState; - public double Time; - - public LegacyReplayFrame(double time, float posX, float posY, LegacyButtonState buttonState) - { - MouseX = posX; - MouseY = posY; - ButtonState = buttonState; - SetButtonStates(buttonState); - Time = time; - } - - public void SetButtonStates(LegacyButtonState buttonState) - { - ButtonState = buttonState; - MouseLeft = (buttonState & (LegacyButtonState.Left1 | LegacyButtonState.Left2)) > 0; - MouseLeft1 = (buttonState & LegacyButtonState.Left1) > 0; - MouseLeft2 = (buttonState & LegacyButtonState.Left2) > 0; - MouseRight = (buttonState & (LegacyButtonState.Right1 | LegacyButtonState.Right2)) > 0; - MouseRight1 = (buttonState & LegacyButtonState.Right1) > 0; - MouseRight2 = (buttonState & LegacyButtonState.Right2) > 0; - } - - public LegacyReplayFrame(Stream s) : this(new SerializationReader(s)) - { - } - - public LegacyReplayFrame(SerializationReader sr) - { - ButtonState = (LegacyButtonState)sr.ReadByte(); - SetButtonStates(ButtonState); - - byte bt = sr.ReadByte(); - if (bt > 0)//Handle Pre-Taiko compatible replays. - SetButtonStates(LegacyButtonState.Right1); - - MouseX = sr.ReadSingle(); - MouseY = sr.ReadSingle(); - Time = sr.ReadInt32(); - } - - public void ReadFromStream(SerializationReader sr) - { - throw new NotImplementedException(); - } - - public void WriteToStream(SerializationWriter sw) - { - sw.Write((byte)ButtonState); - sw.Write((byte)0); - sw.Write(MouseX); - sw.Write(MouseY); - sw.Write(Time); - } - - public override string ToString() - { - return $"{Time}\t({MouseX},{MouseY})\t{MouseLeft}\t{MouseRight}\t{MouseLeft1}\t{MouseRight1}\t{MouseLeft2}\t{MouseRight2}\t{ButtonState}"; - } - } - } -} diff --git a/osu.Game/Modes/Mods/Mod.cs b/osu.Game/Modes/Mods/Mod.cs index c53c6faa21..b6f09b8506 100644 --- a/osu.Game/Modes/Mods/Mod.cs +++ b/osu.Game/Modes/Mods/Mod.cs @@ -157,7 +157,7 @@ namespace osu.Game.Modes.Mods public void Apply(HitRenderer hitRenderer) { - hitRenderer.InputManager.ReplayInputHandler = CreateReplayScore(hitRenderer.Beatmap)?.Replay?.CreateInputHandler(); + hitRenderer.SetReplay(CreateReplayScore(hitRenderer.Beatmap)?.Replay); } } diff --git a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs index 3998a3e385..ed8269876e 100644 --- a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs @@ -93,16 +93,26 @@ namespace osu.Game.Modes.Objects.Drawables /// Whether a hit was processed. protected bool UpdateJudgement(bool userTriggered) { - if (Judgement.Result != null) + IPartialJudgement partial = Judgement as IPartialJudgement; + + // Never re-process non-partial hits + if (Judgement.Result != HitResult.None && partial == null) return false; + // Update the judgement state double endTime = (HitObject as IHasEndTime)?.EndTime ?? HitObject.StartTime; - Judgement.TimeOffset = Time.Current - endTime; + // Update the judgement state + bool hadResult = Judgement.Result != HitResult.None; CheckJudgement(userTriggered); - if (Judgement.Result == null) + // Don't process judgements with no result + if (Judgement.Result == HitResult.None) + return false; + + // Don't process judgements that previously had results but the results were unchanged + if (hadResult && partial?.Changed != true) return false; switch (Judgement.Result) @@ -117,6 +127,9 @@ namespace osu.Game.Modes.Objects.Drawables OnJudgement?.Invoke(this); + if (partial != null) + partial.Changed = false; + return true; } diff --git a/osu.Game/Modes/Objects/Drawables/HitResult.cs b/osu.Game/Modes/Objects/Drawables/HitResult.cs index 1bbf9269bb..e036610ae2 100644 --- a/osu.Game/Modes/Objects/Drawables/HitResult.cs +++ b/osu.Game/Modes/Objects/Drawables/HitResult.cs @@ -7,8 +7,19 @@ namespace osu.Game.Modes.Objects.Drawables { public enum HitResult { + /// + /// Indicates that the object has not been judged yet. + /// + [Description("")] + None, + /// + /// Indicates that the object has been judged as a miss. + /// [Description(@"Miss")] Miss, + /// + /// Indicates that the object has been judged as a hit. + /// [Description(@"Hit")] Hit, } diff --git a/osu.Game/Modes/Replay.cs b/osu.Game/Modes/Replay.cs deleted file mode 100644 index 6d93afdeb9..0000000000 --- a/osu.Game/Modes/Replay.cs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Game.Input.Handlers; - -namespace osu.Game.Modes -{ - public abstract class Replay - { - public virtual ReplayInputHandler CreateInputHandler() => null; - } -} \ No newline at end of file diff --git a/osu.Game/Modes/Replays/FramedReplayInputHandler.cs b/osu.Game/Modes/Replays/FramedReplayInputHandler.cs new file mode 100644 index 0000000000..ae20ece515 --- /dev/null +++ b/osu.Game/Modes/Replays/FramedReplayInputHandler.cs @@ -0,0 +1,151 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using osu.Framework.Extensions.IEnumerableExtensions; +using osu.Framework.Input; +using osu.Framework.MathUtils; +using osu.Game.Input.Handlers; +using OpenTK; +using OpenTK.Input; +using KeyboardState = osu.Framework.Input.KeyboardState; +using MouseState = osu.Framework.Input.MouseState; + +namespace osu.Game.Modes.Replays +{ + /// + /// The ReplayHandler will take a replay and handle the propagation of updates to the input stack. + /// It handles logic of any frames which *must* be executed. + /// + public class FramedReplayInputHandler : ReplayInputHandler + { + private readonly Replay replay; + + protected List Frames => replay.Frames; + + public ReplayFrame CurrentFrame => !hasFrames ? null : Frames[currentFrameIndex]; + public ReplayFrame NextFrame => !hasFrames ? null : Frames[nextFrameIndex]; + + private int currentFrameIndex; + + private int nextFrameIndex => MathHelper.Clamp(currentFrameIndex + (currentDirection > 0 ? 1 : -1), 0, Frames.Count - 1); + + public FramedReplayInputHandler(Replay replay) + { + this.replay = replay; + } + + private bool advanceFrame() + { + int newFrame = nextFrameIndex; + + //ensure we aren't at an extent. + if (newFrame == currentFrameIndex) return false; + + currentFrameIndex = newFrame; + return true; + } + + public void SetPosition(Vector2 pos) + { + } + + private Vector2? position + { + get + { + if (!hasFrames) + return null; + + return Interpolation.ValueAt(currentTime, CurrentFrame.Position, NextFrame.Position, CurrentFrame.Time, NextFrame.Time); + } + } + + public override List GetPendingStates() + { + var buttons = new HashSet(); + if (CurrentFrame?.MouseLeft ?? false) + buttons.Add(MouseButton.Left); + if (CurrentFrame?.MouseRight ?? false) + buttons.Add(MouseButton.Right); + + return new List + { + new InputState + { + Mouse = new ReplayMouseState(ToScreenSpace(position ?? Vector2.Zero), buttons), + Keyboard = new ReplayKeyboardState(new List()) + } + }; + } + + public bool AtLastFrame => currentFrameIndex == Frames.Count - 1; + public bool AtFirstFrame => currentFrameIndex == 0; + + public Vector2 Size => new Vector2(512, 384); + + private const double sixty_frame_time = 1000.0 / 60; + + private double currentTime; + private int currentDirection; + + /// + /// When set, we will ensure frames executed by nested drawables are frame-accurate to replay data. + /// Disabling this can make replay playback smoother (useful for autoplay, currently). + /// + public bool FrameAccuratePlayback = true; + + private bool hasFrames => Frames.Count > 0; + + private bool inImportantSection => + FrameAccuratePlayback && + //a button is in a pressed state + ((currentDirection > 0 ? CurrentFrame : NextFrame)?.IsImportant ?? false) && + //the next frame is within an allowable time span + Math.Abs(currentTime - NextFrame?.Time ?? 0) <= sixty_frame_time * 1.2; + + /// + /// Update the current frame based on an incoming time value. + /// There are cases where we return a "must-use" time value that is different from the input. + /// This is to ensure accurate playback of replay data. + /// + /// The time which we should use for finding the current frame. + /// The usable time value. If null, we should not advance time as we do not have enough data. + public override double? SetFrameFromTime(double time) + { + currentDirection = time.CompareTo(currentTime); + if (currentDirection == 0) currentDirection = 1; + + if (hasFrames) + { + //if we changed frames, we want to execute once *exactly* on the frame's time. + 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. + if (inImportantSection) + return null; + } + + return currentTime = time; + } + + protected class ReplayMouseState : MouseState + { + public ReplayMouseState(Vector2 position, IEnumerable list) + { + Position = position; + list.ForEach(b => PressedButtons.Add(b)); + } + } + + protected class ReplayKeyboardState : KeyboardState + { + public ReplayKeyboardState(List keys) + { + Keys = keys; + } + } + } +} \ No newline at end of file diff --git a/osu.Game/Modes/Replays/Replay.cs b/osu.Game/Modes/Replays/Replay.cs new file mode 100644 index 0000000000..62f60358e0 --- /dev/null +++ b/osu.Game/Modes/Replays/Replay.cs @@ -0,0 +1,12 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System.Collections.Generic; + +namespace osu.Game.Modes.Replays +{ + public class Replay + { + public List Frames = new List(); + } +} \ No newline at end of file diff --git a/osu.Game/Modes/Replays/ReplayButtonState.cs b/osu.Game/Modes/Replays/ReplayButtonState.cs new file mode 100644 index 0000000000..d49139226c --- /dev/null +++ b/osu.Game/Modes/Replays/ReplayButtonState.cs @@ -0,0 +1,18 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; + +namespace osu.Game.Modes.Replays +{ + [Flags] + public enum ReplayButtonState + { + None = 0, + Left1 = 1, + Right1 = 2, + Left2 = 4, + Right2 = 8, + Smoke = 16 + } +} \ No newline at end of file diff --git a/osu.Game/Modes/Replays/ReplayFrame.cs b/osu.Game/Modes/Replays/ReplayFrame.cs new file mode 100644 index 0000000000..4cd681beaf --- /dev/null +++ b/osu.Game/Modes/Replays/ReplayFrame.cs @@ -0,0 +1,71 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; + +namespace osu.Game.Modes.Replays +{ + public class ReplayFrame + { + public Vector2 Position => new Vector2(MouseX, MouseY); + + public bool IsImportant => MouseLeft || MouseRight; + + public float MouseX; + public float MouseY; + + public bool MouseLeft => MouseLeft1 || MouseLeft2; + public bool MouseRight => MouseRight1 || MouseRight2; + + public bool MouseLeft1 + { + get { return (ButtonState & ReplayButtonState.Left1) > 0; } + set { setButtonState(ReplayButtonState.Left1, value); } + } + public bool MouseRight1 + { + get { return (ButtonState & ReplayButtonState.Right1) > 0; } + set { setButtonState(ReplayButtonState.Right1, value); } + } + public bool MouseLeft2 + { + get { return (ButtonState & ReplayButtonState.Left2) > 0; } + set { setButtonState(ReplayButtonState.Left2, value); } + } + public bool MouseRight2 + { + get { return (ButtonState & ReplayButtonState.Right2) > 0; } + set { setButtonState(ReplayButtonState.Right2, value); } + } + + private void setButtonState(ReplayButtonState singleButton, bool pressed) + { + if (pressed) + ButtonState |= singleButton; + else + ButtonState &= ~singleButton; + } + + public double Time; + + public ReplayButtonState ButtonState; + + protected ReplayFrame() + { + + } + + public ReplayFrame(double time, float posX, float posY, ReplayButtonState buttonState) + { + MouseX = posX; + MouseY = posY; + ButtonState = buttonState; + Time = time; + } + + public override string ToString() + { + return $"{Time}\t({MouseX},{MouseY})\t{MouseLeft}\t{MouseRight}\t{MouseLeft1}\t{MouseRight1}\t{MouseLeft2}\t{MouseRight2}\t{ButtonState}"; + } + } +} \ No newline at end of file diff --git a/osu.Game/Modes/Scoring/Score.cs b/osu.Game/Modes/Scoring/Score.cs index 75c243278d..c998b11f77 100644 --- a/osu.Game/Modes/Scoring/Score.cs +++ b/osu.Game/Modes/Scoring/Score.cs @@ -2,11 +2,13 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Collections.Generic; using Newtonsoft.Json; using osu.Game.Database; using osu.Game.Modes.Mods; using osu.Game.Users; using System.IO; +using osu.Game.Modes.Replays; namespace osu.Game.Modes.Scoring { @@ -45,11 +47,34 @@ namespace osu.Game.Modes.Scoring public DateTime Date; /// - /// Creates a legacy replay which is read from a stream. + /// Creates a replay which is read from a stream. /// /// The stream reader. /// The replay. - public virtual Replay CreateLegacyReplayFrom(StreamReader reader) => new LegacyReplay(reader); + public virtual Replay CreateReplay(StreamReader reader) + { + var frames = new List(); + + float lastTime = 0; + + foreach (var l in reader.ReadToEnd().Split(',')) + { + var split = l.Split('|'); + + if (split.Length < 4 || float.Parse(split[0]) < 0) continue; + + lastTime += float.Parse(split[0]); + + frames.Add(new ReplayFrame( + lastTime, + float.Parse(split[1]), + 384 - float.Parse(split[2]), + (ReplayButtonState)int.Parse(split[3]) + )); + } + + return new Replay { Frames = frames }; + } // [JsonProperty(@"count50")] 0, //[JsonProperty(@"count100")] 0, diff --git a/osu.Game/Modes/Scoring/ScoreProcessor.cs b/osu.Game/Modes/Scoring/ScoreProcessor.cs index 393d651dbf..a64b4d4013 100644 --- a/osu.Game/Modes/Scoring/ScoreProcessor.cs +++ b/osu.Game/Modes/Scoring/ScoreProcessor.cs @@ -141,11 +141,17 @@ namespace osu.Game.Modes.Scoring /// The judgement to add. protected void AddJudgement(TJudgement judgement) { - Judgements.Add(judgement); + bool exists = Judgements.Contains(judgement); - OnNewJugement(judgement); + if (!exists) + { + Judgements.Add(judgement); + OnNewJudgement(judgement); - judgement.ComboAtHit = (ulong)Combo.Value; + judgement.ComboAtHit = Combo.Value; + } + else + OnJudgementChanged(judgement); UpdateFailed(); } @@ -158,9 +164,21 @@ namespace osu.Game.Modes.Scoring } /// - /// Update any values that potentially need post-processing on a judgement change. + /// Updates any values that need post-processing. Invoked when a new judgement has occurred. + /// + /// This is not triggered when existing judgements are changed - for that see . + /// /// /// The judgement that triggered this calculation. - protected abstract void OnNewJugement(TJudgement judgement); + protected abstract void OnNewJudgement(TJudgement judgement); + + /// + /// Updates any values that need post-processing. Invoked when an existing judgement has changed. + /// + /// This is not triggered when a new judgement has occurred - for that see . + /// + /// + /// The judgement that triggered this calculation. + protected virtual void OnJudgementChanged(TJudgement judgement) { } } } \ No newline at end of file diff --git a/osu.Game/Modes/UI/HitRenderer.cs b/osu.Game/Modes/UI/HitRenderer.cs index 3d108b895d..e36d2a101c 100644 --- a/osu.Game/Modes/UI/HitRenderer.cs +++ b/osu.Game/Modes/UI/HitRenderer.cs @@ -14,6 +14,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using osu.Game.Modes.Replays; using osu.Game.Modes.Scoring; namespace osu.Game.Modes.UI @@ -68,6 +69,14 @@ namespace osu.Game.Modes.UI /// /// The input manager. protected virtual KeyConversionInputManager CreateKeyConversionInputManager() => new KeyConversionInputManager(); + + protected virtual FramedReplayInputHandler CreateReplayInputHandler(Replay replay) => new FramedReplayInputHandler(replay); + + /// + /// Sets a replay to be used, overriding local input. + /// + /// The replay, null for local input. + public void SetReplay(Replay replay) => InputManager.ReplayInputHandler = replay != null ? CreateReplayInputHandler(replay) : null; } /// @@ -149,7 +158,7 @@ namespace osu.Game.Modes.UI public event Action OnJudgement; protected override Container Content => content; - protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result.HasValue); + protected override bool AllObjectsJudged => Playfield.HitObjects.Children.All(h => h.Judgement.Result != HitResult.None); /// /// The playfield. diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 66196670b8..8ac86c5c67 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -125,7 +125,7 @@ namespace osu.Game Beatmap.Value = BeatmapDatabase.GetWorkingBeatmap(s.Beatmap); - menu.Push(new PlayerLoader(new Player { ReplayInputHandler = s.Replay.CreateInputHandler() })); + menu.Push(new PlayerLoader(new ReplayPlayer(s.Replay))); } protected override void LoadComplete() diff --git a/osu.Game/Screens/Play/Player.cs b/osu.Game/Screens/Play/Player.cs index 0554c0e77b..73d397b24b 100644 --- a/osu.Game/Screens/Play/Player.cs +++ b/osu.Game/Screens/Play/Player.cs @@ -15,7 +15,6 @@ using osu.Framework.Screens; using osu.Framework.Timing; using osu.Game.Configuration; using osu.Game.Database; -using osu.Game.Input.Handlers; using osu.Game.Modes; using osu.Game.Modes.UI; using osu.Game.Screens.Backgrounds; @@ -34,7 +33,7 @@ namespace osu.Game.Screens.Play internal override bool HasLocalCursorDisplayed => !hasReplayLoaded && !IsPaused; - private bool hasReplayLoaded => hitRenderer.InputManager.ReplayInputHandler != null; + private bool hasReplayLoaded => HitRenderer.InputManager.ReplayInputHandler != null; public BeatmapInfo BeatmapInfo; @@ -53,7 +52,7 @@ namespace osu.Game.Screens.Play private Ruleset ruleset; private ScoreProcessor scoreProcessor; - private HitRenderer hitRenderer; + protected HitRenderer HitRenderer; private Bindable dimLevel; private SkipButton skipButton; @@ -112,9 +111,9 @@ namespace osu.Game.Screens.Play }); ruleset = Ruleset.GetRuleset(Beatmap.PlayMode); - hitRenderer = ruleset.CreateHitRendererWith(Beatmap); + HitRenderer = ruleset.CreateHitRendererWith(Beatmap); - scoreProcessor = hitRenderer.CreateScoreProcessor(); + scoreProcessor = HitRenderer.CreateScoreProcessor(); hudOverlay = new StandardHudOverlay(); hudOverlay.KeyCounter.Add(ruleset.CreateGameplayKeys()); @@ -133,13 +132,10 @@ namespace osu.Game.Screens.Play }; - if (ReplayInputHandler != null) - hitRenderer.InputManager.ReplayInputHandler = ReplayInputHandler; - - hudOverlay.BindHitRenderer(hitRenderer); + hudOverlay.BindHitRenderer(HitRenderer); //bind HitRenderer to ScoreProcessor and ourselves (for a pass situation) - hitRenderer.OnAllJudged += onCompletion; + HitRenderer.OnAllJudged += onCompletion; //bind ScoreProcessor to ourselves (for a fail situation) scoreProcessor.Failed += onFail; @@ -152,7 +148,7 @@ namespace osu.Game.Screens.Play Clock = interpolatedSourceClock, Children = new Drawable[] { - hitRenderer, + HitRenderer, skipButton = new SkipButton { Alpha = 0 @@ -336,8 +332,6 @@ namespace osu.Game.Screens.Play private Bindable mouseWheelDisabled; - public ReplayInputHandler ReplayInputHandler; - protected override bool OnWheel(InputState state) => mouseWheelDisabled.Value && !IsPaused; } } \ No newline at end of file diff --git a/osu.Game/Screens/Play/ReplayPlayer.cs b/osu.Game/Screens/Play/ReplayPlayer.cs new file mode 100644 index 0000000000..4593656a2e --- /dev/null +++ b/osu.Game/Screens/Play/ReplayPlayer.cs @@ -0,0 +1,23 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Modes.Replays; + +namespace osu.Game.Screens.Play +{ + public class ReplayPlayer : Player + { + public Replay Replay; + + public ReplayPlayer(Replay replay) + { + Replay = replay; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + HitRenderer.SetReplay(Replay); + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 00c189d01c..ecb3f5084c 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -82,7 +82,7 @@ - + @@ -98,8 +98,10 @@ + - + + @@ -125,7 +127,8 @@ - + + @@ -200,6 +203,7 @@ +