From 9ca03c02091a8700776c2eeeeac44dc337f30dea Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 23 Dec 2017 16:46:02 +0900 Subject: [PATCH] Simplify and tidy sample retrieval Less static weirdness --- osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs | 19 ++++++++++--------- osu.Game/Audio/SampleInfo.cs | 11 ----------- .../ControlPoints/ControlPointInfo.cs | 2 +- .../ControlPoints/SampleControlPoint.cs | 14 ++++++++++++++ 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs index 864b0f0ca4..44c7bdb547 100644 --- a/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs +++ b/osu.Game.Rulesets.Taiko/UI/TaikoPlayfield.cs @@ -62,7 +62,7 @@ public class TaikoPlayfield : ScrollingPlayfield, IKeyBindingHandler> allSamples; + private Dictionary> drumSampleMappings; public TaikoPlayfield(ControlPointInfo controlPointInfo) : base(Axes.X) @@ -207,12 +207,12 @@ public TaikoPlayfield(ControlPointInfo controlPointInfo) [BackgroundDependencyLoader] private void load(OsuColour colours, AudioManager audio) { - allSamples = new Dictionary>(); + drumSampleMappings = new Dictionary>(); foreach (var s in controlPointInfo.SamplePoints) { - var normalSample = SampleInfo.FromSoundPoint(s).GetChannel(audio.Sample); - var clapSample = SampleInfo.FromSoundPoint(s, SampleInfo.HIT_CLAP).GetChannel(audio.Sample); - allSamples.Add(s.Time, new Tuple(normalSample, clapSample)); + var normalSample = s.GetSampleInfo().GetChannel(audio.Sample); + var clapSample = s.GetSampleInfo(SampleInfo.HIT_CLAP).GetChannel(audio.Sample); + drumSampleMappings.Add(s, new Tuple(normalSample, clapSample)); } overlayBackgroundContainer.BorderColour = colours.Gray0; @@ -268,7 +268,9 @@ public override void OnJudgement(DrawableHitObject judgedObject, Judgement judge { topLevelHitContainer.Add(judgedObject.CreateProxy()); } - catch { } + catch + { + } } hitExplosionContainer.Add(new HitExplosion(judgedObject, isRim)); @@ -280,10 +282,9 @@ public override void OnJudgement(DrawableHitObject judgedObject, Judgement judge public bool OnPressed(TaikoAction action) { - var currentTime = Clock.CurrentTime; - var soundPoint = currentTime < controlPointInfo.SamplePoints[0].Time ? controlPointInfo.SamplePoints[0] : controlPointInfo.SamplePointAt(currentTime); + var samplePoint = controlPointInfo.SamplePointAt(Clock.CurrentTime); - if (!allSamples.TryGetValue(soundPoint.Time, out Tuple samples)) + if (!drumSampleMappings.TryGetValue(samplePoint, out var samples)) throw new InvalidOperationException("Current sample set not found."); if (action == TaikoAction.LeftCentre || action == TaikoAction.RightCentre) diff --git a/osu.Game/Audio/SampleInfo.cs b/osu.Game/Audio/SampleInfo.cs index 6a95721bd0..566813dd44 100644 --- a/osu.Game/Audio/SampleInfo.cs +++ b/osu.Game/Audio/SampleInfo.cs @@ -5,7 +5,6 @@ using osu.Framework.Audio; using osu.Framework.Audio.Sample; using osu.Framework.Configuration; -using osu.Game.Beatmaps.ControlPoints; namespace osu.Game.Audio { @@ -17,16 +16,6 @@ public class SampleInfo public const string HIT_NORMAL = @"hitnormal"; public const string HIT_CLAP = @"hitclap"; - public static SampleInfo FromSoundPoint(SampleControlPoint samplePoint, string sampleName = HIT_NORMAL) - { - return new SampleInfo - { - Bank = samplePoint.SampleBank, - Name = sampleName, - Volume = samplePoint.SampleVolume, - }; - } - public SampleChannel GetChannel(SampleManager manager) { var channel = manager.Get($"Gameplay/{Bank}-{Name}"); diff --git a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs index e8ec6595bd..f031ebe353 100644 --- a/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs +++ b/osu.Game/Beatmaps/ControlPoints/ControlPointInfo.cs @@ -55,7 +55,7 @@ public class ControlPointInfo /// /// The time to find the sound control point at. /// The sound control point. - public SampleControlPoint SamplePointAt(double time) => binarySearch(SamplePoints, time); + public SampleControlPoint SamplePointAt(double time) => binarySearch(SamplePoints, time, SamplePoints.FirstOrDefault()); /// /// Finds the timing control point that is active at . diff --git a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs index e3d6eede44..40e45da13c 100644 --- a/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs +++ b/osu.Game/Beatmaps/ControlPoints/SampleControlPoint.cs @@ -1,6 +1,8 @@ // Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using osu.Game.Audio; + namespace osu.Game.Beatmaps.ControlPoints { public class SampleControlPoint : ControlPoint @@ -16,5 +18,17 @@ public class SampleControlPoint : ControlPoint /// The default sample volume at this control point. /// public int SampleVolume; + + /// + /// Create a SampleInfo based on the sample settings in this control point. + /// + /// The name of the same. + /// A populated . + public SampleInfo GetSampleInfo(string sampleName = SampleInfo.HIT_NORMAL) => new SampleInfo + { + Bank = SampleBank, + Name = sampleName, + Volume = SampleVolume, + }; } }