2023-01-11 21:03:49 +08:00
|
|
|
// 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;
|
2023-01-11 21:37:57 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Diagnostics;
|
2023-01-11 21:03:49 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2023-01-11 21:37:57 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Osu;
|
2023-01-11 21:03:49 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual.UserInterface
|
|
|
|
{
|
|
|
|
public partial class TestSceneSegmentedGraph : OsuTestScene
|
|
|
|
{
|
|
|
|
private readonly SegmentedGraph<int> graph;
|
|
|
|
|
|
|
|
public TestSceneSegmentedGraph()
|
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
2023-01-12 17:13:16 +08:00
|
|
|
graph = new SegmentedGraph<int>(6)
|
2023-01-11 21:03:49 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Size = new Vector2(1, 0.5f),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2023-01-12 17:13:16 +08:00
|
|
|
graph.TierColours = new[]
|
2023-01-11 21:03:49 +08:00
|
|
|
{
|
2023-01-12 17:13:16 +08:00
|
|
|
Colour4.Red,
|
|
|
|
Colour4.OrangeRed,
|
|
|
|
Colour4.Orange,
|
|
|
|
Colour4.Yellow,
|
|
|
|
Colour4.YellowGreen,
|
|
|
|
Colour4.Green
|
|
|
|
};
|
2023-01-11 21:03:49 +08:00
|
|
|
|
|
|
|
AddStep("values from 1-10", () => graph.Values = Enumerable.Range(1, 10).ToArray());
|
|
|
|
AddStep("values from 1-100", () => graph.Values = Enumerable.Range(1, 100).ToArray());
|
|
|
|
AddStep("values from 1-500", () => graph.Values = Enumerable.Range(1, 500).ToArray());
|
|
|
|
AddStep("sin() function of size 100", () => sinFunction());
|
|
|
|
AddStep("sin() function of size 500", () => sinFunction(500));
|
|
|
|
AddStep("bumps of size 100", () => bumps());
|
|
|
|
AddStep("bumps of size 500", () => bumps(500));
|
|
|
|
AddStep("100 random values", () => randomValues());
|
|
|
|
AddStep("500 random values", () => randomValues(500));
|
2023-01-11 21:37:57 +08:00
|
|
|
AddStep("beatmap density with granularity of 200", () => beatmapDensity());
|
|
|
|
AddStep("beatmap density with granularity of 300", () => beatmapDensity(300));
|
2023-01-11 21:03:49 +08:00
|
|
|
AddStep("reversed values from 1-10", () => graph.Values = Enumerable.Range(1, 10).Reverse().ToArray());
|
2023-01-12 17:57:12 +08:00
|
|
|
AddStep("change colour", () =>
|
|
|
|
{
|
|
|
|
graph.TierColours = new[]
|
|
|
|
{
|
|
|
|
Colour4.White,
|
|
|
|
Colour4.LightBlue,
|
|
|
|
Colour4.Aqua,
|
|
|
|
Colour4.Blue
|
|
|
|
};
|
|
|
|
});
|
|
|
|
AddStep("reset colour", () =>
|
|
|
|
{
|
|
|
|
graph.TierColours = new[]
|
|
|
|
{
|
|
|
|
Colour4.Red,
|
|
|
|
Colour4.OrangeRed,
|
|
|
|
Colour4.Orange,
|
|
|
|
Colour4.Yellow,
|
|
|
|
Colour4.YellowGreen,
|
|
|
|
Colour4.Green
|
|
|
|
};
|
|
|
|
});
|
2023-01-11 21:03:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private void sinFunction(int size = 100)
|
|
|
|
{
|
|
|
|
const int max_value = 255;
|
2023-01-12 09:36:35 +08:00
|
|
|
graph.Values = new int[size];
|
2023-01-11 21:03:49 +08:00
|
|
|
|
|
|
|
float step = 2 * MathF.PI / size;
|
|
|
|
float x = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2023-01-12 09:36:35 +08:00
|
|
|
graph.Values[i] = (int)(max_value * MathF.Sin(x));
|
2023-01-11 21:03:49 +08:00
|
|
|
x += step;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void bumps(int size = 100)
|
|
|
|
{
|
|
|
|
const int max_value = 255;
|
2023-01-12 09:36:35 +08:00
|
|
|
graph.Values = new int[size];
|
2023-01-11 21:03:49 +08:00
|
|
|
|
|
|
|
float step = 2 * MathF.PI / size;
|
|
|
|
float x = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2023-01-12 09:36:35 +08:00
|
|
|
graph.Values[i] = (int)(max_value * Math.Abs(MathF.Sin(x)));
|
2023-01-11 21:03:49 +08:00
|
|
|
x += step;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void randomValues(int size = 100)
|
|
|
|
{
|
|
|
|
Random rng = new Random();
|
|
|
|
|
2023-01-12 09:36:35 +08:00
|
|
|
graph.Values = new int[size];
|
2023-01-11 21:03:49 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < size; i++)
|
|
|
|
{
|
2023-01-12 09:36:35 +08:00
|
|
|
graph.Values[i] = rng.Next(255);
|
2023-01-11 21:03:49 +08:00
|
|
|
}
|
|
|
|
}
|
2023-01-11 21:37:57 +08:00
|
|
|
|
|
|
|
private void beatmapDensity(int granularity = 200)
|
|
|
|
{
|
|
|
|
var ruleset = new OsuRuleset();
|
|
|
|
var beatmap = CreateBeatmap(ruleset.RulesetInfo);
|
|
|
|
IEnumerable<HitObject> objects = beatmap.HitObjects;
|
|
|
|
|
|
|
|
// Taken from SongProgressGraph
|
2023-01-12 09:36:35 +08:00
|
|
|
graph.Values = new int[granularity];
|
2023-01-11 21:37:57 +08:00
|
|
|
|
|
|
|
if (!objects.Any())
|
|
|
|
return;
|
|
|
|
|
|
|
|
double firstHit = objects.First().StartTime;
|
|
|
|
double lastHit = objects.Max(o => o.GetEndTime());
|
|
|
|
|
|
|
|
if (lastHit == 0)
|
|
|
|
lastHit = objects.Last().StartTime;
|
|
|
|
|
|
|
|
double interval = (lastHit - firstHit + 1) / granularity;
|
|
|
|
|
|
|
|
foreach (var h in objects)
|
|
|
|
{
|
|
|
|
double endTime = h.GetEndTime();
|
|
|
|
|
|
|
|
Debug.Assert(endTime >= h.StartTime);
|
|
|
|
|
|
|
|
int startRange = (int)((h.StartTime - firstHit) / interval);
|
|
|
|
int endRange = (int)((endTime - firstHit) / interval);
|
|
|
|
for (int i = startRange; i <= endRange; i++)
|
2023-01-12 09:36:35 +08:00
|
|
|
graph.Values[i]++;
|
2023-01-11 21:37:57 +08:00
|
|
|
}
|
|
|
|
}
|
2023-01-11 21:03:49 +08:00
|
|
|
}
|
|
|
|
}
|