From 62155e6dd53820d2d5454150ba51f7a6566a9f21 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 16 Nov 2017 20:06:32 +0900 Subject: [PATCH 1/7] Make DifficultyCalculator support mod applications Fixes https://github.com/ppy/osu/issues/476. --- .../CatchDifficultyCalculator.cs | 7 +--- osu.Game.Rulesets.Catch/CatchRuleset.cs | 2 +- .../ManiaDifficultyCalculator.cs | 5 +-- osu.Game.Rulesets.Mania/ManiaRuleset.cs | 2 +- .../OsuDifficulty/OsuDifficultyCalculator.cs | 2 +- osu.Game.Rulesets.Osu/OsuRuleset.cs | 3 +- .../TaikoDifficultyCalculator.cs | 2 +- osu.Game.Rulesets.Taiko/TaikoRuleset.cs | 2 +- osu.Game/Beatmaps/DifficultyCalculator.cs | 37 +++++++++++-------- osu.Game/Beatmaps/DummyWorkingBeatmap.cs | 2 +- osu.Game/Rulesets/Ruleset.cs | 3 +- 11 files changed, 35 insertions(+), 32 deletions(-) diff --git a/osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs b/osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs index 3c6cc4b1a3..127fde74ef 100644 --- a/osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs @@ -14,11 +14,8 @@ namespace osu.Game.Rulesets.Catch { } - protected override double CalculateInternal(Dictionary categoryDifficulty) - { - return 0; - } + public override double Calculate(Dictionary categoryDifficulty) => 0; protected override BeatmapConverter CreateBeatmapConverter() => new CatchBeatmapConverter(); } -} \ No newline at end of file +} diff --git a/osu.Game.Rulesets.Catch/CatchRuleset.cs b/osu.Game.Rulesets.Catch/CatchRuleset.cs index 1a9b034cf2..1d5fc0545e 100644 --- a/osu.Game.Rulesets.Catch/CatchRuleset.cs +++ b/osu.Game.Rulesets.Catch/CatchRuleset.cs @@ -95,7 +95,7 @@ namespace osu.Game.Rulesets.Catch public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_fruits_o }; - public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new CatchDifficultyCalculator(beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap, Mod[] mods = null) => new CatchDifficultyCalculator(beatmap); public override int LegacyID => 2; diff --git a/osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs b/osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs index 784df1f293..d5c6d21131 100644 --- a/osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs @@ -16,10 +16,7 @@ namespace osu.Game.Rulesets.Mania { } - protected override double CalculateInternal(Dictionary categoryDifficulty) - { - return 0; - } + public override double Calculate(Dictionary categoryDifficulty) => 0; protected override BeatmapConverter CreateBeatmapConverter() => new ManiaBeatmapConverter(true, (int)Math.Max(1, Math.Round(Beatmap.BeatmapInfo.BaseDifficulty.CircleSize))); } diff --git a/osu.Game.Rulesets.Mania/ManiaRuleset.cs b/osu.Game.Rulesets.Mania/ManiaRuleset.cs index c0996cadf9..4eea884891 100644 --- a/osu.Game.Rulesets.Mania/ManiaRuleset.cs +++ b/osu.Game.Rulesets.Mania/ManiaRuleset.cs @@ -107,7 +107,7 @@ namespace osu.Game.Rulesets.Mania public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_mania_o }; - public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new ManiaDifficultyCalculator(beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap, Mod[] mods = null) => new ManiaDifficultyCalculator(beatmap); public override int LegacyID => 3; diff --git a/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs b/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs index 457466fd86..6ed45e1f03 100644 --- a/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs @@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.Osu.OsuDifficulty (h as Slider)?.Curve?.Calculate(); } - protected override double CalculateInternal(Dictionary categoryDifficulty) + public override double Calculate(Dictionary categoryDifficulty) { OsuDifficultyBeatmap beatmap = new OsuDifficultyBeatmap(Objects); Skill[] skills = diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 7650a91d7a..a4828319d1 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -14,6 +14,7 @@ using System.Linq; using osu.Framework.Graphics; using osu.Game.Overlays.Settings; using osu.Framework.Input.Bindings; +using osu.Game.Rulesets.Scoring; namespace osu.Game.Rulesets.Osu { @@ -112,7 +113,7 @@ namespace osu.Game.Rulesets.Osu public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_osu_o }; - public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new OsuDifficultyCalculator(beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap, Mod[] mods = null) => new OsuDifficultyCalculator(beatmap); public override string Description => "osu!"; diff --git a/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs b/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs index de97658e35..57986cd198 100644 --- a/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs @@ -36,7 +36,7 @@ namespace osu.Game.Rulesets.Taiko { } - protected override double CalculateInternal(Dictionary categoryDifficulty) + public override double Calculate(Dictionary categoryDifficulty) { // Fill our custom DifficultyHitObject class, that carries additional information difficultyHitObjects.Clear(); diff --git a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs index ea0f0eae1a..99ae36967a 100644 --- a/osu.Game.Rulesets.Taiko/TaikoRuleset.cs +++ b/osu.Game.Rulesets.Taiko/TaikoRuleset.cs @@ -97,7 +97,7 @@ namespace osu.Game.Rulesets.Taiko public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_taiko_o }; - public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => new TaikoDifficultyCalculator(beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap, Mod[] mods = null) => new TaikoDifficultyCalculator(beatmap); public override int LegacyID => 1; diff --git a/osu.Game/Beatmaps/DifficultyCalculator.cs b/osu.Game/Beatmaps/DifficultyCalculator.cs index bb6a292d9d..f6cc535aca 100644 --- a/osu.Game/Beatmaps/DifficultyCalculator.cs +++ b/osu.Game/Beatmaps/DifficultyCalculator.cs @@ -3,6 +3,10 @@ using osu.Game.Rulesets.Objects; using System.Collections.Generic; +using osu.Game.Rulesets.Mods; +using osu.Framework.Timing; +using System.Linq; +using osu.Framework.Extensions.IEnumerableExtensions; namespace osu.Game.Beatmaps { @@ -10,41 +14,44 @@ namespace osu.Game.Beatmaps { protected double TimeRate = 1; - protected abstract double CalculateInternal(Dictionary categoryDifficulty); - - private void loadTiming() - { - // TODO: Handle mods - const int audio_rate = 100; - TimeRate = audio_rate / 100.0; - } - - public double Calculate(Dictionary categoryDifficulty = null) - { - loadTiming(); - double difficulty = CalculateInternal(categoryDifficulty); - return difficulty; - } + public abstract double Calculate(Dictionary categoryDifficulty = null); } public abstract class DifficultyCalculator : DifficultyCalculator where T : HitObject { protected readonly Beatmap Beatmap; + protected readonly Mod[] Mods; protected List Objects; protected DifficultyCalculator(Beatmap beatmap) + : this(beatmap, null) + { + } + + protected DifficultyCalculator(Beatmap beatmap, Mod[] mods) { Beatmap = beatmap; + Mods = mods ?? new Mod[0]; Objects = CreateBeatmapConverter().Convert(beatmap).HitObjects; foreach (var h in Objects) h.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty); + ApplyMods(mods); + PreprocessHitObjects(); } + protected virtual void ApplyMods(Mod[] mods) + { + var clock = new StopwatchClock(); + mods.OfType().ForEach(m => m.ApplyToClock(clock)); + + TimeRate = clock.Rate; + } + protected virtual void PreprocessHitObjects() { } diff --git a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs index b9376849c1..c15d585eb2 100644 --- a/osu.Game/Beatmaps/DummyWorkingBeatmap.cs +++ b/osu.Game/Beatmaps/DummyWorkingBeatmap.cs @@ -59,7 +59,7 @@ namespace osu.Game.Beatmaps throw new NotImplementedException(); } - public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap) => null; + public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap, Mod[] mods = null) => null; public override string Description => "dummy"; diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index 587c2fc659..e8919c4bda 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -10,6 +10,7 @@ using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Overlays.Settings; using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets @@ -47,7 +48,7 @@ namespace osu.Game.Rulesets /// public abstract RulesetContainer CreateRulesetContainerWith(WorkingBeatmap beatmap, bool isForCurrentRuleset); - public abstract DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap); + public abstract DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap, Mod[] mods = null); public virtual Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_question_circle }; From 18f2e92a48b4ba9e044143d04972470980666fc4 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 16 Nov 2017 20:35:57 +0900 Subject: [PATCH 2/7] Rework mod applications to hitobject/rulesetcontainer for DifficultyCalculator --- osu.Game.Rulesets.Mania/Mods/ManiaMod.cs | 6 ++--- osu.Game.Rulesets.Osu/Mods/OsuMod.cs | 27 ++++++++++++------- osu.Game/Beatmaps/DifficultyCalculator.cs | 4 +++ osu.Game/Rulesets/Mods/IApplicableMod.cs | 22 --------------- .../Rulesets/Mods/IApplicableToHitObject.cs | 20 ++++++++++++++ .../Mods/IApplicableToRulesetContainer.cs | 21 +++++++++++++++ osu.Game/Rulesets/Mods/ModAutoplay.cs | 4 +-- osu.Game/Rulesets/UI/RulesetContainer.cs | 6 ++++- osu.Game/osu.Game.csproj | 3 ++- 9 files changed, 74 insertions(+), 39 deletions(-) delete mode 100644 osu.Game/Rulesets/Mods/IApplicableMod.cs create mode 100644 osu.Game/Rulesets/Mods/IApplicableToHitObject.cs create mode 100644 osu.Game/Rulesets/Mods/IApplicableToRulesetContainer.cs diff --git a/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs b/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs index 037c3bd567..164309c227 100644 --- a/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs +++ b/osu.Game.Rulesets.Mania/Mods/ManiaMod.cs @@ -86,18 +86,17 @@ namespace osu.Game.Rulesets.Mania.Mods public override Type[] IncompatibleMods => new[] { typeof(ModFlashlight) }; } - public class ManiaModRandom : Mod, IApplicableMod + public class ManiaModRandom : Mod, IApplicableToRulesetContainer { public override string Name => "Random"; public override string ShortenedName => "RD"; - public override FontAwesome Icon => FontAwesome.fa_osu_dice; + public override FontAwesome Icon => FontAwesome.fa_osu_dice; public override string Description => @"Shuffle around the notes!"; public override double ScoreMultiplier => 1; public void ApplyToRulesetContainer(RulesetContainer rulesetContainer) { int availableColumns = ((ManiaRulesetContainer)rulesetContainer).AvailableColumns; - var shuffledColumns = Enumerable.Range(0, availableColumns).OrderBy(item => RNG.Next()).ToList(); rulesetContainer.Objects.OfType().ForEach(h => h.Column = shuffledColumns[h.Column]); @@ -188,6 +187,7 @@ namespace osu.Game.Rulesets.Mania.Mods base.ApplyToRulesetContainer(rulesetContainer); } + protected override Score CreateReplayScore(Beatmap beatmap) => new Score { User = new User { Username = "osu!topus!" }, diff --git a/osu.Game.Rulesets.Osu/Mods/OsuMod.cs b/osu.Game.Rulesets.Osu/Mods/OsuMod.cs index 2970055bff..596fe27504 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuMod.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuMod.cs @@ -33,22 +33,29 @@ namespace osu.Game.Rulesets.Osu.Mods public override double ScoreMultiplier => 1.06; } - public class OsuModHardRock : ModHardRock, IApplicableMod + public class OsuModHardRock : ModHardRock, IApplicableToHitObject { public override double ScoreMultiplier => 1.06; public override bool Ranked => true; - public void ApplyToRulesetContainer(RulesetContainer rulesetContainer) + public void ApplyToHitObject(OsuHitObject hitObject) + { + hitObject.Position = new Vector2(hitObject.Position.X, OsuPlayfield.BASE_SIZE.Y - hitObject.Y); + + var slider = hitObject as Slider; + if (slider == null) + return; + + var newControlPoints = new List(); + slider.ControlPoints.ForEach(c => newControlPoints.Add(new Vector2(c.X, OsuPlayfield.BASE_SIZE.Y - c.Y))); + + slider.ControlPoints = newControlPoints; + slider.Curve?.Calculate(); // Recalculate the slider curve + } + + public void ApplyToHitObjects(RulesetContainer rulesetContainer) { - rulesetContainer.Objects.OfType().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Y)); - rulesetContainer.Objects.OfType().ForEach(s => - { - var newControlPoints = new List(); - s.ControlPoints.ForEach(c => newControlPoints.Add(new Vector2(c.X, OsuPlayfield.BASE_SIZE.Y - c.Y))); - s.ControlPoints = newControlPoints; - s.Curve?.Calculate(); // Recalculate the slider curve - }); } } diff --git a/osu.Game/Beatmaps/DifficultyCalculator.cs b/osu.Game/Beatmaps/DifficultyCalculator.cs index f6cc535aca..54dab07b31 100644 --- a/osu.Game/Beatmaps/DifficultyCalculator.cs +++ b/osu.Game/Beatmaps/DifficultyCalculator.cs @@ -49,6 +49,10 @@ namespace osu.Game.Beatmaps var clock = new StopwatchClock(); mods.OfType().ForEach(m => m.ApplyToClock(clock)); + foreach (var mod in mods.OfType>()) + foreach (var obj in Objects) + mod.ApplyToHitObject(obj); + TimeRate = clock.Rate; } diff --git a/osu.Game/Rulesets/Mods/IApplicableMod.cs b/osu.Game/Rulesets/Mods/IApplicableMod.cs deleted file mode 100644 index 1957952720..0000000000 --- a/osu.Game/Rulesets/Mods/IApplicableMod.cs +++ /dev/null @@ -1,22 +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.Rulesets.Objects; -using osu.Game.Rulesets.UI; - -namespace osu.Game.Rulesets.Mods -{ - /// - /// An interface for mods that are applied to a RulesetContainer. - /// - /// The type of HitObject the RulesetContainer contains. - public interface IApplicableMod - where TObject : HitObject - { - /// - /// Applies the mod to a RulesetContainer. - /// - /// The RulesetContainer to apply the mod to. - void ApplyToRulesetContainer(RulesetContainer rulesetContainer); - } -} diff --git a/osu.Game/Rulesets/Mods/IApplicableToHitObject.cs b/osu.Game/Rulesets/Mods/IApplicableToHitObject.cs new file mode 100644 index 0000000000..099234d9c1 --- /dev/null +++ b/osu.Game/Rulesets/Mods/IApplicableToHitObject.cs @@ -0,0 +1,20 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Objects; + +namespace osu.Game.Rulesets.Mods +{ + /// + /// An interface for s that can be applied to s. + /// + public interface IApplicableToHitObject + where TObject : HitObject + { + /// + /// Applies this to a . + /// + /// The to apply to. + void ApplyToHitObject(TObject hitObject); + } +} diff --git a/osu.Game/Rulesets/Mods/IApplicableToRulesetContainer.cs b/osu.Game/Rulesets/Mods/IApplicableToRulesetContainer.cs new file mode 100644 index 0000000000..9b23dd58f9 --- /dev/null +++ b/osu.Game/Rulesets/Mods/IApplicableToRulesetContainer.cs @@ -0,0 +1,21 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Game.Rulesets.Objects; +using osu.Game.Rulesets.UI; + +namespace osu.Game.Rulesets.Mods +{ + /// + /// An interface for s that can be applied to s. + /// + public interface IApplicableToRulesetContainer + where TObject : HitObject + { + /// + /// Applies this to a . + /// + /// The to apply to. + void ApplyToRulesetContainer(RulesetContainer rulesetContainer); + } +} diff --git a/osu.Game/Rulesets/Mods/ModAutoplay.cs b/osu.Game/Rulesets/Mods/ModAutoplay.cs index ece0deba84..d94d4ba0db 100644 --- a/osu.Game/Rulesets/Mods/ModAutoplay.cs +++ b/osu.Game/Rulesets/Mods/ModAutoplay.cs @@ -10,7 +10,7 @@ using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets.Mods { - public abstract class ModAutoplay : ModAutoplay, IApplicableMod + public abstract class ModAutoplay : ModAutoplay, IApplicableToRulesetContainer where T : HitObject { protected abstract Score CreateReplayScore(Beatmap beatmap); @@ -30,4 +30,4 @@ namespace osu.Game.Rulesets.Mods public override double ScoreMultiplier => 0; public override Type[] IncompatibleMods => new[] { typeof(ModRelax), typeof(ModSuddenDeath), typeof(ModNoFail) }; } -} \ No newline at end of file +} diff --git a/osu.Game/Rulesets/UI/RulesetContainer.cs b/osu.Game/Rulesets/UI/RulesetContainer.cs index 278814ea7e..6726d94995 100644 --- a/osu.Game/Rulesets/UI/RulesetContainer.cs +++ b/osu.Game/Rulesets/UI/RulesetContainer.cs @@ -212,7 +212,11 @@ namespace osu.Game.Rulesets.UI if (mods == null) return; - foreach (var mod in mods.OfType>()) + foreach (var mod in mods.OfType>()) + foreach (var obj in Beatmap.HitObjects) + mod.ApplyToHitObject(obj); + + foreach (var mod in mods.OfType>()) mod.ApplyToRulesetContainer(this); } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index ac1498c9d9..7b479bdba2 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -549,9 +549,10 @@ - + + From 5781b45b3903393570025c567a7071446b08f9f5 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Thu, 16 Nov 2017 20:41:26 +0900 Subject: [PATCH 3/7] Set TimeRate after mod application --- osu.Game/Beatmaps/DifficultyCalculator.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/osu.Game/Beatmaps/DifficultyCalculator.cs b/osu.Game/Beatmaps/DifficultyCalculator.cs index 54dab07b31..f101cfbfb8 100644 --- a/osu.Game/Beatmaps/DifficultyCalculator.cs +++ b/osu.Game/Beatmaps/DifficultyCalculator.cs @@ -48,12 +48,11 @@ namespace osu.Game.Beatmaps { var clock = new StopwatchClock(); mods.OfType().ForEach(m => m.ApplyToClock(clock)); + TimeRate = clock.Rate; foreach (var mod in mods.OfType>()) foreach (var obj in Objects) mod.ApplyToHitObject(obj); - - TimeRate = clock.Rate; } protected virtual void PreprocessHitObjects() From cc1720241e8d63fb3d9d56333eb348d89933eafb Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 17 Nov 2017 12:35:03 +0900 Subject: [PATCH 4/7] Fix DifficultyCalculator using incorrect mods --- osu.Game/Beatmaps/DifficultyCalculator.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Beatmaps/DifficultyCalculator.cs b/osu.Game/Beatmaps/DifficultyCalculator.cs index f101cfbfb8..34c6bb95ff 100644 --- a/osu.Game/Beatmaps/DifficultyCalculator.cs +++ b/osu.Game/Beatmaps/DifficultyCalculator.cs @@ -39,7 +39,7 @@ namespace osu.Game.Beatmaps foreach (var h in Objects) h.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty); - ApplyMods(mods); + ApplyMods(Mods); PreprocessHitObjects(); } From 7892eefd6899bf6c0a64d397f300d77bc3576e92 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 17 Nov 2017 14:23:52 +0900 Subject: [PATCH 5/7] Fix up mod application + beatmap/hitobject references --- .../OsuDifficulty/OsuDifficultyCalculator.cs | 13 ++++++++++--- osu.Game.Rulesets.Osu/OsuRuleset.cs | 2 +- .../TaikoDifficultyCalculator.cs | 2 +- osu.Game/Beatmaps/DifficultyCalculator.cs | 18 +++++++++--------- 4 files changed, 21 insertions(+), 14 deletions(-) diff --git a/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs b/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs index 6ed45e1f03..9f279ccae4 100644 --- a/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using osu.Game.Beatmaps; +using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Osu.Beatmaps; using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.OsuDifficulty.Preprocessing; @@ -16,19 +17,25 @@ namespace osu.Game.Rulesets.Osu.OsuDifficulty private const int section_length = 400; private const double difficulty_multiplier = 0.0675; - public OsuDifficultyCalculator(Beatmap beatmap) : base(beatmap) + public OsuDifficultyCalculator(Beatmap beatmap) + : base(beatmap) + { + } + + public OsuDifficultyCalculator(Beatmap beatmap, Mod[] mods) + : base(beatmap, mods) { } protected override void PreprocessHitObjects() { - foreach (OsuHitObject h in Objects) + foreach (OsuHitObject h in Beatmap.HitObjects) (h as Slider)?.Curve?.Calculate(); } public override double Calculate(Dictionary categoryDifficulty) { - OsuDifficultyBeatmap beatmap = new OsuDifficultyBeatmap(Objects); + OsuDifficultyBeatmap beatmap = new OsuDifficultyBeatmap(Beatmap.HitObjects); Skill[] skills = { new Aim(), diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index a4828319d1..8b7a014ea8 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -113,7 +113,7 @@ namespace osu.Game.Rulesets.Osu public override Drawable CreateIcon() => new SpriteIcon { Icon = FontAwesome.fa_osu_osu_o }; - public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap, Mod[] mods = null) => new OsuDifficultyCalculator(beatmap); + public override DifficultyCalculator CreateDifficultyCalculator(Beatmap beatmap, Mod[] mods = null) => new OsuDifficultyCalculator(beatmap, mods); public override string Description => "osu!"; diff --git a/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs b/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs index 57986cd198..adb7ace5f9 100644 --- a/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs @@ -41,7 +41,7 @@ namespace osu.Game.Rulesets.Taiko // Fill our custom DifficultyHitObject class, that carries additional information difficultyHitObjects.Clear(); - foreach (var hitObject in Objects) + foreach (var hitObject in Beatmap.HitObjects) difficultyHitObjects.Add(new TaikoHitObjectDifficulty(hitObject)); // Sort DifficultyHitObjects by StartTime of the HitObjects - just to make sure. diff --git a/osu.Game/Beatmaps/DifficultyCalculator.cs b/osu.Game/Beatmaps/DifficultyCalculator.cs index 34c6bb95ff..3c32b718bc 100644 --- a/osu.Game/Beatmaps/DifficultyCalculator.cs +++ b/osu.Game/Beatmaps/DifficultyCalculator.cs @@ -19,11 +19,9 @@ namespace osu.Game.Beatmaps public abstract class DifficultyCalculator : DifficultyCalculator where T : HitObject { - protected readonly Beatmap Beatmap; + protected readonly Beatmap Beatmap; protected readonly Mod[] Mods; - protected List Objects; - protected DifficultyCalculator(Beatmap beatmap) : this(beatmap, null) { @@ -31,13 +29,9 @@ namespace osu.Game.Beatmaps protected DifficultyCalculator(Beatmap beatmap, Mod[] mods) { - Beatmap = beatmap; + Beatmap = CreateBeatmapConverter().Convert(beatmap); Mods = mods ?? new Mod[0]; - Objects = CreateBeatmapConverter().Convert(beatmap).HitObjects; - - foreach (var h in Objects) - h.ApplyDefaults(beatmap.ControlPointInfo, beatmap.BeatmapInfo.BaseDifficulty); ApplyMods(Mods); @@ -50,9 +44,15 @@ namespace osu.Game.Beatmaps mods.OfType().ForEach(m => m.ApplyToClock(clock)); TimeRate = clock.Rate; + foreach (var mod in Mods.OfType()) + mod.ApplyToDifficulty(Beatmap.BeatmapInfo.BaseDifficulty); + foreach (var mod in mods.OfType>()) - foreach (var obj in Objects) + foreach (var obj in Beatmap.HitObjects) mod.ApplyToHitObject(obj); + + foreach (var h in Beatmap.HitObjects) + h.ApplyDefaults(Beatmap.ControlPointInfo, Beatmap.BeatmapInfo.BaseDifficulty); } protected virtual void PreprocessHitObjects() From ac6213d1fadd8362580b482de0b1355981a25c8e Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 17 Nov 2017 14:26:33 +0900 Subject: [PATCH 6/7] CI fixes --- osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs | 2 +- osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs | 2 +- osu.Game.Rulesets.Osu/Mods/OsuMod.cs | 1 - osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs | 2 +- osu.Game.Rulesets.Osu/OsuRuleset.cs | 1 - osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs | 2 +- osu.Game/Beatmaps/DifficultyCalculator.cs | 2 +- osu.Game/Rulesets/Mods/IApplicableToHitObject.cs | 2 +- osu.Game/Rulesets/Ruleset.cs | 1 - 9 files changed, 6 insertions(+), 9 deletions(-) diff --git a/osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs b/osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs index 127fde74ef..db88e04dd0 100644 --- a/osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs @@ -14,7 +14,7 @@ namespace osu.Game.Rulesets.Catch { } - public override double Calculate(Dictionary categoryDifficulty) => 0; + public override double Calculate(Dictionary categoryDifficulty = null) => 0; protected override BeatmapConverter CreateBeatmapConverter() => new CatchBeatmapConverter(); } diff --git a/osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs b/osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs index d5c6d21131..070fc2b4dd 100644 --- a/osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs @@ -16,7 +16,7 @@ namespace osu.Game.Rulesets.Mania { } - public override double Calculate(Dictionary categoryDifficulty) => 0; + public override double Calculate(Dictionary categoryDifficulty = null) => 0; protected override BeatmapConverter CreateBeatmapConverter() => new ManiaBeatmapConverter(true, (int)Math.Max(1, Math.Round(Beatmap.BeatmapInfo.BaseDifficulty.CircleSize))); } diff --git a/osu.Game.Rulesets.Osu/Mods/OsuMod.cs b/osu.Game.Rulesets.Osu/Mods/OsuMod.cs index 596fe27504..71349285b3 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuMod.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuMod.cs @@ -9,7 +9,6 @@ using osu.Game.Rulesets.Osu.Objects; using System; using System.Collections.Generic; using System.Linq; -using osu.Framework.Extensions.IEnumerableExtensions; using osu.Game.Rulesets.Osu.UI; using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; diff --git a/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs b/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs index 9f279ccae4..f7909f8335 100644 --- a/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs @@ -33,7 +33,7 @@ namespace osu.Game.Rulesets.Osu.OsuDifficulty (h as Slider)?.Curve?.Calculate(); } - public override double Calculate(Dictionary categoryDifficulty) + public override double Calculate(Dictionary categoryDifficulty = null) { OsuDifficultyBeatmap beatmap = new OsuDifficultyBeatmap(Beatmap.HitObjects); Skill[] skills = diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index 8b7a014ea8..9c11474f97 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -14,7 +14,6 @@ using System.Linq; using osu.Framework.Graphics; using osu.Game.Overlays.Settings; using osu.Framework.Input.Bindings; -using osu.Game.Rulesets.Scoring; namespace osu.Game.Rulesets.Osu { diff --git a/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs b/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs index adb7ace5f9..e06582500f 100644 --- a/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs @@ -36,7 +36,7 @@ namespace osu.Game.Rulesets.Taiko { } - public override double Calculate(Dictionary categoryDifficulty) + public override double Calculate(Dictionary categoryDifficulty = null) { // Fill our custom DifficultyHitObject class, that carries additional information difficultyHitObjects.Clear(); diff --git a/osu.Game/Beatmaps/DifficultyCalculator.cs b/osu.Game/Beatmaps/DifficultyCalculator.cs index 3c32b718bc..351154623e 100644 --- a/osu.Game/Beatmaps/DifficultyCalculator.cs +++ b/osu.Game/Beatmaps/DifficultyCalculator.cs @@ -27,7 +27,7 @@ namespace osu.Game.Beatmaps { } - protected DifficultyCalculator(Beatmap beatmap, Mod[] mods) + protected DifficultyCalculator(Beatmap beatmap, Mod[] mods = null) { Beatmap = CreateBeatmapConverter().Convert(beatmap); Mods = mods ?? new Mod[0]; diff --git a/osu.Game/Rulesets/Mods/IApplicableToHitObject.cs b/osu.Game/Rulesets/Mods/IApplicableToHitObject.cs index 099234d9c1..7f39def343 100644 --- a/osu.Game/Rulesets/Mods/IApplicableToHitObject.cs +++ b/osu.Game/Rulesets/Mods/IApplicableToHitObject.cs @@ -8,7 +8,7 @@ namespace osu.Game.Rulesets.Mods /// /// An interface for s that can be applied to s. /// - public interface IApplicableToHitObject + public interface IApplicableToHitObject where TObject : HitObject { /// diff --git a/osu.Game/Rulesets/Ruleset.cs b/osu.Game/Rulesets/Ruleset.cs index e8919c4bda..ed2fdf4157 100644 --- a/osu.Game/Rulesets/Ruleset.cs +++ b/osu.Game/Rulesets/Ruleset.cs @@ -10,7 +10,6 @@ using osu.Game.Beatmaps; using osu.Game.Graphics; using osu.Game.Overlays.Settings; using osu.Game.Rulesets.Mods; -using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.UI; namespace osu.Game.Rulesets From 95fd323c6b122cd768a31a889eaa464319390212 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 17 Nov 2017 14:37:06 +0900 Subject: [PATCH 7/7] Fix ManiaDifficultyCalculator possibly failing due to nullref --- osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs | 2 +- osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs | 2 +- .../OsuDifficulty/OsuDifficultyCalculator.cs | 2 +- osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs | 2 +- osu.Game/Beatmaps/DifficultyCalculator.cs | 9 ++------- 5 files changed, 6 insertions(+), 11 deletions(-) diff --git a/osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs b/osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs index db88e04dd0..b77be9d1f0 100644 --- a/osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Catch/CatchDifficultyCalculator.cs @@ -16,6 +16,6 @@ namespace osu.Game.Rulesets.Catch public override double Calculate(Dictionary categoryDifficulty = null) => 0; - protected override BeatmapConverter CreateBeatmapConverter() => new CatchBeatmapConverter(); + protected override BeatmapConverter CreateBeatmapConverter(Beatmap beatmap) => new CatchBeatmapConverter(); } } diff --git a/osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs b/osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs index 070fc2b4dd..67bc347535 100644 --- a/osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Mania/ManiaDifficultyCalculator.cs @@ -18,6 +18,6 @@ namespace osu.Game.Rulesets.Mania public override double Calculate(Dictionary categoryDifficulty = null) => 0; - protected override BeatmapConverter CreateBeatmapConverter() => new ManiaBeatmapConverter(true, (int)Math.Max(1, Math.Round(Beatmap.BeatmapInfo.BaseDifficulty.CircleSize))); + protected override BeatmapConverter CreateBeatmapConverter(Beatmap beatmap) => new ManiaBeatmapConverter(true, (int)Math.Max(1, Math.Round(beatmap.BeatmapInfo.BaseDifficulty.CircleSize))); } } diff --git a/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs b/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs index f7909f8335..537874f643 100644 --- a/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Osu/OsuDifficulty/OsuDifficultyCalculator.cs @@ -74,6 +74,6 @@ namespace osu.Game.Rulesets.Osu.OsuDifficulty return starRating; } - protected override BeatmapConverter CreateBeatmapConverter() => new OsuBeatmapConverter(); + protected override BeatmapConverter CreateBeatmapConverter(Beatmap beatmap) => new OsuBeatmapConverter(); } } diff --git a/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs b/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs index e06582500f..e881942fbf 100644 --- a/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs +++ b/osu.Game.Rulesets.Taiko/TaikoDifficultyCalculator.cs @@ -134,6 +134,6 @@ namespace osu.Game.Rulesets.Taiko return difficulty; } - protected override BeatmapConverter CreateBeatmapConverter() => new TaikoBeatmapConverter(true); + protected override BeatmapConverter CreateBeatmapConverter(Beatmap beatmap) => new TaikoBeatmapConverter(true); } } diff --git a/osu.Game/Beatmaps/DifficultyCalculator.cs b/osu.Game/Beatmaps/DifficultyCalculator.cs index 351154623e..f58f433cb2 100644 --- a/osu.Game/Beatmaps/DifficultyCalculator.cs +++ b/osu.Game/Beatmaps/DifficultyCalculator.cs @@ -22,14 +22,9 @@ namespace osu.Game.Beatmaps protected readonly Beatmap Beatmap; protected readonly Mod[] Mods; - protected DifficultyCalculator(Beatmap beatmap) - : this(beatmap, null) - { - } - protected DifficultyCalculator(Beatmap beatmap, Mod[] mods = null) { - Beatmap = CreateBeatmapConverter().Convert(beatmap); + Beatmap = CreateBeatmapConverter(beatmap).Convert(beatmap); Mods = mods ?? new Mod[0]; @@ -59,6 +54,6 @@ namespace osu.Game.Beatmaps { } - protected abstract BeatmapConverter CreateBeatmapConverter(); + protected abstract BeatmapConverter CreateBeatmapConverter(Beatmap beatmap); } }