From 7128d73178c62f5dd4c760aa819549f0381209d4 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 16 Jun 2017 21:08:23 +0900 Subject: [PATCH 01/16] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index e256557def..3dd751659b 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit e256557defe595032cbc3a9896797fa41d6ee8b6 +Subproject commit 3dd751659b5f8e3267146db1557ec43d77456b8e From 87f6ba57d32b4c714a1c22dd9673117f35833e01 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Sat, 17 Jun 2017 14:08:18 +0900 Subject: [PATCH 02/16] Fix resources being reset incorrectly to an old revision --- osu-resources | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-resources b/osu-resources index 9f46a456dc..10fda22522 160000 --- a/osu-resources +++ b/osu-resources @@ -1 +1 @@ -Subproject commit 9f46a456dc3a56dcbff09671a3f588b16a464106 +Subproject commit 10fda22522ffadbdbc43fa0f3683a065e536f7d1 From ccac2e9a7511b72e7d60a0b635ec5ae51ccd7222 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Sun, 18 Jun 2017 19:33:50 -0500 Subject: [PATCH 03/16] Add a visualizer around the logo --- osu.Game/Screens/Menu/LogoVisualisation.cs | 198 +++++++++++++++++++++ osu.Game/Screens/Menu/MenuVisualisation.cs | 11 -- osu.Game/Screens/Menu/OsuLogo.cs | 21 ++- osu.Game/osu.Game.csproj | 4 +- 4 files changed, 213 insertions(+), 21 deletions(-) create mode 100644 osu.Game/Screens/Menu/LogoVisualisation.cs delete mode 100644 osu.Game/Screens/Menu/MenuVisualisation.cs diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs new file mode 100644 index 0000000000..36b5a672a3 --- /dev/null +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -0,0 +1,198 @@ +// Copyright (c) 2007-2017 ppy Pty Ltd . +// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using OpenTK; +using OpenTK.Graphics; +using OpenTK.Graphics.ES30; +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Batches; +using osu.Framework.Graphics.Colour; +using osu.Framework.Graphics.OpenGL.Vertices; +using osu.Framework.Graphics.Primitives; +using osu.Framework.Graphics.Shaders; +using osu.Framework.Graphics.Textures; +using osu.Game.Beatmaps; +using osu.Game.Graphics; +using System; + +namespace osu.Game.Screens.Menu +{ + internal class LogoVisualisation : Drawable, IHasAccentColour + { + private Bindable beatmap = new Bindable(); + private Color4 barColour; + + private const int index_change = 5; + private const int bar_length = 1200; + private const int bars_per_visualizer = 250; + private const int visualizers = 5; + + /// + /// How much should each bar go down each milisecond (based on a full bar) + /// + private const float decay_per_milisecond = 0.0024f; + + private int indexOffset; + + public Color4 AccentColour + { + get + { + return barColour; + } + set + { + //Half alpha makes it look really good! + value.A = 0.5f; + barColour = value; + } + } + + private float[] fftData = new float[256]; + + public override bool HandleInput => false; + + private Shader shader; + private readonly Texture texture; + + public LogoVisualisation() + { + texture = Texture.WhitePixel; + AccentColour = Color4.White; + } + + [BackgroundDependencyLoader] + private void load(ShaderManager shaders, OsuGame game) + { + beatmap.BindTo(game.Beatmap); + shader = shaders?.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED); + } + + private void ensureFFTData() + { + float[] temporalFFTData = beatmap?.Value?.Track?.CurrentAmplitudes.FrequencyAmplitudes ?? new float[256]; + + for (int i = 0; i < bars_per_visualizer; i++) + { + int index = (i + indexOffset) % bars_per_visualizer; + if (beatmap?.Value?.Track?.IsRunning ?? false) + { + if (temporalFFTData[index] > fftData[i]) + fftData[i] = temporalFFTData[index]; + } + else + { + if (fftData[(i + index_change) % bars_per_visualizer] > fftData[i]) + fftData[i] = fftData[(i + index_change) % bars_per_visualizer]; + } + } + indexOffset = (indexOffset + index_change) % bars_per_visualizer; + Scheduler.AddDelayed(ensureFFTData, 50); + } + + protected override void LoadComplete() + { + base.LoadComplete(); + ensureFFTData(); + } + + protected override void Update() + { + base.Update(); + + float decayFactor = (float)Time.Elapsed * decay_per_milisecond; + for (int i = 0; i < bars_per_visualizer; i++) + { + //0.03% of extra bar length to make it a little faster when bar is almost at it's minimum + fftData[i] -= decayFactor * (fftData[i] + 0.03f); + if (fftData[i] < 0) + fftData[i] = 0; + } + + Invalidate(Invalidation.DrawNode, shallPropagate: false); + } + + protected override DrawNode CreateDrawNode() => new VisualisationDrawNode(); + + private readonly VisualizerSharedData sharedData = new VisualizerSharedData(); + protected override void ApplyDrawNode(DrawNode node) + { + base.ApplyDrawNode(node); + + var visNode = (VisualisationDrawNode)node; + + visNode.Shader = shader; + visNode.Texture = texture; + visNode.Size = DrawSize.X; + visNode.Shared = sharedData; + visNode.Colour = barColour; + visNode.AudioData = fftData; + } + + private class VisualizerSharedData + { + public readonly LinearBatch VertexBatch = new LinearBatch(100 * 4, 10, PrimitiveType.Quads); + } + + private class VisualisationDrawNode : DrawNode + { + public Shader Shader; + public Texture Texture; + public VisualizerSharedData Shared; + //Asuming the logo is a circle, we don't need a second dimension. + public float Size; + + public Color4 Colour; + public float[] AudioData; + + public override void Draw(Action vertexAction) + { + base.Draw(vertexAction); + + Shader.Bind(); + Texture.TextureGL.Bind(); + + Vector2 inflation = DrawInfo.MatrixInverse.ExtractScale().Xy; + + ColourInfo colourInfo = DrawInfo.Colour; + colourInfo.ApplyChild(Colour); + + if (AudioData != null) + { + for (int i = 0; i < bars_per_visualizer * visualizers; i++) + { + float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualizer * 360 + (i / bars_per_visualizer * (360 / visualizers))); + float rotationCos = (float)Math.Cos(rotation); + float rotationSin = (float)Math.Sin(rotation); + //taking the cos and sin to the 0..1 range + var barPosition = new Vector2(rotationCos / 2 + 0.5f, rotationSin / 2 + 0.5f) * Size; + + var barSize = new Vector2(Size * (float)Math.Sqrt(2 * (1 - Math.Cos(MathHelper.DegreesToRadians(360f / bars_per_visualizer)))) / 2f, bar_length * AudioData[i % bars_per_visualizer]); + //The distance between the position and the sides of the bar. + var bottomOffset = new Vector2(-rotationSin * barSize.X / 2, rotationCos * barSize.X / 2); + //The distance between the bottom side of the bar and the top side. + var amplitudeOffset = new Vector2(rotationCos * barSize.Y, rotationSin * barSize.Y); + + var rectangle = new Quad( + (barPosition - bottomOffset) * DrawInfo.Matrix, + (barPosition - bottomOffset + amplitudeOffset) * DrawInfo.Matrix, + (barPosition + bottomOffset) * DrawInfo.Matrix, + (barPosition + bottomOffset + amplitudeOffset) * DrawInfo.Matrix + ); + + Texture.DrawQuad( + rectangle, + colourInfo, + null, + Shared.VertexBatch.Add, + //barSize by itself will make it smooth more in the X axis than in the Y axis, this reverts that. + Vector2.Divide(inflation, barSize.Yx)); + } + } + Shader.Unbind(); + } + } + } +} diff --git a/osu.Game/Screens/Menu/MenuVisualisation.cs b/osu.Game/Screens/Menu/MenuVisualisation.cs deleted file mode 100644 index 85c65b460d..0000000000 --- a/osu.Game/Screens/Menu/MenuVisualisation.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . -// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE - -using osu.Framework.Graphics; - -namespace osu.Game.Screens.Menu -{ - internal class MenuVisualisation : Drawable - { - } -} diff --git a/osu.Game/Screens/Menu/OsuLogo.cs b/osu.Game/Screens/Menu/OsuLogo.cs index db1f008dcf..8459993967 100644 --- a/osu.Game/Screens/Menu/OsuLogo.cs +++ b/osu.Game/Screens/Menu/OsuLogo.cs @@ -34,6 +34,7 @@ namespace osu.Game.Screens.Menu private readonly Container logoBeatContainer; private readonly Container logoAmplitudeContainer; private readonly Container logoHoverContainer; + private readonly LogoVisualisation visualizer; private SampleChannel sampleClick; @@ -120,6 +121,14 @@ namespace osu.Game.Screens.Menu AutoSizeAxes = Axes.Both, Children = new Drawable[] { + visualizer = new LogoVisualisation + { + RelativeSizeAxes = Axes.Both, + Origin = Anchor.Centre, + Anchor = Anchor.Centre, + Alpha = 0.5f, + Size = new Vector2(0.96f) + }, new BufferedContainer { AutoSizeAxes = Axes.Both, @@ -189,14 +198,6 @@ namespace osu.Game.Screens.Menu Alpha = 0, } } - }, - new MenuVisualisation - { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, - RelativeSizeAxes = Axes.Both, - BlendingMode = BlendingMode.Additive, - Alpha = 0.2f, } } } @@ -246,10 +247,14 @@ namespace osu.Game.Screens.Menu if (effectPoint.KiaiMode && flashLayer.Alpha < 0.4f) { flashLayer.ClearTransforms(); + visualizer.ClearTransforms(); flashLayer.FadeTo(0.2f * amplitudeAdjust, beat_in_time, EasingTypes.Out); + visualizer.FadeTo(0.9f * amplitudeAdjust, beat_in_time, EasingTypes.Out); using (flashLayer.BeginDelayedSequence(beat_in_time)) flashLayer.FadeOut(beatLength); + using (visualizer.BeginDelayedSequence(beat_in_time)) + visualizer.FadeTo(0.5f, beatLength); } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 36f358801e..4b1985e3d4 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -45,7 +45,7 @@ True - $(SolutionDir)\packages\SharpCompress.0.17.1\lib\net45\SharpCompress.dll + $(SolutionDir)\packages\SharpCompress.0.17.1\lib\net45\SharpCompress.dll $(SolutionDir)\packages\SQLite.Net.Core-PCL.3.1.1\lib\portable-win8+net45+wp8+wpa81+MonoAndroid1+MonoTouch1\SQLite.Net.dll @@ -276,7 +276,7 @@ - + From cc7f341f98a11fe2107dc03c632cdede2a15c481 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Sun, 18 Jun 2017 21:52:39 -0500 Subject: [PATCH 04/16] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 3dd751659b..09746aa895 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 3dd751659b5f8e3267146db1557ec43d77456b8e +Subproject commit 09746aa89545253546d69a38d08e6972ddd06871 From d3662636d6ed9ba446aafde58d372a07e90c2f00 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Sun, 18 Jun 2017 22:01:07 -0500 Subject: [PATCH 05/16] CI fixes --- osu.Game/Screens/Menu/LogoVisualisation.cs | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index 36b5a672a3..0bbaf33c98 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -21,7 +21,7 @@ namespace osu.Game.Screens.Menu { internal class LogoVisualisation : Drawable, IHasAccentColour { - private Bindable beatmap = new Bindable(); + private readonly Bindable beatmap = new Bindable(); private Color4 barColour; private const int index_change = 5; @@ -50,7 +50,7 @@ namespace osu.Game.Screens.Menu } } - private float[] fftData = new float[256]; + private readonly float[] frequencyAmplitudes = new float[256]; public override bool HandleInput => false; @@ -70,32 +70,32 @@ namespace osu.Game.Screens.Menu shader = shaders?.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED); } - private void ensureFFTData() + private void ensureAmplitudes() { - float[] temporalFFTData = beatmap?.Value?.Track?.CurrentAmplitudes.FrequencyAmplitudes ?? new float[256]; + float[] temporalAmplitudes = beatmap?.Value?.Track?.CurrentAmplitudes.FrequencyAmplitudes ?? new float[256]; for (int i = 0; i < bars_per_visualizer; i++) { int index = (i + indexOffset) % bars_per_visualizer; if (beatmap?.Value?.Track?.IsRunning ?? false) { - if (temporalFFTData[index] > fftData[i]) - fftData[i] = temporalFFTData[index]; + if (temporalAmplitudes[index] > frequencyAmplitudes[i]) + frequencyAmplitudes[i] = temporalAmplitudes[index]; } else { - if (fftData[(i + index_change) % bars_per_visualizer] > fftData[i]) - fftData[i] = fftData[(i + index_change) % bars_per_visualizer]; + if (frequencyAmplitudes[(i + index_change) % bars_per_visualizer] > frequencyAmplitudes[i]) + frequencyAmplitudes[i] = frequencyAmplitudes[(i + index_change) % bars_per_visualizer]; } } indexOffset = (indexOffset + index_change) % bars_per_visualizer; - Scheduler.AddDelayed(ensureFFTData, 50); + Scheduler.AddDelayed(ensureAmplitudes, 50); } protected override void LoadComplete() { base.LoadComplete(); - ensureFFTData(); + ensureAmplitudes(); } protected override void Update() @@ -106,9 +106,9 @@ namespace osu.Game.Screens.Menu for (int i = 0; i < bars_per_visualizer; i++) { //0.03% of extra bar length to make it a little faster when bar is almost at it's minimum - fftData[i] -= decayFactor * (fftData[i] + 0.03f); - if (fftData[i] < 0) - fftData[i] = 0; + frequencyAmplitudes[i] -= decayFactor * (frequencyAmplitudes[i] + 0.03f); + if (frequencyAmplitudes[i] < 0) + frequencyAmplitudes[i] = 0; } Invalidate(Invalidation.DrawNode, shallPropagate: false); @@ -128,7 +128,7 @@ namespace osu.Game.Screens.Menu visNode.Size = DrawSize.X; visNode.Shared = sharedData; visNode.Colour = barColour; - visNode.AudioData = fftData; + visNode.AudioData = frequencyAmplitudes; } private class VisualizerSharedData @@ -163,7 +163,7 @@ namespace osu.Game.Screens.Menu { for (int i = 0; i < bars_per_visualizer * visualizers; i++) { - float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualizer * 360 + (i / bars_per_visualizer * (360 / visualizers))); + float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualizer * 360 + i / bars_per_visualizer * 360 / visualizers); float rotationCos = (float)Math.Cos(rotation); float rotationSin = (float)Math.Sin(rotation); //taking the cos and sin to the 0..1 range From cea8dc5602eb1f431407e49c4629c724f0ee2ca9 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Sun, 18 Jun 2017 22:13:21 -0500 Subject: [PATCH 06/16] Fix possible loss of fraction --- osu.Game/Screens/Menu/LogoVisualisation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index 0bbaf33c98..52f6abd3e7 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -163,7 +163,7 @@ namespace osu.Game.Screens.Menu { for (int i = 0; i < bars_per_visualizer * visualizers; i++) { - float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualizer * 360 + i / bars_per_visualizer * 360 / visualizers); + float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualizer * 360 + i / bars_per_visualizer * (360 / visualizers)); float rotationCos = (float)Math.Cos(rotation); float rotationSin = (float)Math.Sin(rotation); //taking the cos and sin to the 0..1 range From 3764c1d7993b8979b99db703ae1defd9ecb18aec Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Sun, 18 Jun 2017 22:28:18 -0500 Subject: [PATCH 07/16] Make bar length and visualizer count floats --- osu.Game/Screens/Menu/LogoVisualisation.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index 52f6abd3e7..08816019a0 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -25,9 +25,9 @@ namespace osu.Game.Screens.Menu private Color4 barColour; private const int index_change = 5; - private const int bar_length = 1200; + private const float bar_length = 1200; private const int bars_per_visualizer = 250; - private const int visualizers = 5; + private const float visualizers = 5; /// /// How much should each bar go down each milisecond (based on a full bar) From 63aabc162b85ab2e189d9011e857d28219068e22 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Sun, 18 Jun 2017 22:34:45 -0500 Subject: [PATCH 08/16] Fix TestCaseMenuButtonSystem not starting up --- osu.Game/Screens/Menu/LogoVisualisation.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index 08816019a0..3a49793cc2 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -63,10 +63,11 @@ namespace osu.Game.Screens.Menu AccentColour = Color4.White; } - [BackgroundDependencyLoader] + [BackgroundDependencyLoader(true)] private void load(ShaderManager shaders, OsuGame game) { - beatmap.BindTo(game.Beatmap); + if (game?.Beatmap != null) + beatmap.BindTo(game.Beatmap); shader = shaders?.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED); } From 84aa17dea3ba9bcba63d15fb92d6775b1eac2689 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Sun, 18 Jun 2017 23:08:27 -0500 Subject: [PATCH 09/16] Attempt to fix possible loss of fraction --- osu.Game/Screens/Menu/LogoVisualisation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index 3a49793cc2..d4ebdf8125 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -164,7 +164,7 @@ namespace osu.Game.Screens.Menu { for (int i = 0; i < bars_per_visualizer * visualizers; i++) { - float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualizer * 360 + i / bars_per_visualizer * (360 / visualizers)); + float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualizer * 360 + (i / bars_per_visualizer) * (360 / visualizers)); float rotationCos = (float)Math.Cos(rotation); float rotationSin = (float)Math.Sin(rotation); //taking the cos and sin to the 0..1 range From 77ca48c1bd03bd51d82db449725a0033342daa79 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Sun, 18 Jun 2017 23:52:42 -0500 Subject: [PATCH 10/16] CI Fixes --- osu.Game/Screens/Menu/LogoVisualisation.cs | 51 ++++++++++++---------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index d4ebdf8125..2752418687 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -162,34 +162,37 @@ namespace osu.Game.Screens.Menu if (AudioData != null) { - for (int i = 0; i < bars_per_visualizer * visualizers; i++) + for (int j = 0; j < visualizers; j++) { - float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualizer * 360 + (i / bars_per_visualizer) * (360 / visualizers)); - float rotationCos = (float)Math.Cos(rotation); - float rotationSin = (float)Math.Sin(rotation); - //taking the cos and sin to the 0..1 range - var barPosition = new Vector2(rotationCos / 2 + 0.5f, rotationSin / 2 + 0.5f) * Size; + for (int i = 0; i < bars_per_visualizer; i++) + { + float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualizer * 360 + j * 360 / visualizers); + float rotationCos = (float)Math.Cos(rotation); + float rotationSin = (float)Math.Sin(rotation); + //taking the cos and sin to the 0..1 range + var barPosition = new Vector2(rotationCos / 2 + 0.5f, rotationSin / 2 + 0.5f) * Size; - var barSize = new Vector2(Size * (float)Math.Sqrt(2 * (1 - Math.Cos(MathHelper.DegreesToRadians(360f / bars_per_visualizer)))) / 2f, bar_length * AudioData[i % bars_per_visualizer]); - //The distance between the position and the sides of the bar. - var bottomOffset = new Vector2(-rotationSin * barSize.X / 2, rotationCos * barSize.X / 2); - //The distance between the bottom side of the bar and the top side. - var amplitudeOffset = new Vector2(rotationCos * barSize.Y, rotationSin * barSize.Y); + var barSize = new Vector2(Size * (float)Math.Sqrt(2 * (1 - Math.Cos(MathHelper.DegreesToRadians(360f / bars_per_visualizer)))) / 2f, bar_length * AudioData[i % bars_per_visualizer]); + //The distance between the position and the sides of the bar. + var bottomOffset = new Vector2(-rotationSin * barSize.X / 2, rotationCos * barSize.X / 2); + //The distance between the bottom side of the bar and the top side. + var amplitudeOffset = new Vector2(rotationCos * barSize.Y, rotationSin * barSize.Y); - var rectangle = new Quad( - (barPosition - bottomOffset) * DrawInfo.Matrix, - (barPosition - bottomOffset + amplitudeOffset) * DrawInfo.Matrix, - (barPosition + bottomOffset) * DrawInfo.Matrix, - (barPosition + bottomOffset + amplitudeOffset) * DrawInfo.Matrix - ); + var rectangle = new Quad( + (barPosition - bottomOffset) * DrawInfo.Matrix, + (barPosition - bottomOffset + amplitudeOffset) * DrawInfo.Matrix, + (barPosition + bottomOffset) * DrawInfo.Matrix, + (barPosition + bottomOffset + amplitudeOffset) * DrawInfo.Matrix + ); - Texture.DrawQuad( - rectangle, - colourInfo, - null, - Shared.VertexBatch.Add, - //barSize by itself will make it smooth more in the X axis than in the Y axis, this reverts that. - Vector2.Divide(inflation, barSize.Yx)); + Texture.DrawQuad( + rectangle, + colourInfo, + null, + Shared.VertexBatch.Add, + //barSize by itself will make it smooth more in the X axis than in the Y axis, this reverts that. + Vector2.Divide(inflation, barSize.Yx)); + } } } Shader.Unbind(); From 359cb4c083f09e5151d00d9a285d60e2dcc8cc18 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Jun 2017 18:29:44 +0900 Subject: [PATCH 11/16] Add kiai support --- osu.Game/Screens/Menu/LogoVisualisation.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index 2752418687..dec90087e4 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -73,7 +73,9 @@ namespace osu.Game.Screens.Menu private void ensureAmplitudes() { - float[] temporalAmplitudes = beatmap?.Value?.Track?.CurrentAmplitudes.FrequencyAmplitudes ?? new float[256]; + float[] temporalAmplitudes = beatmap.Value?.Track?.CurrentAmplitudes.FrequencyAmplitudes ?? new float[256]; + + var effect = beatmap.Value?.Beatmap.ControlPointInfo.EffectPointAt(beatmap.Value.Track?.CurrentTime ?? Time.Current); for (int i = 0; i < bars_per_visualizer; i++) { @@ -81,7 +83,7 @@ namespace osu.Game.Screens.Menu if (beatmap?.Value?.Track?.IsRunning ?? false) { if (temporalAmplitudes[index] > frequencyAmplitudes[i]) - frequencyAmplitudes[i] = temporalAmplitudes[index]; + frequencyAmplitudes[i] = temporalAmplitudes[index] * (effect?.KiaiMode == true ? 1 : 0.5f); } else { From e269bdbad7fcd755e15b97e45d291b12143f3de2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Jun 2017 18:30:13 +0900 Subject: [PATCH 12/16] Use additive colour; adjust constants a bit --- osu.Game/Screens/Menu/LogoVisualisation.cs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index dec90087e4..77ebd768f7 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -25,8 +25,8 @@ namespace osu.Game.Screens.Menu private Color4 barColour; private const int index_change = 5; - private const float bar_length = 1200; - private const int bars_per_visualizer = 250; + private const float bar_length = 600; + private const int bars_per_visualizer = 200; private const float visualizers = 5; /// @@ -44,8 +44,6 @@ namespace osu.Game.Screens.Menu } set { - //Half alpha makes it look really good! - value.A = 0.5f; barColour = value; } } @@ -60,7 +58,8 @@ namespace osu.Game.Screens.Menu public LogoVisualisation() { texture = Texture.WhitePixel; - AccentColour = Color4.White; + AccentColour = new Color4(1, 1, 1, 0.2f); + BlendingMode = BlendingMode.Additive; } [BackgroundDependencyLoader(true)] From 25b1058cd389df90f1eeeb80cf28c4d7cb67fd3c Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Jun 2017 18:30:44 +0900 Subject: [PATCH 13/16] Update framework --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index 09746aa895..5f3ec7ba17 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit 09746aa89545253546d69a38d08e6972ddd06871 +Subproject commit 5f3ec7ba178a6edda281ab42b4ca14c8c3c2e0b5 From 8c063fe2b88ba5e061931776cce348ee692ed843 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Jun 2017 18:38:39 +0900 Subject: [PATCH 14/16] Simplify AccentColour property for now --- osu.Game/Screens/Menu/LogoVisualisation.cs | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index 77ebd768f7..76f0292660 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -22,7 +22,6 @@ namespace osu.Game.Screens.Menu internal class LogoVisualisation : Drawable, IHasAccentColour { private readonly Bindable beatmap = new Bindable(); - private Color4 barColour; private const int index_change = 5; private const float bar_length = 600; @@ -36,17 +35,7 @@ namespace osu.Game.Screens.Menu private int indexOffset; - public Color4 AccentColour - { - get - { - return barColour; - } - set - { - barColour = value; - } - } + public Color4 AccentColour { get; set; } private readonly float[] frequencyAmplitudes = new float[256]; @@ -129,7 +118,7 @@ namespace osu.Game.Screens.Menu visNode.Texture = texture; visNode.Size = DrawSize.X; visNode.Shared = sharedData; - visNode.Colour = barColour; + visNode.Colour = AccentColour; visNode.AudioData = frequencyAmplitudes; } From a1b9499480b152354588983235abf560cc982aa9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Jun 2017 18:41:11 +0900 Subject: [PATCH 15/16] More documentation and constants --- osu.Game/Screens/Menu/LogoVisualisation.cs | 33 ++++++++++++++++++---- 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index 76f0292660..dcba07a8a3 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -23,16 +23,36 @@ namespace osu.Game.Screens.Menu { private readonly Bindable beatmap = new Bindable(); + /// + /// The number of bars to jump each update iteration. + /// private const int index_change = 5; + + /// + /// The maximum length of each bar in the visualiser. Will be reduced when kiai is not activated. + /// private const float bar_length = 600; + + /// + /// The number of bars in one rotation of the visualiser. + /// private const int bars_per_visualizer = 200; - private const float visualizers = 5; + + /// + /// How many times we should stretch around the circumference (overlapping overselves). + /// + private const float visualiser_rounds = 5; /// /// How much should each bar go down each milisecond (based on a full bar) /// private const float decay_per_milisecond = 0.0024f; + /// + /// Number of milliseconds between each amplitude update. + /// + private const float time_between_updates = 50; + private int indexOffset; public Color4 AccentColour { get; set; } @@ -59,7 +79,7 @@ namespace osu.Game.Screens.Menu shader = shaders?.Load(VertexShaderDescriptor.TEXTURE_2, FragmentShaderDescriptor.TEXTURE_ROUNDED); } - private void ensureAmplitudes() + private void updateAmplitudes() { float[] temporalAmplitudes = beatmap.Value?.Track?.CurrentAmplitudes.FrequencyAmplitudes ?? new float[256]; @@ -79,14 +99,15 @@ namespace osu.Game.Screens.Menu frequencyAmplitudes[i] = frequencyAmplitudes[(i + index_change) % bars_per_visualizer]; } } + indexOffset = (indexOffset + index_change) % bars_per_visualizer; - Scheduler.AddDelayed(ensureAmplitudes, 50); + Scheduler.AddDelayed(updateAmplitudes, time_between_updates); } protected override void LoadComplete() { base.LoadComplete(); - ensureAmplitudes(); + updateAmplitudes(); } protected override void Update() @@ -152,11 +173,11 @@ namespace osu.Game.Screens.Menu if (AudioData != null) { - for (int j = 0; j < visualizers; j++) + for (int j = 0; j < visualiser_rounds; j++) { for (int i = 0; i < bars_per_visualizer; i++) { - float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualizer * 360 + j * 360 / visualizers); + float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualizer * 360 + j * 360 / visualiser_rounds); float rotationCos = (float)Math.Cos(rotation); float rotationSin = (float)Math.Sin(rotation); //taking the cos and sin to the 0..1 range From 17cb043cb21dc9f70848e287c1845dd03c1172a0 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 19 Jun 2017 18:41:35 +0900 Subject: [PATCH 16/16] Visualiser --- osu.Game/Screens/Menu/LogoVisualisation.cs | 26 +++++++++++----------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/osu.Game/Screens/Menu/LogoVisualisation.cs b/osu.Game/Screens/Menu/LogoVisualisation.cs index dcba07a8a3..9fe98036ad 100644 --- a/osu.Game/Screens/Menu/LogoVisualisation.cs +++ b/osu.Game/Screens/Menu/LogoVisualisation.cs @@ -36,7 +36,7 @@ namespace osu.Game.Screens.Menu /// /// The number of bars in one rotation of the visualiser. /// - private const int bars_per_visualizer = 200; + private const int bars_per_visualiser = 200; /// /// How many times we should stretch around the circumference (overlapping overselves). @@ -85,9 +85,9 @@ namespace osu.Game.Screens.Menu var effect = beatmap.Value?.Beatmap.ControlPointInfo.EffectPointAt(beatmap.Value.Track?.CurrentTime ?? Time.Current); - for (int i = 0; i < bars_per_visualizer; i++) + for (int i = 0; i < bars_per_visualiser; i++) { - int index = (i + indexOffset) % bars_per_visualizer; + int index = (i + indexOffset) % bars_per_visualiser; if (beatmap?.Value?.Track?.IsRunning ?? false) { if (temporalAmplitudes[index] > frequencyAmplitudes[i]) @@ -95,12 +95,12 @@ namespace osu.Game.Screens.Menu } else { - if (frequencyAmplitudes[(i + index_change) % bars_per_visualizer] > frequencyAmplitudes[i]) - frequencyAmplitudes[i] = frequencyAmplitudes[(i + index_change) % bars_per_visualizer]; + if (frequencyAmplitudes[(i + index_change) % bars_per_visualiser] > frequencyAmplitudes[i]) + frequencyAmplitudes[i] = frequencyAmplitudes[(i + index_change) % bars_per_visualiser]; } } - indexOffset = (indexOffset + index_change) % bars_per_visualizer; + indexOffset = (indexOffset + index_change) % bars_per_visualiser; Scheduler.AddDelayed(updateAmplitudes, time_between_updates); } @@ -115,7 +115,7 @@ namespace osu.Game.Screens.Menu base.Update(); float decayFactor = (float)Time.Elapsed * decay_per_milisecond; - for (int i = 0; i < bars_per_visualizer; i++) + for (int i = 0; i < bars_per_visualiser; i++) { //0.03% of extra bar length to make it a little faster when bar is almost at it's minimum frequencyAmplitudes[i] -= decayFactor * (frequencyAmplitudes[i] + 0.03f); @@ -128,7 +128,7 @@ namespace osu.Game.Screens.Menu protected override DrawNode CreateDrawNode() => new VisualisationDrawNode(); - private readonly VisualizerSharedData sharedData = new VisualizerSharedData(); + private readonly VisualiserSharedData sharedData = new VisualiserSharedData(); protected override void ApplyDrawNode(DrawNode node) { base.ApplyDrawNode(node); @@ -143,7 +143,7 @@ namespace osu.Game.Screens.Menu visNode.AudioData = frequencyAmplitudes; } - private class VisualizerSharedData + private class VisualiserSharedData { public readonly LinearBatch VertexBatch = new LinearBatch(100 * 4, 10, PrimitiveType.Quads); } @@ -152,7 +152,7 @@ namespace osu.Game.Screens.Menu { public Shader Shader; public Texture Texture; - public VisualizerSharedData Shared; + public VisualiserSharedData Shared; //Asuming the logo is a circle, we don't need a second dimension. public float Size; @@ -175,15 +175,15 @@ namespace osu.Game.Screens.Menu { for (int j = 0; j < visualiser_rounds; j++) { - for (int i = 0; i < bars_per_visualizer; i++) + for (int i = 0; i < bars_per_visualiser; i++) { - float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualizer * 360 + j * 360 / visualiser_rounds); + float rotation = MathHelper.DegreesToRadians(i / (float)bars_per_visualiser * 360 + j * 360 / visualiser_rounds); float rotationCos = (float)Math.Cos(rotation); float rotationSin = (float)Math.Sin(rotation); //taking the cos and sin to the 0..1 range var barPosition = new Vector2(rotationCos / 2 + 0.5f, rotationSin / 2 + 0.5f) * Size; - var barSize = new Vector2(Size * (float)Math.Sqrt(2 * (1 - Math.Cos(MathHelper.DegreesToRadians(360f / bars_per_visualizer)))) / 2f, bar_length * AudioData[i % bars_per_visualizer]); + var barSize = new Vector2(Size * (float)Math.Sqrt(2 * (1 - Math.Cos(MathHelper.DegreesToRadians(360f / bars_per_visualiser)))) / 2f, bar_length * AudioData[i % bars_per_visualiser]); //The distance between the position and the sides of the bar. var bottomOffset = new Vector2(-rotationSin * barSize.X / 2, rotationCos * barSize.X / 2); //The distance between the bottom side of the bar and the top side.