forked from ppy/osu-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ppy#5927 from peppy/performance-tests-cleanup
Refactor performance test scenes
- Loading branch information
Showing
12 changed files
with
230 additions
and
233 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 50 additions & 4 deletions
54
osu.Framework.Tests/Visual/Performance/PerformanceTestScene.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,87 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System; | ||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Configuration; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Utils; | ||
using osuTK; | ||
using osuTK.Graphics; | ||
|
||
namespace osu.Framework.Tests.Visual.Performance | ||
{ | ||
public abstract partial class PerformanceTestScene : FrameworkTestScene | ||
{ | ||
protected override Container<Drawable> Content => content; | ||
|
||
private BufferedContainer content = null!; | ||
private Container content = null!; | ||
|
||
private bool rotation; | ||
private bool cycleColour; | ||
|
||
[Resolved] | ||
private FrameworkDebugConfigManager debugConfig { get; set; } = null!; | ||
|
||
private Bindable<bool> bypassFrontToBack = null!; | ||
|
||
private BufferedContainer buffer = null!; | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
|
||
bypassFrontToBack = debugConfig.GetBindable<bool>(DebugSetting.BypassFrontToBackPass); | ||
|
||
base.Content.Child = content = new BufferedContainer | ||
base.Content.Child = buffer = new BufferedContainer(pixelSnapping: true) | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Child = content = new Container | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
}, | ||
}; | ||
|
||
AddLabel("General"); | ||
|
||
AddStep("do nothing", () => { }); | ||
|
||
AddToggleStep("hide content", v => Content.Alpha = v ? 0 : 1); | ||
AddToggleStep("bypass front to back", v => bypassFrontToBack.Value = v); | ||
AddSliderStep("render scale", 0.01f, 1f, 1f, v => content.FrameBufferScale = new Vector2(v)); | ||
AddToggleStep("enable front to back", v => bypassFrontToBack.Value = !v); | ||
AddSliderStep("render scale", 0.01f, 1f, 1f, v => buffer.FrameBufferScale = new Vector2(v)); | ||
AddToggleStep("rotate everything", v => rotation = v); | ||
AddToggleStep("cycle colour", v => cycleColour = v); | ||
} | ||
|
||
protected override void Update() | ||
{ | ||
base.Update(); | ||
|
||
if (rotation) | ||
{ | ||
content.Rotation += (float)Time.Elapsed * 0.01f; | ||
content.Scale = new Vector2(0.5f); | ||
} | ||
else | ||
{ | ||
content.Scale = Vector2.One; | ||
content.Rotation = 0; | ||
} | ||
|
||
if (cycleColour) | ||
{ | ||
var col = Interpolation.ValueAt((MathF.Sin((float)Time.Current / 1000) + 1) / 2, Color4.Red, Color4.SkyBlue, 0f, 1f); | ||
|
||
content.Colour = col; | ||
} | ||
else | ||
{ | ||
content.Colour = Color4.White; | ||
} | ||
} | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
osu.Framework.Tests/Visual/Performance/RepeatedDrawablePerformanceTestScene.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using System.Linq; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Colour; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Utils; | ||
using osuTK; | ||
using osuTK.Graphics; | ||
|
||
namespace osu.Framework.Tests.Visual.Performance | ||
{ | ||
public abstract partial class RepeatedDrawablePerformanceTestScene : PerformanceTestScene | ||
{ | ||
protected readonly BindableFloat DrawableSize = new BindableFloat(); | ||
protected readonly BindableInt DrawableCount = new BindableInt(); | ||
protected readonly BindableBool GradientColour = new BindableBool(); | ||
protected readonly BindableBool RandomiseColour = new BindableBool(); | ||
|
||
public FillFlowContainer Flow { get; private set; } = null!; | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
|
||
AddLabel("Drawables"); | ||
|
||
AddSliderStep("size", 1f, 128f, 20f, v => DrawableSize.Value = v); | ||
AddSliderStep("count", 1, 10000, 1000, v => DrawableCount.Value = v); | ||
|
||
AddToggleStep("gradient colour", v => GradientColour.Value = v); | ||
AddToggleStep("randomise colour", v => RandomiseColour.Value = v); | ||
|
||
Child = Flow = new FillFlowContainer | ||
{ | ||
RelativeSizeAxes = Axes.X, | ||
AutoSizeAxes = Axes.Y, | ||
Anchor = Anchor.Centre, | ||
Origin = Anchor.Centre, | ||
Padding = new MarginPadding(20f), | ||
Spacing = new Vector2(5f), | ||
}; | ||
|
||
DrawableCount.BindValueChanged(_ => adjustDrawableCount(), true); | ||
|
||
DrawableSize.BindValueChanged(_ => updateMetrics()); | ||
GradientColour.BindValueChanged(_ => updateMetrics()); | ||
RandomiseColour.BindValueChanged(_ => updateMetrics()); | ||
} | ||
|
||
protected void Recreate() | ||
{ | ||
Flow.Clear(); | ||
adjustDrawableCount(); | ||
} | ||
|
||
protected abstract Drawable CreateDrawable(); | ||
|
||
private void adjustDrawableCount() | ||
{ | ||
while (Flow.Count > DrawableCount.Value) | ||
Flow.Remove(Flow.Children.Last(), true); | ||
|
||
while (Flow.Count < DrawableCount.Value) | ||
{ | ||
var drawable = CreateDrawable(); | ||
updateMetrics(drawable); | ||
Flow.Add(drawable); | ||
} | ||
} | ||
|
||
private void updateMetrics() | ||
{ | ||
foreach (var b in Flow) | ||
updateMetrics(b); | ||
} | ||
|
||
private void updateMetrics(Drawable drawable) | ||
{ | ||
drawable.Size = new Vector2(DrawableSize.Value); | ||
|
||
if (GradientColour.Value) | ||
{ | ||
drawable.Colour = new ColourInfo | ||
{ | ||
TopLeft = RandomiseColour.Value ? getRandomColour() : Color4.Red, | ||
TopRight = RandomiseColour.Value ? getRandomColour() : Color4.Blue, | ||
BottomLeft = RandomiseColour.Value ? getRandomColour() : Color4.Green, | ||
BottomRight = RandomiseColour.Value ? getRandomColour() : Color4.Yellow | ||
}; | ||
} | ||
else | ||
drawable.Colour = RandomiseColour.Value ? getRandomColour() : Color4.White; | ||
} | ||
|
||
private Colour4 getRandomColour() => new Colour4(RNG.NextSingle(), RNG.NextSingle(), RNG.NextSingle(), 1f); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 3 additions & 100 deletions
103
osu.Framework.Tests/Visual/Performance/TestSceneBoxPerformance.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,110 +1,13 @@ | ||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. | ||
// See the LICENCE file in the repository root for full licence text. | ||
|
||
using osu.Framework.Allocation; | ||
using osu.Framework.Bindables; | ||
using osu.Framework.Graphics; | ||
using osu.Framework.Graphics.Colour; | ||
using osu.Framework.Graphics.Containers; | ||
using osu.Framework.Graphics.Rendering; | ||
using osu.Framework.Graphics.Sprites; | ||
using osu.Framework.Utils; | ||
using osuTK; | ||
using osuTK.Graphics; | ||
using osu.Framework.Graphics.Shapes; | ||
|
||
namespace osu.Framework.Tests.Visual.Performance | ||
{ | ||
public partial class TestSceneBoxPerformance : PerformanceTestScene | ||
public sealed partial class TestSceneBoxPerformance : RepeatedDrawablePerformanceTestScene | ||
{ | ||
protected readonly BindableFloat FillWidth = new BindableFloat(); | ||
protected readonly BindableFloat FillHeight = new BindableFloat(); | ||
protected readonly BindableInt SpritesCount = new BindableInt(); | ||
protected readonly BindableBool GradientColour = new BindableBool(); | ||
protected readonly BindableBool RandomiseColour = new BindableBool(); | ||
|
||
public FillFlowContainer Flow { get; private set; } = null!; | ||
|
||
protected override void LoadComplete() | ||
{ | ||
base.LoadComplete(); | ||
|
||
AddLabel("Boxes"); | ||
AddSliderStep("fill width", 0.01f, 1.0f, 0.1f, v => FillWidth.Value = v); | ||
AddSliderStep("fill height", 0.01f, 1.0f, 0.1f, v => FillHeight.Value = v); | ||
AddSliderStep("sprites count", 1, 1000, 100, v => SpritesCount.Value = v); | ||
AddToggleStep("gradient colour", v => GradientColour.Value = v); | ||
AddToggleStep("randomise colour", v => RandomiseColour.Value = v); | ||
|
||
Child = Flow = new FillFlowContainer | ||
{ | ||
RelativeSizeAxes = Axes.Both, | ||
Padding = new MarginPadding(20f), | ||
Spacing = new Vector2(20f), | ||
}; | ||
|
||
SpritesCount.BindValueChanged(v => | ||
{ | ||
for (int i = v.OldValue - 1; i >= v.NewValue; i--) | ||
Flow.Remove(Flow.Children[i], true); | ||
for (int i = v.OldValue; i < v.NewValue; i++) | ||
Flow.Add(CreateDrawable()); | ||
}, true); | ||
} | ||
|
||
protected void Recreate() | ||
{ | ||
Flow.Clear(); | ||
|
||
for (int i = 0; i < SpritesCount.Value; i++) | ||
Flow.Add(CreateDrawable()); | ||
} | ||
|
||
protected virtual Drawable CreateDrawable() => new TestBox | ||
{ | ||
FillWidth = { BindTarget = FillWidth }, | ||
FillHeight = { BindTarget = FillHeight }, | ||
GradientColour = { BindTarget = GradientColour }, | ||
RandomiseColour = { BindTarget = RandomiseColour }, | ||
}; | ||
|
||
protected partial class TestBox : Sprite | ||
{ | ||
public readonly IBindable<float> FillWidth = new BindableFloat(); | ||
public readonly IBindable<float> FillHeight = new BindableFloat(); | ||
public readonly IBindable<bool> GradientColour = new BindableBool(); | ||
public readonly IBindable<bool> RandomiseColour = new BindableBool(); | ||
|
||
[BackgroundDependencyLoader] | ||
private void load(IRenderer renderer) | ||
{ | ||
RelativeSizeAxes = Axes.Both; | ||
Texture = renderer.WhitePixel; | ||
|
||
FillWidth.BindValueChanged(v => Width = v.NewValue, true); | ||
FillHeight.BindValueChanged(v => Height = v.NewValue, true); | ||
|
||
RandomiseColour.BindValueChanged(_ => updateColour()); | ||
GradientColour.BindValueChanged(_ => updateColour(), true); | ||
|
||
void updateColour() | ||
{ | ||
if (GradientColour.Value) | ||
{ | ||
Colour = new ColourInfo | ||
{ | ||
TopLeft = RandomiseColour.Value ? getRandomColour() : Color4.Red, | ||
TopRight = RandomiseColour.Value ? getRandomColour() : Color4.Blue, | ||
BottomLeft = RandomiseColour.Value ? getRandomColour() : Color4.Green, | ||
BottomRight = RandomiseColour.Value ? getRandomColour() : Color4.Yellow | ||
}; | ||
} | ||
else | ||
Colour = RandomiseColour.Value ? getRandomColour() : Color4.White; | ||
} | ||
} | ||
|
||
private Colour4 getRandomColour() => new Colour4(RNG.NextSingle(), RNG.NextSingle(), RNG.NextSingle(), 1f); | ||
} | ||
protected override Drawable CreateDrawable() => new Box(); | ||
} | ||
} |
Oops, something went wrong.