From b1f6828a1a29e7ccd7004fe15c039c8153cc29a3 Mon Sep 17 00:00:00 2001 From: MaxOhn Date: Wed, 5 Sep 2018 20:30:03 +0200 Subject: [PATCH 1/5] Added OsuModWiggle class and adjusted OsuRuleset.cs --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 82 ++++++++++++++++++++++ osu.Game.Rulesets.Osu/OsuRuleset.cs | 5 ++ 2 files changed, 87 insertions(+) create mode 100644 osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs new file mode 100644 index 0000000000..5e6cb22ec3 --- /dev/null +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -0,0 +1,82 @@ +// Copyright (c) 2007-2018 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using osu.Framework.Graphics; +using osu.Game.Graphics; +using osu.Game.Rulesets.Mods; +using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Osu.Objects; +using OpenTK; + +namespace osu.Game.Rulesets.Osu.Mods +{ + internal class OsuModWiggle : Mod, IApplicableToDrawableHitObjects + { + public override string Name => "Wiggle"; + public override string ShortenedName => "WG"; + public override FontAwesome Icon => FontAwesome.fa_arrows_alt; + public override ModType Type => ModType.Fun; + public override string Description => "They just won't stay still..."; + public override double ScoreMultiplier => 1; + + private readonly int wiggle_delay = 90; // (ms) Higher = fewer wiggles + private readonly int wiggle_strength = 10; // Higher = stronger wiggles + + public void ApplyToDrawableHitObjects(IEnumerable drawables) + { + foreach(var drawable in drawables) + drawable.ApplyCustomUpdateState += drawableOnApplyCustomUpdateState; + } + + private void drawableOnApplyCustomUpdateState(DrawableHitObject drawable, ArmedState state) + { + var hitObject = (OsuHitObject)drawable.HitObject; + Vector2 origPos = drawable.Position; + + Random distRand = new Random(hitObject.ComboOffset); + Random angleRand = new Random(hitObject.IndexInCurrentCombo); + + // Wiggle all objects during TimePreempt + int amountWiggles = (int)hitObject.TimePreempt / wiggle_delay; + + for (int i = 0; i < amountWiggles; i++) + { + using (drawable.BeginAbsoluteSequence(hitObject.StartTime - hitObject.TimePreempt + i * wiggle_delay, true)) + { + float nextAngle = (float)(angleRand.NextDouble() * 2 * Math.PI); + float nextDist = (float)(distRand.NextDouble() * wiggle_strength); + Vector2 wiggledPos = new Vector2((float)(nextDist * Math.Cos(nextAngle) + origPos.X), (float)(nextDist * Math.Sin(nextAngle) + origPos.Y)); + drawable.MoveTo(wiggledPos, wiggle_delay); + } + } + + // Keep wiggling sliders and spinners for their duration + double objDuration; + if (hitObject is Slider slider) + { + objDuration = slider.Duration; + } + else if (hitObject is Spinner spinner) + { + objDuration = spinner.Duration; + } + else + return; + + amountWiggles = (int)(objDuration / wiggle_delay); + + for (int i = 0; i < amountWiggles; i++) + { + using (drawable.BeginAbsoluteSequence(hitObject.StartTime + i * wiggle_delay, true)) + { + float nextAngle = (float)(angleRand.NextDouble() * 2 * Math.PI); + float nextDist = (float)(distRand.NextDouble() * wiggle_strength); + Vector2 wiggledPos = new Vector2((float)(nextDist * Math.Cos(nextAngle) + origPos.X), (float)(nextDist * Math.Sin(nextAngle) + origPos.Y)); + drawable.MoveTo(wiggledPos, wiggle_delay); + } + } + } + } +} diff --git a/osu.Game.Rulesets.Osu/OsuRuleset.cs b/osu.Game.Rulesets.Osu/OsuRuleset.cs index fa6e9a018a..a16f6494e7 100644 --- a/osu.Game.Rulesets.Osu/OsuRuleset.cs +++ b/osu.Game.Rulesets.Osu/OsuRuleset.cs @@ -117,6 +117,11 @@ namespace osu.Game.Rulesets.Osu new OsuModRelax(), new OsuModAutopilot(), }; + case ModType.Fun: + return new Mod[] + { + new OsuModWiggle(), + }; default: return new Mod[] { }; } From 9d94aa4e6260cac120abb67f15c43ba6be3367ff Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Sep 2018 17:38:47 +0900 Subject: [PATCH 2/5] Fix formatting and constants --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index 5e6cb22ec3..d03908fef1 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -21,12 +21,12 @@ namespace osu.Game.Rulesets.Osu.Mods public override string Description => "They just won't stay still..."; public override double ScoreMultiplier => 1; - private readonly int wiggle_delay = 90; // (ms) Higher = fewer wiggles - private readonly int wiggle_strength = 10; // Higher = stronger wiggles - + private const int wiggle_delay = 90; // (ms) Higher = fewer wiggles + private const int wiggle_strength = 10; // Higher = stronger wiggles + public void ApplyToDrawableHitObjects(IEnumerable drawables) { - foreach(var drawable in drawables) + foreach (var drawable in drawables) drawable.ApplyCustomUpdateState += drawableOnApplyCustomUpdateState; } @@ -34,7 +34,7 @@ namespace osu.Game.Rulesets.Osu.Mods { var hitObject = (OsuHitObject)drawable.HitObject; Vector2 origPos = drawable.Position; - + Random distRand = new Random(hitObject.ComboOffset); Random angleRand = new Random(hitObject.IndexInCurrentCombo); From 00daaef27a8885284372fcbd738df89b78454d76 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Sep 2018 17:57:27 +0900 Subject: [PATCH 3/5] Use a slightly more suiting icon --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index d03908fef1..46ccfc5a35 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -16,7 +16,7 @@ namespace osu.Game.Rulesets.Osu.Mods { public override string Name => "Wiggle"; public override string ShortenedName => "WG"; - public override FontAwesome Icon => FontAwesome.fa_arrows_alt; + public override FontAwesome Icon => FontAwesome.fa_certificate; public override ModType Type => ModType.Fun; public override string Description => "They just won't stay still..."; public override double ScoreMultiplier => 1; From ef31698f5653a82219a5ad3f9d29e86da362caaf Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Sep 2018 18:18:40 +0900 Subject: [PATCH 4/5] Further code tidying --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 55 ++++++++-------------- 1 file changed, 20 insertions(+), 35 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index 46ccfc5a35..206d7e649f 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics; using osu.Game.Graphics; using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Objects.Drawables; +using osu.Game.Rulesets.Objects.Types; using osu.Game.Rulesets.Osu.Objects; using OpenTK; @@ -21,7 +22,7 @@ namespace osu.Game.Rulesets.Osu.Mods public override string Description => "They just won't stay still..."; public override double ScoreMultiplier => 1; - private const int wiggle_delay = 90; // (ms) Higher = fewer wiggles + private const int wiggle_duration = 90; // (ms) Higher = fewer wiggles private const int wiggle_strength = 10; // Higher = stronger wiggles public void ApplyToDrawableHitObjects(IEnumerable drawables) @@ -32,51 +33,35 @@ namespace osu.Game.Rulesets.Osu.Mods private void drawableOnApplyCustomUpdateState(DrawableHitObject drawable, ArmedState state) { - var hitObject = (OsuHitObject)drawable.HitObject; - Vector2 origPos = drawable.Position; + var osuObject = (OsuHitObject)drawable.HitObject; + Vector2 origin = drawable.Position; - Random distRand = new Random(hitObject.ComboOffset); - Random angleRand = new Random(hitObject.IndexInCurrentCombo); + Random distRand = new Random(osuObject.ComboOffset); + Random angleRand = new Random(osuObject.IndexInCurrentCombo); // Wiggle all objects during TimePreempt - int amountWiggles = (int)hitObject.TimePreempt / wiggle_delay; + int amountWiggles = (int)osuObject.TimePreempt / wiggle_duration; + + void wiggle() + { + float nextAngle = (float)(angleRand.NextDouble() * 2 * Math.PI); + float nextDist = (float)(distRand.NextDouble() * wiggle_strength); + drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), wiggle_duration); + } for (int i = 0; i < amountWiggles; i++) - { - using (drawable.BeginAbsoluteSequence(hitObject.StartTime - hitObject.TimePreempt + i * wiggle_delay, true)) - { - float nextAngle = (float)(angleRand.NextDouble() * 2 * Math.PI); - float nextDist = (float)(distRand.NextDouble() * wiggle_strength); - Vector2 wiggledPos = new Vector2((float)(nextDist * Math.Cos(nextAngle) + origPos.X), (float)(nextDist * Math.Sin(nextAngle) + origPos.Y)); - drawable.MoveTo(wiggledPos, wiggle_delay); - } - } + using (drawable.BeginAbsoluteSequence(osuObject.StartTime - osuObject.TimePreempt + i * wiggle_duration, true)) + wiggle(); // Keep wiggling sliders and spinners for their duration - double objDuration; - if (hitObject is Slider slider) - { - objDuration = slider.Duration; - } - else if (hitObject is Spinner spinner) - { - objDuration = spinner.Duration; - } - else + if (!(osuObject is IHasEndTime endTime)) return; - amountWiggles = (int)(objDuration / wiggle_delay); + amountWiggles = (int)(endTime.Duration / wiggle_duration); for (int i = 0; i < amountWiggles; i++) - { - using (drawable.BeginAbsoluteSequence(hitObject.StartTime + i * wiggle_delay, true)) - { - float nextAngle = (float)(angleRand.NextDouble() * 2 * Math.PI); - float nextDist = (float)(distRand.NextDouble() * wiggle_strength); - Vector2 wiggledPos = new Vector2((float)(nextDist * Math.Cos(nextAngle) + origPos.X), (float)(nextDist * Math.Sin(nextAngle) + origPos.Y)); - drawable.MoveTo(wiggledPos, wiggle_delay); - } - } + using (drawable.BeginAbsoluteSequence(osuObject.StartTime + i * wiggle_duration, true)) + wiggle(); } } } From ec6185cd3196776c2eacc120ebcb50e937b175db Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 14 Sep 2018 18:20:19 +0900 Subject: [PATCH 5/5] Reduce random allocations --- osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs index 206d7e649f..5b69247451 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModWiggle.cs @@ -36,16 +36,15 @@ namespace osu.Game.Rulesets.Osu.Mods var osuObject = (OsuHitObject)drawable.HitObject; Vector2 origin = drawable.Position; - Random distRand = new Random(osuObject.ComboOffset); - Random angleRand = new Random(osuObject.IndexInCurrentCombo); + Random objRand = new Random((int)osuObject.StartTime); // Wiggle all objects during TimePreempt int amountWiggles = (int)osuObject.TimePreempt / wiggle_duration; void wiggle() { - float nextAngle = (float)(angleRand.NextDouble() * 2 * Math.PI); - float nextDist = (float)(distRand.NextDouble() * wiggle_strength); + float nextAngle = (float)(objRand.NextDouble() * 2 * Math.PI); + float nextDist = (float)(objRand.NextDouble() * wiggle_strength); drawable.MoveTo(new Vector2((float)(nextDist * Math.Cos(nextAngle) + origin.X), (float)(nextDist * Math.Sin(nextAngle) + origin.Y)), wiggle_duration); }