1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 09:27:29 +08:00

Split out types

This commit is contained in:
smoogipoo 2020-06-15 21:48:59 +09:00
parent 41cec2c216
commit f9db37a1de
6 changed files with 344 additions and 321 deletions

View File

@ -7,7 +7,6 @@ using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Osu.Judgements;
using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring;
namespace osu.Game.Rulesets.Osu.Scoring
{
@ -62,11 +61,6 @@ namespace osu.Game.Rulesets.Osu.Scoring
}
}
public override void PopulateScore(ScoreInfo score)
{
base.PopulateScore(score);
}
protected override void Reset(bool storeResults)
{
base.Reset(storeResults);
@ -78,16 +72,4 @@ namespace osu.Game.Rulesets.Osu.Scoring
public override HitWindows CreateHitWindows() => new OsuHitWindows();
}
public class TimingDistribution
{
public readonly int[] Bins;
public readonly double BinSize;
public TimingDistribution(int binCount, double binSize)
{
Bins = new int[binCount];
BinSize = binSize;
}
}
}

View File

@ -0,0 +1,17 @@
// 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.
namespace osu.Game.Rulesets.Osu.Scoring
{
public class TimingDistribution
{
public readonly int[] Bins;
public readonly double BinSize;
public TimingDistribution(int binCount, double binSize)
{
Bins = new int[binCount];
BinSize = binSize;
}
}
}

View File

@ -0,0 +1,186 @@
// 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 System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Statistics
{
public class Heatmap : CompositeDrawable
{
/// <summary>
/// Full size of the heatmap.
/// </summary>
private const float size = 130;
/// <summary>
/// Size of the inner circle containing the "hit" points, relative to <see cref="size"/>.
/// All other points outside of the inner circle are "miss" points.
/// </summary>
private const float inner_portion = 0.8f;
private const float rotation = 45;
private const float point_size = 4;
private Container<HitPoint> allPoints;
public Heatmap()
{
Size = new Vector2(size);
}
[BackgroundDependencyLoader]
private void load()
{
InternalChildren = new Drawable[]
{
new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(inner_portion),
Masking = true,
BorderThickness = 2f,
BorderColour = Color4.White,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#202624")
}
},
new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new Drawable[]
{
new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Y,
Height = 2, // We're rotating along a diagonal - we don't really care how big this is.
Width = 1f,
Rotation = -rotation,
Alpha = 0.3f,
},
new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Y,
Height = 2, // We're rotating along a diagonal - we don't really care how big this is.
Width = 1f,
Rotation = rotation
},
new Box
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Width = 10,
Height = 2f,
},
new Box
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Y = -1,
Width = 2f,
Height = 10,
}
}
},
allPoints = new Container<HitPoint> { RelativeSizeAxes = Axes.Both }
};
Vector2 centre = new Vector2(size / 2);
int rows = (int)Math.Ceiling(size / point_size);
int cols = (int)Math.Ceiling(size / point_size);
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < cols; c++)
{
Vector2 pos = new Vector2(c * point_size, r * point_size);
HitPointType pointType = HitPointType.Hit;
if (Vector2.Distance(pos, centre) > size * inner_portion / 2)
pointType = HitPointType.Miss;
allPoints.Add(new HitPoint(pos, pointType)
{
Size = new Vector2(point_size),
Colour = pointType == HitPointType.Hit ? new Color4(102, 255, 204, 255) : new Color4(255, 102, 102, 255)
});
}
}
}
public void AddPoint(Vector2 start, Vector2 end, Vector2 hitPoint, float radius)
{
double angle1 = Math.Atan2(end.Y - hitPoint.Y, hitPoint.X - end.X); // Angle between the end point and the hit point.
double angle2 = Math.Atan2(end.Y - start.Y, start.X - end.X); // Angle between the end point and the start point.
double finalAngle = angle2 - angle1; // Angle between start, end, and hit points.
float normalisedDistance = Vector2.Distance(hitPoint, end) / radius;
// Find the most relevant hit point.
double minDist = double.PositiveInfinity;
HitPoint point = null;
foreach (var p in allPoints)
{
Vector2 localCentre = new Vector2(size / 2);
float localRadius = localCentre.X * inner_portion * normalisedDistance;
double localAngle = finalAngle + 3 * Math.PI / 4;
Vector2 localPoint = localCentre + localRadius * new Vector2((float)Math.Cos(localAngle), (float)Math.Sin(localAngle));
float dist = Vector2.Distance(p.DrawPosition + p.DrawSize / 2, localPoint);
if (dist < minDist)
{
minDist = dist;
point = p;
}
}
Debug.Assert(point != null);
point.Increment();
}
private class HitPoint : Circle
{
private readonly HitPointType pointType;
public HitPoint(Vector2 position, HitPointType pointType)
{
this.pointType = pointType;
Position = position;
Alpha = 0;
}
public void Increment()
{
if (Alpha < 1)
Alpha += 0.1f;
else if (pointType == HitPointType.Hit)
Colour = ((Color4)Colour).Lighten(0.1f);
}
}
private enum HitPointType
{
Hit,
Miss
}
}
}

