From c848c83d0daa5e26cf82bb8c245613e98802d15c Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Sat, 22 Dec 2018 09:56:33 +0900 Subject: [PATCH] Refactor for readability + performance --- .../Difficulty/Skills/Aim.cs | 33 ++++++++++++------- .../Difficulty/Skills/Speed.cs | 27 ++++++++++++--- 2 files changed, 44 insertions(+), 16 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Difficulty/Skills/Aim.cs b/osu.Game.Rulesets.Osu/Difficulty/Skills/Aim.cs index 87d561b38f..d6137dff82 100644 --- a/osu.Game.Rulesets.Osu/Difficulty/Skills/Aim.cs +++ b/osu.Game.Rulesets.Osu/Difficulty/Skills/Aim.cs @@ -14,9 +14,10 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Skills private const double angle_bonus_begin = 5 * Math.PI / 12; private const double timing_threshold = 107; private const double min_distance_for_bonus = 90; - private const double angle_threshold = Math.PI / 4; + private static readonly double sin_angle_threshold = Math.Sin(angle_threshold); + protected override double SkillMultiplier => 26.25; protected override double StrainDecayBase => 0.15; @@ -28,23 +29,33 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Skills { if (current.Angle != null && current.Angle.Value > angle_bonus_begin) { - var angleBonus = Math.Sqrt( + var sinDiffAngle = Math.Sin(current.Angle.Value - angle_bonus_begin); + + var angleBonus = Math.Sqrt + ( Math.Max(0, Previous[0].JumpDistance + Previous[0].TravelDistance - min_distance_for_bonus) - * Math.Min( - Math.Sin(current.Angle.Value - angle_bonus_begin), - Math.Sin(angle_threshold)) - * (Math.Max(0, current.JumpDistance - min_distance_for_bonus) - * Math.Min( - Math.Sin(current.Angle.Value - angle_bonus_begin), - Math.Sin(angle_threshold)))); + * Math.Min + ( + sinDiffAngle, + sin_angle_threshold + ) + * Math.Max(0, current.JumpDistance - min_distance_for_bonus) + * Math.Min + ( + sinDiffAngle, + sin_angle_threshold + ) + ); result = 2 * Math.Pow(Math.Max(0, angleBonus), 0.99) / Math.Max(Previous[0].StrainTime, timing_threshold); } } - return Math.Max( + return Math.Max + ( result + (Math.Pow(current.TravelDistance, 0.99) + Math.Pow(current.JumpDistance, 0.99)) / Math.Max(current.StrainTime, timing_threshold), - (Math.Pow(current.TravelDistance, 0.99) + Math.Pow(current.JumpDistance, 0.99)) / current.StrainTime); + (Math.Pow(current.TravelDistance, 0.99) + Math.Pow(current.JumpDistance, 0.99)) / current.StrainTime + ); } } } diff --git a/osu.Game.Rulesets.Osu/Difficulty/Skills/Speed.cs b/osu.Game.Rulesets.Osu/Difficulty/Skills/Speed.cs index daa77d8872..f63013b2af 100644 --- a/osu.Game.Rulesets.Osu/Difficulty/Skills/Speed.cs +++ b/osu.Game.Rulesets.Osu/Difficulty/Skills/Speed.cs @@ -13,6 +13,10 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Skills { private const double angle_bonus_begin = 3 * Math.PI / 4; private const double pi_over_4 = Math.PI / 4; + private const double pi_over_2 = Math.PI / 2; + private const double max_distance_for_bonus = 90; + + private static readonly double sin_pi_over_4 = Math.Sin(pi_over_4); protected override double SkillMultiplier => 1400; protected override double StrainDecayBase => 0.3; @@ -33,11 +37,24 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Skills double angleBonus = 1.0; if (current.Angle != null && current.Angle.Value < angle_bonus_begin) { - angleBonus = 1 + Math.Min(Math.Sin(angle_bonus_begin - current.Angle.Value), Math.Sin(Math.PI / 4)) / 2.5; - if (distance < 90 && current.Angle.Value < Math.PI / 4) - angleBonus += (1 - angleBonus) * Math.Min((90 - distance) / 10, 1); - else if (distance < 90 && current.Angle.Value < Math.PI / 2) - angleBonus += (1 - angleBonus) * Math.Min((90 - distance) / 10, 1) * Math.Sin((Math.PI / 2 - current.Angle.Value) / pi_over_4); + angleBonus = 1 + Math.Min(Math.Sin(angle_bonus_begin - current.Angle.Value), sin_pi_over_4) / 2.5; + + if (distance < max_distance_for_bonus) + { + if (current.Angle.Value < pi_over_4) + { + angleBonus += + (1 - angleBonus) + * Math.Min((max_distance_for_bonus - distance) / 10, 1); + } + else if (current.Angle.Value < pi_over_2) + { + angleBonus += + (1 - angleBonus) + * Math.Min((max_distance_for_bonus - distance) / 10, 1) + * Math.Sin((pi_over_2 - current.Angle.Value) / pi_over_4); + } + } } return speedBonus * angleBonus * (0.95 + Math.Pow(distance / SINGLE_SPACING_THRESHOLD, 4)) / current.StrainTime;