From 2722565204b59c3b99be66ea801127863e28b3e8 Mon Sep 17 00:00:00 2001 From: Henry Lin Date: Tue, 29 Jun 2021 13:36:30 +0800 Subject: [PATCH] Take circle radius into account when clamping to playfield --- osu.Game.Rulesets.Osu/Mods/OsuModRandom.cs | 36 ++++++++++++++-------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModRandom.cs b/osu.Game.Rulesets.Osu/Mods/OsuModRandom.cs index 25bdac7be3..62ca5e5fb4 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModRandom.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModRandom.cs @@ -74,6 +74,10 @@ public void ApplyToBeatmap(IBeatmap beatmap) applyRandomisation(rateOfChangeMultiplier, previous, current); + // Move hit objects back into the playfield if they are outside of it, + // which would sometimes happen during big jumps otherwise. + current.PositionRandomised = clampToPlayfield(current.PositionRandomised, (float)hitObject.Radius); + hitObject.Position = current.PositionRandomised; // update end position as it may have changed as a result of the position update. @@ -142,14 +146,7 @@ private void applyRandomisation(float rateOfChangeMultiplier, RandomObjectInfo p current.AngleRad = (float)Math.Atan2(posRelativeToPrev.Y, posRelativeToPrev.X); - var position = previous.EndPositionRandomised + posRelativeToPrev; - - // Move hit objects back into the playfield if they are outside of it, - // which would sometimes happen during big jumps otherwise. - position.X = MathHelper.Clamp(position.X, 0, OsuPlayfield.BASE_SIZE.X); - position.Y = MathHelper.Clamp(position.Y, 0, OsuPlayfield.BASE_SIZE.Y); - - current.PositionRandomised = position; + current.PositionRandomised = previous.EndPositionRandomised + posRelativeToPrev; } /// @@ -185,14 +182,12 @@ private void applyDecreasingShift(IList hitObjects, Vector2 shift) { for (int i = 0; i < hitObjects.Count; i++) { + var hitObject = hitObjects[i]; // The first object is shifted by a vector slightly smaller than shift // The last object is shifted by a vector slightly larger than zero - Vector2 position = hitObjects[i].Position + shift * ((hitObjects.Count - i) / (float)(hitObjects.Count + 1)); + Vector2 position = hitObject.Position + shift * ((hitObjects.Count - i) / (float)(hitObjects.Count + 1)); - position.X = MathHelper.Clamp(position.X, 0, OsuPlayfield.BASE_SIZE.X); - position.Y = MathHelper.Clamp(position.Y, 0, OsuPlayfield.BASE_SIZE.Y); - - hitObjects[i].Position = position; + hitObject.Position = clampToPlayfield(position, (float)hitObject.Radius); } } @@ -217,6 +212,13 @@ private MarginPadding getMinSliderMargin(Slider slider) minMargin.Left = Math.Min(minMargin.Left, OsuPlayfield.BASE_SIZE.X - minMargin.Right); minMargin.Top = Math.Min(minMargin.Top, OsuPlayfield.BASE_SIZE.Y - minMargin.Bottom); + var radius = (float)slider.Radius; + + minMargin.Left += radius; + minMargin.Right += radius; + minMargin.Top += radius; + minMargin.Bottom += radius; + return minMargin; } @@ -236,6 +238,14 @@ private void shiftNestedObjects(Slider slider, Vector2 shift) } } + private Vector2 clampToPlayfield(Vector2 position, float radius) + { + position.X = MathHelper.Clamp(position.X, radius, OsuPlayfield.BASE_SIZE.X - radius); + position.Y = MathHelper.Clamp(position.Y, radius, OsuPlayfield.BASE_SIZE.Y - radius); + + return position; + } + private class RandomObjectInfo { public float AngleRad { get; set; }