View File

@ -0,0 +1,139 @@
// 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.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Osu.Scoring;
namespace osu.Game.Rulesets.Osu.Statistics
{
public class TimingDistributionGraph : CompositeDrawable
{
/// <summary>
/// The number of data points shown on the axis below the graph.
/// </summary>
private const float axis_points = 5;
/// <summary>
/// An amount to adjust the value of the axis points by, effectively insetting the axis in the graph.
/// Without an inset, the final data point will be placed halfway outside the graph.
/// </summary>
private const float axis_value_inset = 0.2f;
private readonly TimingDistribution distribution;
public TimingDistributionGraph(TimingDistribution distribution)
{
this.distribution = distribution;
}
[BackgroundDependencyLoader]
private void load()
{
int maxCount = distribution.Bins.Max();
var bars = new Drawable[distribution.Bins.Length];
for (int i = 0; i < bars.Length; i++)
bars[i] = new Bar { Height = (float)distribution.Bins[i] / maxCount };
Container axisFlow;
InternalChild = new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[] { bars }
}
},
new Drawable[]
{
axisFlow = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y
}
},
},
RowDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
}
};
// We know the total number of bins on each side of the centre ((n - 1) / 2), and the size of each bin.
// So our axis will contain one centre element + 5 points on each side, each with a value depending on the number of bins * bin size.
int sideBins = (distribution.Bins.Length - 1) / 2;
double maxValue = sideBins * distribution.BinSize;
double axisValueStep = maxValue / axis_points * (1 - axis_value_inset);
axisFlow.Add(new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "0",
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)
});
for (int i = 1; i <= axis_points; i++)
{
double axisValue = i * axisValueStep;
float position = (float)(axisValue / maxValue);
float alpha = 1f - position * 0.8f;
axisFlow.Add(new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativePositionAxes = Axes.X,
X = -position / 2,
Alpha = alpha,
Text = axisValue.ToString("-0"),
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)
});
axisFlow.Add(new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativePositionAxes = Axes.X,
X = position / 2,
Alpha = alpha,
Text = axisValue.ToString("+0"),
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)
});
}
}
private class Bar : CompositeDrawable
{
public Bar()
{
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
RelativeSizeAxes = Axes.Both;
Padding = new MarginPadding { Horizontal = 1 };
InternalChild = new Circle
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#66FFCC")
};
}
}
}
}

View File

