diff --git a/osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs b/osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs index 1e3d8df6c6..f82ea1c98c 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs @@ -37,7 +37,7 @@ namespace osu.Desktop.VisualTests.Tests playbackSpeed.ValueChanged += delegate { rateAdjustClock.Rate = playbackSpeed.Value; }; } - HitObjectType mode = HitObjectType.Spinner; + HitObjectType mode = HitObjectType.Slider; BindableNumber playbackSpeed = new BindableDouble(0.5) { MinValue = 0, MaxValue = 1 }; private Container playfieldContainer; @@ -75,6 +75,7 @@ namespace osu.Desktop.VisualTests.Tests Length = 400, Position = new Vector2(-200, 0), Velocity = 1, + TickDistance = 100, })); break; case HitObjectType.Spinner: diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs index 208bf15328..0e085d63b8 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableHitCircle.cs @@ -84,18 +84,18 @@ namespace osu.Game.Modes.Osu.Objects.Drawables double hitOffset = Math.Abs(Judgement.TimeOffset); + OsuJudgementInfo osuJudgement = Judgement as OsuJudgementInfo; + if (hitOffset < hit50) { Judgement.Result = HitResult.Hit; - OsuJudgementInfo osuInfo = Judgement as OsuJudgementInfo; - if (hitOffset < hit300) - osuInfo.Score = OsuScoreResult.Hit300; + osuJudgement.Score = OsuScoreResult.Hit300; else if (hitOffset < hit100) - osuInfo.Score = OsuScoreResult.Hit100; + osuJudgement.Score = OsuScoreResult.Hit100; else if (hitOffset < hit50) - osuInfo.Score = OsuScoreResult.Hit50; + osuJudgement.Score = OsuScoreResult.Hit50; } else Judgement.Result = HitResult.Miss; diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs index ef153848d4..c7cc7cfdd7 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableOsuHitObject.cs @@ -4,7 +4,6 @@ using System.ComponentModel; using osu.Game.Modes.Objects; using osu.Game.Modes.Objects.Drawables; -using osu.Framework.Graphics; namespace osu.Game.Modes.Osu.Objects.Drawables { @@ -19,7 +18,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables { } - public override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo(); + public override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo { MaxScore = OsuScoreResult.Hit300 }; protected override void UpdateState(ArmedState state) { @@ -49,7 +48,37 @@ namespace osu.Game.Modes.Osu.Objects.Drawables public class OsuJudgementInfo : PositionalJudgementInfo { + /// + /// The score the user achieved. + /// public OsuScoreResult Score; + + /// + /// The score which would be achievable on a perfect hit. + /// + public OsuScoreResult MaxScore = OsuScoreResult.Hit300; + + public int ScoreValue => scoreToInt(Score); + + public int MaxScoreValue => scoreToInt(MaxScore); + + private int scoreToInt(OsuScoreResult result) + { + switch (result) + { + default: + return 0; + case OsuScoreResult.Hit50: + return 50; + case OsuScoreResult.Hit100: + return 100; + case OsuScoreResult.Hit300: + return 300; + case OsuScoreResult.SliderTick: + return 10; + } + } + public ComboResult Combo; } @@ -73,5 +102,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables Hit100, [Description(@"300")] Hit300, + [Description(@"10")] + SliderTick } } diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs index 6c4e1fec78..745c696fee 100644 --- a/osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs @@ -1,11 +1,13 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE -using System.Collections.Generic; +using OpenTK; using osu.Framework.Graphics; using osu.Game.Modes.Objects.Drawables; using osu.Game.Modes.Osu.Objects.Drawables.Pieces; -using OpenTK; +using System.Collections.Generic; +using System.Linq; +using osu.Framework.Graphics.Containers; namespace osu.Game.Modes.Osu.Objects.Drawables { @@ -17,6 +19,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables private List components = new List(); + private Container ticks; + SliderBody body; SliderBall ball; @@ -33,6 +37,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables Position = s.StackedPosition, PathWidth = s.Scale * 64, }, + ticks = new Container(), bouncer1 = new SliderBouncer(s, false) { Position = s.Curve.PositionAt(1), @@ -63,6 +68,26 @@ namespace osu.Game.Modes.Osu.Objects.Drawables components.Add(ball); components.Add(bouncer1); components.Add(bouncer2); + + AddNested(initialCircle); + + var repeatDuration = s.Curve.Length / s.Velocity; + foreach (var tick in s.Ticks) + { + var repeatStartTime = s.StartTime + tick.RepeatIndex * repeatDuration; + var fadeInTime = repeatStartTime + (tick.StartTime - repeatStartTime) / 2 - (tick.RepeatIndex == 0 ? TIME_FADEIN : TIME_FADEIN / 2); + var fadeOutTime = repeatStartTime + repeatDuration; + + var drawableTick = new DrawableSliderTick(tick) + { + FadeInTime = fadeInTime, + FadeOutTime = fadeOutTime, + Position = tick.Position, + }; + + ticks.Add(drawableTick); + AddNested(drawableTick); + } } // Since the DrawableSlider itself is just a container without a size we need to @@ -96,7 +121,8 @@ namespace osu.Game.Modes.Osu.Objects.Drawables if (initialCircle.Judgement?.Result != HitResult.Hit) initialCircle.Position = slider.Curve.PositionAt(progress); - components.ForEach(c => c.UpdateProgress(progress, repeat)); + foreach (var c in components) c.UpdateProgress(progress, repeat); + foreach (var t in ticks.Children) t.Tracking = ball.Tracking; } protected override void CheckJudgement(bool userTriggered) @@ -106,8 +132,22 @@ namespace osu.Game.Modes.Osu.Objects.Drawables if (!userTriggered && Time.Current >= HitObject.EndTime) { - j.Score = sc.Score; - j.Result = sc.Result; + var ticksCount = ticks.Children.Count() + 1; + var ticksHit = ticks.Children.Count(t => t.Judgement.Result == HitResult.Hit); + if (sc.Result == HitResult.Hit) + ticksHit++; + + var hitFraction = (double)ticksHit / ticksCount; + if (hitFraction == 1 && sc.Score == OsuScoreResult.Hit300) + j.Score = OsuScoreResult.Hit300; + else if (hitFraction >= 0.5 && sc.Score >= OsuScoreResult.Hit100) + j.Score = OsuScoreResult.Hit100; + else if (hitFraction > 0) + j.Score = OsuScoreResult.Hit50; + else + j.Score = OsuScoreResult.Miss; + + j.Result = j.Score != OsuScoreResult.Miss ? HitResult.Hit : HitResult.Miss; } } diff --git a/osu.Game.Modes.Osu/Objects/Drawables/DrawableSliderTick.cs b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSliderTick.cs new file mode 100644 index 0000000000..7380871583 --- /dev/null +++ b/osu.Game.Modes.Osu/Objects/Drawables/DrawableSliderTick.cs @@ -0,0 +1,120 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Framework.Allocation; +using osu.Framework.Audio; +using osu.Framework.Audio.Sample; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Transformations; +using osu.Game.Beatmaps.Samples; +using osu.Game.Modes.Objects.Drawables; +using OpenTK; +using OpenTK.Graphics; + +namespace osu.Game.Modes.Osu.Objects.Drawables +{ + public class DrawableSliderTick : DrawableOsuHitObject + { + private SliderTick sliderTick; + + public double FadeInTime; + public double FadeOutTime; + + public bool Tracking; + + public override bool RemoveWhenNotAlive => false; + + public override JudgementInfo CreateJudgementInfo() => new OsuJudgementInfo { MaxScore = OsuScoreResult.SliderTick }; + + public DrawableSliderTick(SliderTick sliderTick) : base(sliderTick) + { + this.sliderTick = sliderTick; + + Size = new Vector2(16) * sliderTick.Scale; + + Masking = true; + CornerRadius = Size.X / 2; + + Origin = Anchor.Centre; + + BorderThickness = 2; + BorderColour = Color4.White; + + Children = new Drawable[] + { + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = sliderTick.Colour, + Alpha = 0.3f, + } + }; + } + + private AudioSample sample; + + [BackgroundDependencyLoader] + private void load(AudioManager audio) + { + string sampleSet = (HitObject.Sample?.Set ?? SampleSet.Normal).ToString().ToLower(); + + sample = audio.Sample.Get($@"Gameplay/{sampleSet}-slidertick"); + } + + protected override void PlaySample() + { + sample?.Play(); + } + + + protected override void CheckJudgement(bool userTriggered) + { + var j = Judgement as OsuJudgementInfo; + + if (Judgement.TimeOffset >= 0) + { + j.Result = Tracking ? HitResult.Hit : HitResult.Miss; + j.Score = Tracking ? OsuScoreResult.SliderTick : OsuScoreResult.Miss; + } + } + + protected override void UpdatePreemptState() + { + var animIn = Math.Min(150, sliderTick.StartTime - FadeInTime); + + ScaleTo(0.5f); + ScaleTo(1.2f, animIn); + FadeIn(animIn); + + Delay(animIn); + ScaleTo(1, 150, EasingTypes.Out); + + Delay(-animIn); + } + + protected override void UpdateState(ArmedState state) + { + if (!IsLoaded) return; + + base.UpdateState(state); + + switch (state) + { + case ArmedState.Idle: + Delay(FadeOutTime - sliderTick.StartTime); + FadeOut(); + break; + case ArmedState.Miss: + FadeOut(160); + FadeColour(Color4.Red, 80); + break; + case ArmedState.Hit: + FadeOut(120, EasingTypes.OutQuint); + ScaleTo(Scale * 1.5f, 120, EasingTypes.OutQuint); + break; + } + } + } +} \ No newline at end of file diff --git a/osu.Game.Modes.Osu/Objects/Slider.cs b/osu.Game.Modes.Osu/Objects/Slider.cs index 8479d69669..c3d8190240 100644 --- a/osu.Game.Modes.Osu/Objects/Slider.cs +++ b/osu.Game.Modes.Osu/Objects/Slider.cs @@ -1,9 +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; -using osu.Game.Beatmaps; using OpenTK; +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.Samples; +using osu.Game.Beatmaps.Timing; +using System; +using System.Collections.Generic; namespace osu.Game.Modes.Osu.Objects { @@ -43,17 +46,70 @@ namespace osu.Game.Modes.Osu.Objects } public double Velocity; + public double TickDistance; public override void SetDefaultsFromBeatmap(Beatmap beatmap) { base.SetDefaultsFromBeatmap(beatmap); - Velocity = 100 / beatmap.BeatLengthAt(StartTime, true) * beatmap.BeatmapInfo.BaseDifficulty.SliderMultiplier; + var baseDifficulty = beatmap.BeatmapInfo.BaseDifficulty; + + ControlPoint overridePoint; + ControlPoint timingPoint = beatmap.TimingPointAt(StartTime, out overridePoint); + var velocityAdjustment = overridePoint?.VelocityAdjustment ?? 1; + var baseVelocity = 100 * baseDifficulty.SliderMultiplier; + + Velocity = baseVelocity / (timingPoint.BeatLength * velocityAdjustment); + TickDistance = baseVelocity / (baseDifficulty.SliderTickRate * velocityAdjustment); } public int RepeatCount = 1; internal readonly SliderCurve Curve = new SliderCurve(); + + public IEnumerable Ticks + { + get + { + if (TickDistance == 0) yield break; + + var length = Curve.Length; + var tickDistance = Math.Min(TickDistance, length); + var repeatDuration = length / Velocity; + + var minDistanceFromEnd = Velocity * 0.01; + + for (var repeat = 0; repeat < RepeatCount; repeat++) + { + var repeatStartTime = StartTime + repeat * repeatDuration; + var reversed = repeat % 2 == 1; + + for (var d = tickDistance; d <= length; d += tickDistance) + { + if (d > length - minDistanceFromEnd) + break; + + var distanceProgress = d / length; + var timeProgress = reversed ? 1 - distanceProgress : distanceProgress; + + yield return new SliderTick + { + RepeatIndex = repeat, + StartTime = repeatStartTime + timeProgress * repeatDuration, + Position = Curve.PositionAt(distanceProgress), + StackHeight = StackHeight, + Scale = Scale, + Colour = Colour, + Sample = new HitSampleInfo + { + Type = SampleType.None, + Set = SampleSet.Soft, + }, + }; + } + } + } + } } public enum CurveTypes diff --git a/osu.Game.Modes.Osu/Objects/SliderTick.cs b/osu.Game.Modes.Osu/Objects/SliderTick.cs new file mode 100644 index 0000000000..de8f3f4b6f --- /dev/null +++ b/osu.Game.Modes.Osu/Objects/SliderTick.cs @@ -0,0 +1,9 @@ +using OpenTK; + +namespace osu.Game.Modes.Osu.Objects +{ + public class SliderTick : OsuHitObject + { + public int RepeatIndex { get; set; } + } +} diff --git a/osu.Game.Modes.Osu/OsuScoreProcessor.cs b/osu.Game.Modes.Osu/OsuScoreProcessor.cs index 8a9f7d6b2e..9493259558 100644 --- a/osu.Game.Modes.Osu/OsuScoreProcessor.cs +++ b/osu.Game.Modes.Osu/OsuScoreProcessor.cs @@ -36,24 +36,8 @@ namespace osu.Game.Modes.Osu foreach (OsuJudgementInfo j in Judgements) { - switch (j.Score) - { - case OsuScoreResult.Miss: - maxScore += 300; - break; - case OsuScoreResult.Hit50: - score += 50; - maxScore += 300; - break; - case OsuScoreResult.Hit100: - score += 100; - maxScore += 300; - break; - case OsuScoreResult.Hit300: - score += 300; - maxScore += 300; - break; - } + score += j.ScoreValue; + maxScore += j.MaxScoreValue; } TotalScore.Value = score; diff --git a/osu.Game.Modes.Osu/osu.Game.Modes.Osu.csproj b/osu.Game.Modes.Osu/osu.Game.Modes.Osu.csproj index 82c5537597..1b1ded3d61 100644 --- a/osu.Game.Modes.Osu/osu.Game.Modes.Osu.csproj +++ b/osu.Game.Modes.Osu/osu.Game.Modes.Osu.csproj @@ -59,6 +59,7 @@ + @@ -67,6 +68,7 @@ + diff --git a/osu.Game/Beatmaps/Beatmap.cs b/osu.Game/Beatmaps/Beatmap.cs index 0914d1a2ad..d0ce290bad 100644 --- a/osu.Game/Beatmaps/Beatmap.cs +++ b/osu.Game/Beatmaps/Beatmap.cs @@ -26,26 +26,31 @@ namespace osu.Game.Beatmaps return 60000 / BeatLengthAt(time); } - public double BeatLengthAt(double time, bool applyMultipliers = false) + public double BeatLengthAt(double time) { - int point = 0; - int samplePoint = 0; + ControlPoint overridePoint; + ControlPoint timingPoint = TimingPointAt(time, out overridePoint); + return timingPoint.BeatLength; + } - for (int i = 0; i < ControlPoints.Count; i++) - if (ControlPoints[i].Time <= time) + public ControlPoint TimingPointAt(double time, out ControlPoint overridePoint) + { + overridePoint = null; + + ControlPoint timingPoint = null; + foreach (var controlPoint in ControlPoints) + if (controlPoint.Time <= time) { - if (ControlPoints[i].TimingChange) - point = i; - else - samplePoint = i; + if (controlPoint.TimingChange) + { + timingPoint = controlPoint; + overridePoint = null; + } + else overridePoint = controlPoint; } + else break; - double mult = 1; - - if (applyMultipliers && samplePoint > point) - mult = ControlPoints[samplePoint].VelocityAdjustment; - - return ControlPoints[point].BeatLength * mult; + return timingPoint; } } } diff --git a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs index 4df49ca01f..94369d51aa 100644 --- a/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs +++ b/osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs @@ -2,6 +2,7 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using osu.Framework; @@ -23,8 +24,6 @@ namespace osu.Game.Modes.Objects.Drawables public bool Interactive = true; - public Container ChildObjects; - public JudgementInfo Judgement; public abstract JudgementInfo CreateJudgementInfo(); @@ -66,7 +65,7 @@ namespace osu.Game.Modes.Objects.Drawables sample = audio.Sample.Get($@"Gameplay/{sampleSet}-hit{hitType}"); } - protected void PlaySample() + protected virtual void PlaySample() { sample?.Play(); } @@ -85,6 +84,19 @@ namespace osu.Game.Modes.Objects.Drawables Expire(true); } + private List nestedHitObjects; + + protected IEnumerable NestedHitObjects => nestedHitObjects; + + protected void AddNested(DrawableHitObject h) + { + if (nestedHitObjects == null) + nestedHitObjects = new List(); + + h.OnJudgement += (d, j) => { OnJudgement?.Invoke(d, j); } ; + nestedHitObjects.Add(h); + } + /// /// Process a hit of this hitobject. Carries out judgement. /// @@ -119,7 +131,11 @@ namespace osu.Game.Modes.Objects.Drawables protected virtual void CheckJudgement(bool userTriggered) { - //todo: consider making abstract. + if (NestedHitObjects != null) + { + foreach (var d in NestedHitObjects) + d.CheckJudgement(userTriggered); + } } protected override void UpdateAfterChildren()