From 0c476388204c61798ea9444ca8b356c4c0ba886f Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 16 Mar 2017 16:55:08 +0900 Subject: [PATCH 1/3] Better hit object defaults setting. --- .../Beatmaps/OsuBeatmapProcessor.cs | 5 --- osu.Game.Modes.Osu/Objects/OsuHitObject.cs | 7 +++-- osu.Game.Modes.Osu/Objects/Slider.cs | 13 +++----- osu.Game/Beatmaps/IBeatmapProcessor.cs | 15 +++------ osu.Game/Modes/Objects/HitObject.cs | 6 ++++ osu.Game/Modes/Objects/HitObjectDefaults.cs | 25 +++++++++++++++ osu.Game/Modes/UI/HitRenderer.cs | 31 ++++++++++++++----- osu.Game/osu.Game.csproj | 1 + 8 files changed, 69 insertions(+), 34 deletions(-) create mode 100644 osu.Game/Modes/Objects/HitObjectDefaults.cs 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 @@ + From 9f6f581b6439ebee7c9d96785781b0a6c4745067 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Thu, 16 Mar 2017 17:24:41 +0900 Subject: [PATCH 2/3] Pass through method instead of instantiating object. --- osu.Game.Modes.Osu/Objects/OsuHitObject.cs | 8 ++++--- osu.Game.Modes.Osu/Objects/Slider.cs | 11 ++++----- osu.Game/Modes/Objects/HitObject.cs | 7 ++++-- osu.Game/Modes/Objects/HitObjectDefaults.cs | 25 --------------------- osu.Game/Modes/UI/HitRenderer.cs | 9 +------- osu.Game/osu.Game.csproj | 1 - 6 files changed, 17 insertions(+), 44 deletions(-) delete mode 100644 osu.Game/Modes/Objects/HitObjectDefaults.cs diff --git a/osu.Game.Modes.Osu/Objects/OsuHitObject.cs b/osu.Game.Modes.Osu/Objects/OsuHitObject.cs index 42313a7e71..9648ba9c87 100644 --- a/osu.Game.Modes.Osu/Objects/OsuHitObject.cs +++ b/osu.Game.Modes.Osu/Objects/OsuHitObject.cs @@ -6,6 +6,8 @@ using OpenTK; using osu.Game.Modes.Osu.Objects.Drawables; using osu.Game.Modes.Objects.Types; using OpenTK.Graphics; +using osu.Game.Beatmaps.Timing; +using osu.Game.Database; namespace osu.Game.Modes.Osu.Objects { @@ -66,11 +68,11 @@ namespace osu.Game.Modes.Osu.Objects return OsuScoreResult.Miss; } - public override void ApplyDefaults(HitObjectDefaults defaults) + public override void ApplyDefaults(TimingInfo timing, BaseDifficulty difficulty) { - base.ApplyDefaults(defaults); + base.ApplyDefaults(timing, difficulty); - Scale = (1.0f - 0.7f * (defaults.Difficulty.CircleSize - 5) / 5) / 2; + Scale = (1.0f - 0.7f * (difficulty.CircleSize - 5) / 5) / 2; } } } diff --git a/osu.Game.Modes.Osu/Objects/Slider.cs b/osu.Game.Modes.Osu/Objects/Slider.cs index 35883ff131..baa6e9442d 100644 --- a/osu.Game.Modes.Osu/Objects/Slider.cs +++ b/osu.Game.Modes.Osu/Objects/Slider.cs @@ -8,6 +8,7 @@ using osu.Game.Modes.Objects.Types; using System; using System.Collections.Generic; using osu.Game.Modes.Objects; +using osu.Game.Database; namespace osu.Game.Modes.Osu.Objects { @@ -46,17 +47,17 @@ namespace osu.Game.Modes.Osu.Objects public double Velocity; public double TickDistance; - public override void ApplyDefaults(HitObjectDefaults defaults) + public override void ApplyDefaults(TimingInfo timing, BaseDifficulty difficulty) { - base.ApplyDefaults(defaults); + base.ApplyDefaults(timing, difficulty); ControlPoint overridePoint; - ControlPoint timingPoint = defaults.Timing.TimingPointAt(StartTime, out overridePoint); + ControlPoint timingPoint = timing.TimingPointAt(StartTime, out overridePoint); var velocityAdjustment = overridePoint?.VelocityAdjustment ?? 1; - var baseVelocity = 100 * defaults.Difficulty.SliderMultiplier / velocityAdjustment; + var baseVelocity = 100 * difficulty.SliderMultiplier / velocityAdjustment; Velocity = baseVelocity / timingPoint.BeatLength; - TickDistance = baseVelocity / defaults.Difficulty.SliderTickRate; + TickDistance = baseVelocity / difficulty.SliderTickRate; } public IEnumerable Ticks diff --git a/osu.Game/Modes/Objects/HitObject.cs b/osu.Game/Modes/Objects/HitObject.cs index 94e1f88b7f..7fe30ff1ac 100644 --- a/osu.Game/Modes/Objects/HitObject.cs +++ b/osu.Game/Modes/Objects/HitObject.cs @@ -2,6 +2,8 @@ // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using osu.Game.Beatmaps.Samples; +using osu.Game.Beatmaps.Timing; +using osu.Game.Database; namespace osu.Game.Modes.Objects { @@ -26,7 +28,8 @@ namespace osu.Game.Modes.Objects /// /// Applies default values to this HitObject. /// - /// The default values to apply. - public virtual void ApplyDefaults(HitObjectDefaults defaults) { } + /// The difficulty settings to use. + /// The timing settings to use. + public virtual void ApplyDefaults(TimingInfo timing, BaseDifficulty difficulty) { } } } diff --git a/osu.Game/Modes/Objects/HitObjectDefaults.cs b/osu.Game/Modes/Objects/HitObjectDefaults.cs deleted file mode 100644 index 7a0d64391e..0000000000 --- a/osu.Game/Modes/Objects/HitObjectDefaults.cs +++ /dev/null @@ -1,25 +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.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 da47bf2c67..6707f7aa15 100644 --- a/osu.Game/Modes/UI/HitRenderer.cs +++ b/osu.Game/Modes/UI/HitRenderer.cs @@ -9,7 +9,6 @@ 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; @@ -96,14 +95,8 @@ namespace osu.Game.Modes.UI 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); + h.ApplyDefaults(Beatmap.TimingInfo, Beatmap.BeatmapInfo.BaseDifficulty); // Post-process the beatmap processor.PostProcess(Beatmap); diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index d7370078ed..80d5c906e0 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -100,7 +100,6 @@ - From faacac331d8b70810540d766b1bd66fa75b9ed87 Mon Sep 17 00:00:00 2001 From: smoogipooo Date: Fri, 17 Mar 2017 00:38:40 +0900 Subject: [PATCH 3/3] Fix post-rebase issues. --- osu.Game.Modes.Osu/Objects/OsuHitObject.cs | 2 +- osu.Game.Modes.Osu/Objects/Slider.cs | 2 +- osu.Game/Modes/Objects/HitObject.cs | 2 +- osu.Game/Modes/UI/HitRenderer.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game.Modes.Osu/Objects/OsuHitObject.cs b/osu.Game.Modes.Osu/Objects/OsuHitObject.cs index 9648ba9c87..bedde7a763 100644 --- a/osu.Game.Modes.Osu/Objects/OsuHitObject.cs +++ b/osu.Game.Modes.Osu/Objects/OsuHitObject.cs @@ -68,7 +68,7 @@ namespace osu.Game.Modes.Osu.Objects return OsuScoreResult.Miss; } - public override void ApplyDefaults(TimingInfo timing, BaseDifficulty difficulty) + public override void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) { base.ApplyDefaults(timing, difficulty); diff --git a/osu.Game.Modes.Osu/Objects/Slider.cs b/osu.Game.Modes.Osu/Objects/Slider.cs index baa6e9442d..d94b6534ed 100644 --- a/osu.Game.Modes.Osu/Objects/Slider.cs +++ b/osu.Game.Modes.Osu/Objects/Slider.cs @@ -47,7 +47,7 @@ namespace osu.Game.Modes.Osu.Objects public double Velocity; public double TickDistance; - public override void ApplyDefaults(TimingInfo timing, BaseDifficulty difficulty) + public override void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) { base.ApplyDefaults(timing, difficulty); diff --git a/osu.Game/Modes/Objects/HitObject.cs b/osu.Game/Modes/Objects/HitObject.cs index 7fe30ff1ac..f2712d92ba 100644 --- a/osu.Game/Modes/Objects/HitObject.cs +++ b/osu.Game/Modes/Objects/HitObject.cs @@ -30,6 +30,6 @@ namespace osu.Game.Modes.Objects /// /// The difficulty settings to use. /// The timing settings to use. - public virtual void ApplyDefaults(TimingInfo timing, BaseDifficulty difficulty) { } + public virtual void ApplyDefaults(TimingInfo timing, BeatmapDifficulty difficulty) { } } } diff --git a/osu.Game/Modes/UI/HitRenderer.cs b/osu.Game/Modes/UI/HitRenderer.cs index 6707f7aa15..0faa986fc7 100644 --- a/osu.Game/Modes/UI/HitRenderer.cs +++ b/osu.Game/Modes/UI/HitRenderer.cs @@ -96,7 +96,7 @@ namespace osu.Game.Modes.UI // Apply defaults foreach (var h in Beatmap.HitObjects) - h.ApplyDefaults(Beatmap.TimingInfo, Beatmap.BeatmapInfo.BaseDifficulty); + h.ApplyDefaults(Beatmap.TimingInfo, Beatmap.BeatmapInfo.Difficulty); // Post-process the beatmap processor.PostProcess(Beatmap);