@ -1,15 +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 System;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Rulesets.Osu.Statistics;
using osuTK;
using osuTK.Graphics;
@ -70,177 +68,6 @@ namespace osu.Game.Tests.Visual.Ranking
return true;
}
private class Heatmap : CompositeDrawable
{
/// <summary>
/// Full size of the heatmap.
/// </summary>
private const float size = 130;
/// <summary>
/// Size of the inner circle containing the "hit" points, relative to <see cref="size"/>.
/// All other points outside of the inner circle are "miss" points.
/// </summary>
private const float inner_portion = 0.8f;
private const float rotation = 45;
private const float point_size = 4;
private Container<HitPoint> allPoints;
public Heatmap()
{
Size = new Vector2(size);
}
[BackgroundDependencyLoader]
private void load()
{
InternalChildren = new Drawable[]
{
new CircularContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(inner_portion),
Masking = true,
BorderThickness = 2f,
BorderColour = Color4.White,
Child = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#202624")
}
},
new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Children = new Drawable[]
{
new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Y,
Height = 2, // We're rotating along a diagonal - we don't really care how big this is.
Width = 1f,
Rotation = -rotation,
Alpha = 0.3f,
},
new Box
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Y,
Height = 2, // We're rotating along a diagonal - we don't really care how big this is.
Width = 1f,
Rotation = rotation
},
new Box
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Width = 10,
Height = 2f,
},
new Box
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Y = -1,
Width = 2f,
Height = 10,
}
}
},
allPoints = new Container<HitPoint> { RelativeSizeAxes = Axes.Both }
};
Vector2 centre = new Vector2(size / 2);
int rows = (int)Math.Ceiling(size / point_size);
int cols = (int)Math.Ceiling(size / point_size);
for (int r = 0; r < rows; r++)
{
for (int c = 0; c < cols; c++)
{
Vector2 pos = new Vector2(c * point_size, r * point_size);
HitPointType pointType = HitPointType.Hit;
if (Vector2.Distance(pos, centre) > size * inner_portion / 2)
pointType = HitPointType.Miss;
allPoints.Add(new HitPoint(pos, pointType)
{
Size = new Vector2(point_size),
Colour = pointType == HitPointType.Hit ? new Color4(102, 255, 204, 255) : new Color4(255, 102, 102, 255)
});
}
}
}
public void AddPoint(Vector2 start, Vector2 end, Vector2 hitPoint, float radius)
{
double angle1 = Math.Atan2(end.Y - hitPoint.Y, hitPoint.X - end.X); // Angle between the end point and the hit point.
double angle2 = Math.Atan2(end.Y - start.Y, start.X - end.X); // Angle between the end point and the start point.
double finalAngle = angle2 - angle1; // Angle between start, end, and hit points.
float normalisedDistance = Vector2.Distance(hitPoint, end) / radius;
// Find the most relevant hit point.
double minDist = double.PositiveInfinity;
HitPoint point = null;
foreach (var p in allPoints)
{
Vector2 localCentre = new Vector2(size / 2);
float localRadius = localCentre.X * inner_portion * normalisedDistance;
double localAngle = finalAngle + 3 * Math.PI / 4;
Vector2 localPoint = localCentre + localRadius * new Vector2((float)Math.Cos(localAngle), (float)Math.Sin(localAngle));
float dist = Vector2.Distance(p.DrawPosition + p.DrawSize / 2, localPoint);
if (dist < minDist)
{
minDist = dist;
point = p;
}
}
Debug.Assert(point != null);
point.Increment();
}
}
private class HitPoint : Circle
{
private readonly HitPointType pointType;
public HitPoint(Vector2 position, HitPointType pointType)
{
this.pointType = pointType;
Position = position;
Alpha = 0;
}
public void Increment()
{
if (Alpha < 1)
Alpha += 0.1f;
else if (pointType == HitPointType.Hit)
Colour = ((Color4)Colour).Lighten(0.1f);
}
}
private enum HitPointType
{
Hit,
Miss
}
private class BorderCircle : CircularContainer
{
public BorderCircle()

View File

@ -2,15 +2,11 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Osu.Scoring;
using osu.Game.Rulesets.Osu.Statistics;
using osuTK;
namespace osu.Game.Tests.Visual.Ranking
@ -65,128 +61,4 @@ namespace osu.Game.Tests.Visual.Ranking
return distribution;
}
}
public class TimingDistributionGraph : CompositeDrawable
{
/// <summary>
/// The number of data points shown on the axis below the graph.
/// </summary>
private const float axis_points = 5;
/// <summary>
/// An amount to adjust the value of the axis points by, effectively insetting the axis in the graph.
/// Without an inset, the final data point will be placed halfway outside the graph.
/// </summary>
private const float axis_value_inset = 0.2f;
private readonly TimingDistribution distribution;
public TimingDistributionGraph(TimingDistribution distribution)
{
this.distribution = distribution;
}
[BackgroundDependencyLoader]
private void load()
{
int maxCount = distribution.Bins.Max();
var bars = new Drawable[distribution.Bins.Length];
for (int i = 0; i < bars.Length; i++)
bars[i] = new Bar { Height = (float)distribution.Bins[i] / maxCount };
Container axisFlow;
InternalChild = new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[]
{
new Drawable[]
{
new GridContainer
{
RelativeSizeAxes = Axes.Both,
Content = new[] { bars }
}
},
new Drawable[]
{
axisFlow = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y
}
},
},
RowDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
}
};
// We know the total number of bins on each side of the centre ((n - 1) / 2), and the size of each bin.
// So our axis will contain one centre element + 5 points on each side, each with a value depending on the number of bins * bin size.
int sideBins = (distribution.Bins.Length - 1) / 2;
double maxValue = sideBins * distribution.BinSize;
double axisValueStep = maxValue / axis_points * (1 - axis_value_inset);
axisFlow.Add(new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Text = "0",
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)
});
for (int i = 1; i <= axis_points; i++)
{
double axisValue = i * axisValueStep;
float position = (float)(axisValue / maxValue);
float alpha = 1f - position * 0.8f;
axisFlow.Add(new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativePositionAxes = Axes.X,
X = -position / 2,
Alpha = alpha,
Text = axisValue.ToString("-0"),
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)
});
axisFlow.Add(new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativePositionAxes = Axes.X,
X = position / 2,
Alpha = alpha,
Text = axisValue.ToString("+0"),
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold)
});
}
}
private class Bar : CompositeDrawable
{
public Bar()
{
Anchor = Anchor.BottomCentre;
Origin = Anchor.BottomCentre;
RelativeSizeAxes = Axes.Both;
Padding = new MarginPadding { Horizontal = 1 };
InternalChild = new Circle
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#66FFCC")
};
}
}
}
}