mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 17:52:56 +08:00
Code optimisation
This commit is contained in:
parent
9090e75020
commit
1bb27cd488
@ -8,6 +8,7 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Rulesets.Mods;
|
using osu.Game.Rulesets.Mods;
|
||||||
using osu.Game.Rulesets.Objects;
|
using osu.Game.Rulesets.Objects;
|
||||||
using osu.Game.Rulesets.Osu.Beatmaps;
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
||||||
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
using osu.Game.Rulesets.Osu.UI;
|
using osu.Game.Rulesets.Osu.UI;
|
||||||
using osu.Game.Rulesets.Osu.Utils;
|
using osu.Game.Rulesets.Osu.Utils;
|
||||||
|
|
||||||
@ -22,6 +23,8 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
|
|
||||||
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModTarget)).ToArray();
|
public override Type[] IncompatibleMods => base.IncompatibleMods.Append(typeof(OsuModTarget)).ToArray();
|
||||||
|
|
||||||
|
private static readonly float playfield_diagonal = OsuPlayfield.BASE_SIZE.LengthFast;
|
||||||
|
|
||||||
private Random? rng;
|
private Random? rng;
|
||||||
|
|
||||||
public void ApplyToBeatmap(IBeatmap beatmap)
|
public void ApplyToBeatmap(IBeatmap beatmap)
|
||||||
@ -43,7 +46,7 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
bool invertFlow = false;
|
bool invertFlow = false;
|
||||||
|
|
||||||
if (i == 0 ||
|
if (i == 0 ||
|
||||||
(positionInfos[i - 1].HitObject.NewCombo && (i <= 1 || !positionInfos[i - 2].HitObject.NewCombo) && (i <= 2 || !positionInfos[i - 3].HitObject.NewCombo)) ||
|
(positionInfos[Math.Max(0, i - 2)].HitObject.IndexInCurrentCombo > 1 && positionInfos[i - 1].HitObject.NewCombo && rng.NextDouble() < 0.6) ||
|
||||||
OsuHitObjectGenerationUtils.IsHitObjectOnBeat(osuBeatmap, positionInfos[i - 1].HitObject, true) ||
|
OsuHitObjectGenerationUtils.IsHitObjectOnBeat(osuBeatmap, positionInfos[i - 1].HitObject, true) ||
|
||||||
(OsuHitObjectGenerationUtils.IsHitObjectOnBeat(osuBeatmap, positionInfos[i - 1].HitObject) && rng.NextDouble() < 0.25))
|
(OsuHitObjectGenerationUtils.IsHitObjectOnBeat(osuBeatmap, positionInfos[i - 1].HitObject) && rng.NextDouble() < 0.25))
|
||||||
{
|
{
|
||||||
@ -63,7 +66,7 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
float flowChangeOffset = 0;
|
float flowChangeOffset = 0;
|
||||||
float oneTimeOffset = OsuHitObjectGenerationUtils.RandomGaussian(rng, 0, 0.03f);
|
float oneTimeOffset = OsuHitObjectGenerationUtils.RandomGaussian(rng, 0, 0.03f);
|
||||||
|
|
||||||
if (positionInfos[i - 1].HitObject.NewCombo && (i <= 1 || !positionInfos[i - 2].HitObject.NewCombo) && rng.NextDouble() < 0.6)
|
if (positionInfos[Math.Max(0, i - 2)].HitObject.IndexInCurrentCombo > 1 && positionInfos[i - 1].HitObject.NewCombo && rng.NextDouble() < 0.6)
|
||||||
{
|
{
|
||||||
flowChangeOffset = OsuHitObjectGenerationUtils.RandomGaussian(rng, 0, 0.05f);
|
flowChangeOffset = OsuHitObjectGenerationUtils.RandomGaussian(rng, 0, 0.05f);
|
||||||
|
|
||||||
@ -72,12 +75,12 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (invertFlow)
|
if (invertFlow)
|
||||||
flowDirection ^= true;
|
flowDirection = !flowDirection;
|
||||||
|
|
||||||
positionInfos[i].RelativeAngle = OsuHitObjectGenerationUtils.GetRelativeTargetAngle(
|
positionInfos[i].RelativeAngle = getRelativeTargetAngle(
|
||||||
positionInfos[i].DistanceFromPrevious,
|
positionInfos[i].DistanceFromPrevious,
|
||||||
(sequenceOffset + oneTimeOffset) * (float)Math.Sqrt(positionInfos[i].DistanceFromPrevious) +
|
(sequenceOffset + oneTimeOffset) * (float)Math.Sqrt(positionInfos[i].DistanceFromPrevious) +
|
||||||
flowChangeOffset * (float)Math.Sqrt(640 - positionInfos[i].DistanceFromPrevious),
|
flowChangeOffset * (float)Math.Sqrt(playfield_diagonal - positionInfos[i].DistanceFromPrevious),
|
||||||
flowDirection
|
flowDirection
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -85,5 +88,15 @@ namespace osu.Game.Rulesets.Osu.Mods
|
|||||||
|
|
||||||
osuBeatmap.HitObjects = OsuHitObjectGenerationUtils.RepositionHitObjects(positionInfos);
|
osuBeatmap.HitObjects = OsuHitObjectGenerationUtils.RepositionHitObjects(positionInfos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <param name="targetDistance">The target distance between the previous and the current <see cref="OsuHitObject"/>.</param>
|
||||||
|
/// <param name="offset">The angle (in rad) by which the target angle should be offset.</param>
|
||||||
|
/// <param name="flowDirection">Whether the relative angle should be positive or negative.</param>
|
||||||
|
private static float getRelativeTargetAngle(float targetDistance, float offset, bool flowDirection)
|
||||||
|
{
|
||||||
|
float angle = (float)(3 / (1 + 200 * Math.Exp(0.016 * (targetDistance - 466))) + 0.45 + offset);
|
||||||
|
float relativeAngle = (float)Math.PI - angle;
|
||||||
|
return flowDirection ? -relativeAngle : relativeAngle;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,7 +196,7 @@ namespace osu.Game.Rulesets.Osu.Utils
|
|||||||
public static bool IsHitObjectOnBeat(OsuBeatmap beatmap, OsuHitObject hitObject, bool downbeatsOnly = false)
|
public static bool IsHitObjectOnBeat(OsuBeatmap beatmap, OsuHitObject hitObject, bool downbeatsOnly = false)
|
||||||
{
|
{
|
||||||
var timingPoints = beatmap.ControlPointInfo.TimingPoints;
|
var timingPoints = beatmap.ControlPointInfo.TimingPoints;
|
||||||
var currentTimingPoint = timingPoints.Reverse().FirstOrDefault(p => p.Time <= hitObject.StartTime);
|
var currentTimingPoint = timingPoints.LastOrDefault(p => p.Time <= hitObject.StartTime);
|
||||||
|
|
||||||
if (currentTimingPoint == null)
|
if (currentTimingPoint == null)
|
||||||
return false;
|
return false;
|
||||||
@ -210,21 +210,11 @@ namespace osu.Game.Rulesets.Osu.Utils
|
|||||||
return (timeSinceTimingPoint + 1) % length < 2;
|
return (timeSinceTimingPoint + 1) % length < 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <param name="targetDistance">The target distance between the previous and the current <see cref="OsuHitObject"/>.</param>
|
|
||||||
/// <param name="offset">The angle (in rad) by which the target angle should be offset.</param>
|
|
||||||
/// <param name="flowDirection">Whether the relative angle should be positive or negative.</param>
|
|
||||||
public static float GetRelativeTargetAngle(float targetDistance, float offset, bool flowDirection)
|
|
||||||
{
|
|
||||||
float angle = (float)(3 / (1 + 200 * Math.Pow(MathHelper.E, 0.016 * (targetDistance - 466))) + 0.45 + offset);
|
|
||||||
float relativeAngle = MathHelper.Pi - angle;
|
|
||||||
return flowDirection ? -relativeAngle : relativeAngle;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static float RandomGaussian(Random rng, float mean = 0, float stdDev = 1)
|
public static float RandomGaussian(Random rng, float mean = 0, float stdDev = 1)
|
||||||
{
|
{
|
||||||
double x1 = 1 - rng.NextDouble();
|
double x1 = rng.NextDouble();
|
||||||
double x2 = 1 - rng.NextDouble();
|
double x2 = rng.NextDouble();
|
||||||
double stdNormal = Math.Sqrt(-2 * Math.Log(x1)) * Math.Sin(MathHelper.TwoPi * x2);
|
double stdNormal = Math.Sqrt(-2 * Math.Log(x1)) * Math.Sin(2 * Math.PI * x2);
|
||||||
return mean + stdDev * (float)stdNormal;
|
return mean + stdDev * (float)stdNormal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user