diff --git a/osu.Game.Modes.Osu/Beatmaps/OsuBeatmapProcessor.cs b/osu.Game.Modes.Osu/Beatmaps/OsuBeatmapProcessor.cs index 1f7785f174..08c9d94141 100644 --- a/osu.Game.Modes.Osu/Beatmaps/OsuBeatmapProcessor.cs +++ b/osu.Game.Modes.Osu/Beatmaps/OsuBeatmapProcessor.cs @@ -8,11 +8,6 @@ namespace osu.Game.Modes.Osu.Beatmaps { internal class OsuBeatmapProcessor : IBeatmapProcessor { - public void SetDefaults(OsuHitObject hitObject, Beatmap beatmap) - { - hitObject.SetDefaultsFromBeatmap(beatmap); - } - public void PostProcess(Beatmap beatmap) { if (beatmap.ComboColors.Count == 0) diff --git a/osu.Game.Modes.Osu/Objects/OsuHitObject.cs b/osu.Game.Modes.Osu/Objects/OsuHitObject.cs index cee55a281c..42313a7e71 100644 --- a/osu.Game.Modes.Osu/Objects/OsuHitObject.cs +++ b/osu.Game.Modes.Osu/Objects/OsuHitObject.cs @@ -3,7 +3,6 @@ using osu.Game.Modes.Objects; using OpenTK; -using osu.Game.Beatmaps; using osu.Game.Modes.Osu.Objects.Drawables; using osu.Game.Modes.Objects.Types; using OpenTK.Graphics; @@ -67,9 +66,11 @@ namespace osu.Game.Modes.Osu.Objects return OsuScoreResult.Miss; } - public virtual void SetDefaultsFromBeatmap(Beatmap beatmap) + public override void ApplyDefaults(HitObjectDefaults defaults) { - Scale = (1.0f - 0.7f * (beatmap.BeatmapInfo.Difficulty.CircleSize - 5) / 5) / 2; + base.ApplyDefaults(defaults); + + Scale = (1.0f - 0.7f * (defaults.Difficulty.CircleSize - 5) / 5) / 2; } } } diff --git a/osu.Game.Modes.Osu/Objects/Slider.cs b/osu.Game.Modes.Osu/Objects/Slider.cs index fdf3658d44..35883ff131 100644 --- a/osu.Game.Modes.Osu/Objects/Slider.cs +++ b/osu.Game.Modes.Osu/Objects/Slider.cs @@ -2,7 +2,6 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using OpenTK; -using osu.Game.Beatmaps; using osu.Game.Beatmaps.Samples; using osu.Game.Beatmaps.Timing; using osu.Game.Modes.Objects.Types; @@ -47,19 +46,17 @@ namespace osu.Game.Modes.Osu.Objects public double Velocity; public double TickDistance; - public override void SetDefaultsFromBeatmap(Beatmap beatmap) + public override void ApplyDefaults(HitObjectDefaults defaults) { - base.SetDefaultsFromBeatmap(beatmap); - - var baseDifficulty = beatmap.BeatmapInfo.Difficulty; + base.ApplyDefaults(defaults); ControlPoint overridePoint; - ControlPoint timingPoint = beatmap.TimingInfo.TimingPointAt(StartTime, out overridePoint); + ControlPoint timingPoint = defaults.Timing.TimingPointAt(StartTime, out overridePoint); var velocityAdjustment = overridePoint?.VelocityAdjustment ?? 1; - var baseVelocity = 100 * baseDifficulty.SliderMultiplier / velocityAdjustment; + var baseVelocity = 100 * defaults.Difficulty.SliderMultiplier / velocityAdjustment; Velocity = baseVelocity / timingPoint.BeatLength; - TickDistance = baseVelocity / baseDifficulty.SliderTickRate; + TickDistance = baseVelocity / defaults.Difficulty.SliderTickRate; } public IEnumerable Ticks diff --git a/osu.Game/Beatmaps/IBeatmapProcessor.cs b/osu.Game/Beatmaps/IBeatmapProcessor.cs index 3773f69279..9157a760b1 100644 --- a/osu.Game/Beatmaps/IBeatmapProcessor.cs +++ b/osu.Game/Beatmaps/IBeatmapProcessor.cs @@ -8,17 +8,10 @@ namespace osu.Game.Beatmaps /// /// Processes a post-converted Beatmap. /// - /// The type of HitObject contained in the Beatmap. - public interface IBeatmapProcessor - where T : HitObject + /// The type of HitObject contained in the Beatmap. + public interface IBeatmapProcessor + where TObject : HitObject { - /// - /// Sets default values for a HitObject. - /// - /// The HitObject to set default values for. - /// The Beatmap to extract the default values from. - void SetDefaults(T hitObject, Beatmap beatmap); - /// /// Post-processes a Beatmap to add mode-specific components that aren't added during conversion. /// @@ -26,6 +19,6 @@ namespace osu.Game.Beatmaps /// /// /// The Beatmap to process. - void PostProcess(Beatmap beatmap); + void PostProcess(Beatmap beatmap); } } diff --git a/osu.Game/Modes/Objects/HitObject.cs b/osu.Game/Modes/Objects/HitObject.cs index e43702e2da..94e1f88b7f 100644 --- a/osu.Game/Modes/Objects/HitObject.cs +++ b/osu.Game/Modes/Objects/HitObject.cs @@ -22,5 +22,11 @@ namespace osu.Game.Modes.Objects /// The sample to be played when this HitObject is hit. /// public HitSampleInfo Sample { get; set; } + + /// + /// Applies default values to this HitObject. + /// + /// The default values to apply. + public virtual void ApplyDefaults(HitObjectDefaults defaults) { } } } diff --git a/osu.Game/Modes/Objects/HitObjectDefaults.cs b/osu.Game/Modes/Objects/HitObjectDefaults.cs new file mode 100644 index 0000000000..7a0d64391e --- /dev/null +++ b/osu.Game/Modes/Objects/HitObjectDefaults.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.Beatmaps; +using osu.Game.Beatmaps.Timing; +using osu.Game.Database; + +namespace osu.Game.Modes.Objects +{ + /// + /// A set of default Beatmap values for HitObjects to consume. + /// + public class HitObjectDefaults + { + /// + /// The Beatmap timing. + /// + public TimingInfo Timing; + + /// + /// The Beatmap difficulty. + /// + public BaseDifficulty Difficulty; + } +} diff --git a/osu.Game/Modes/UI/HitRenderer.cs b/osu.Game/Modes/UI/HitRenderer.cs index a0ca2549c0..da47bf2c67 100644 --- a/osu.Game/Modes/UI/HitRenderer.cs +++ b/osu.Game/Modes/UI/HitRenderer.cs @@ -9,6 +9,7 @@ using osu.Game.Modes.Judgements; using osu.Game.Modes.Mods; using osu.Game.Modes.Objects; using osu.Game.Modes.Objects.Drawables; +using osu.Game.Modes.Objects.Types; using osu.Game.Screens.Play; using System; using System.Collections.Generic; @@ -86,16 +87,32 @@ namespace osu.Game.Modes.UI { Debug.Assert(beatmap != null, "HitRenderer initialized with a null beatmap."); - // Convert + process the beatmap - Beatmap = CreateBeatmapConverter().Convert(beatmap.Beatmap); - Beatmap.HitObjects.ForEach(h => CreateBeatmapProcessor().SetDefaults(h, Beatmap)); - CreateBeatmapProcessor().PostProcess(Beatmap); - - applyMods(beatmap.Mods.Value); - RelativeSizeAxes = Axes.Both; + + IBeatmapConverter converter = CreateBeatmapConverter(); + IBeatmapProcessor processor = CreateBeatmapProcessor(); + + // Convert the beatmap + Beatmap = converter.Convert(beatmap.Beatmap); + + // Apply defaults + HitObjectDefaults defaults = new HitObjectDefaults + { + Timing = Beatmap.TimingInfo, + Difficulty = Beatmap.BeatmapInfo.BaseDifficulty + }; + + foreach (var h in Beatmap.HitObjects) + h.ApplyDefaults(defaults); + + // Post-process the beatmap + processor.PostProcess(Beatmap); + + // Add mods, should always be the last thing applied to give full control to mods + applyMods(beatmap.Mods.Value); } + /// /// Applies the active mods to this HitRenderer. /// diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 80d5c906e0..d7370078ed 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -100,6 +100,7 @@ +