mirror of
https://github.com/osukey/osukey.git
synced 2025-08-03 22:56:36 +09:00
Merge remote-tracking branch 'origin/master' into generic_judgements_2
Conflicts: osu.Desktop.VisualTests/Tests/TestCaseHitObjects.cs osu.Game.Modes.Catch/UI/CatchHitRenderer.cs osu.Game.Modes.Mania/UI/ManiaHitRenderer.cs osu.Game.Modes.Mania/osu.Game.Modes.Mania.csproj osu.Game.Modes.Osu/Objects/Drawables/DrawableSlider.cs osu.Game.Modes.Osu/Objects/Drawables/DrawableSpinner.cs osu.Game.Modes.Osu/UI/OsuHitRenderer.cs osu.Game.Modes.Taiko/UI/TaikoHitRenderer.cs osu.Game.Modes.Taiko/osu.Game.Modes.Taiko.csproj osu.Game/Modes/Objects/Drawables/DrawableHitObject.cs osu.Game/Modes/UI/HitRenderer.cs osu.Game/osu.Game.csproj
This commit is contained in:
@ -1,150 +0,0 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Modes.Osu.Objects
|
||||
{
|
||||
public class BezierApproximator
|
||||
{
|
||||
private int count;
|
||||
private List<Vector2> controlPoints;
|
||||
private Vector2[] subdivisionBuffer1;
|
||||
private Vector2[] subdivisionBuffer2;
|
||||
|
||||
private const float tolerance = 0.25f;
|
||||
private const float tolerance_sq = tolerance * tolerance;
|
||||
|
||||
public BezierApproximator(List<Vector2> controlPoints)
|
||||
{
|
||||
this.controlPoints = controlPoints;
|
||||
count = controlPoints.Count;
|
||||
|
||||
subdivisionBuffer1 = new Vector2[count];
|
||||
subdivisionBuffer2 = new Vector2[count * 2 - 1];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Make sure the 2nd order derivative (approximated using finite elements) is within tolerable bounds.
|
||||
/// NOTE: The 2nd order derivative of a 2d curve represents its curvature, so intuitively this function
|
||||
/// checks (as the name suggests) whether our approximation is _locally_ "flat". More curvy parts
|
||||
/// need to have a denser approximation to be more "flat".
|
||||
/// </summary>
|
||||
/// <param name="controlPoints">The control points to check for flatness.</param>
|
||||
/// <returns>Whether the control points are flat enough.</returns>
|
||||
private static bool isFlatEnough(Vector2[] controlPoints)
|
||||
{
|
||||
for (int i = 1; i < controlPoints.Length - 1; i++)
|
||||
if ((controlPoints[i - 1] - 2 * controlPoints[i] + controlPoints[i + 1]).LengthSquared > tolerance_sq * 4)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Subdivides n control points representing a bezier curve into 2 sets of n control points, each
|
||||
/// describing a bezier curve equivalent to a half of the original curve. Effectively this splits
|
||||
/// the original curve into 2 curves which result in the original curve when pieced back together.
|
||||
/// </summary>
|
||||
/// <param name="controlPoints">The control points to split.</param>
|
||||
/// <param name="l">Output: The control points corresponding to the left half of the curve.</param>
|
||||
/// <param name="r">Output: The control points corresponding to the right half of the curve.</param>
|
||||
private void subdivide(Vector2[] controlPoints, Vector2[] l, Vector2[] r)
|
||||
{
|
||||
Vector2[] midpoints = subdivisionBuffer1;
|
||||
|
||||
for (int i = 0; i < count; ++i)
|
||||
midpoints[i] = controlPoints[i];
|
||||
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
l[i] = midpoints[0];
|
||||
r[count - i - 1] = midpoints[count - i - 1];
|
||||
|
||||
for (int j = 0; j < count - i - 1; j++)
|
||||
midpoints[j] = (midpoints[j] + midpoints[j + 1]) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This uses <a href="https://en.wikipedia.org/wiki/De_Casteljau%27s_algorithm">De Casteljau's algorithm</a> to obtain an optimal
|
||||
/// piecewise-linear approximation of the bezier curve with the same amount of points as there are control points.
|
||||
/// </summary>
|
||||
/// <param name="controlPoints">The control points describing the bezier curve to be approximated.</param>
|
||||
/// <param name="output">The points representing the resulting piecewise-linear approximation.</param>
|
||||
private void approximate(Vector2[] controlPoints, List<Vector2> output)
|
||||
{
|
||||
Vector2[] l = subdivisionBuffer2;
|
||||
Vector2[] r = subdivisionBuffer1;
|
||||
|
||||
subdivide(controlPoints, l, r);
|
||||
|
||||
for (int i = 0; i < count - 1; ++i)
|
||||
l[count + i] = r[i + 1];
|
||||
|
||||
output.Add(controlPoints[0]);
|
||||
for (int i = 1; i < count - 1; ++i)
|
||||
{
|
||||
int index = 2 * i;
|
||||
Vector2 p = 0.25f * (l[index - 1] + 2 * l[index] + l[index + 1]);
|
||||
output.Add(p);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a piecewise-linear approximation of a bezier curve, by adaptively repeatedly subdividing
|
||||
/// the control points until their approximation error vanishes below a given threshold.
|
||||
/// </summary>
|
||||
/// <returns>A list of vectors representing the piecewise-linear approximation.</returns>
|
||||
public List<Vector2> CreateBezier()
|
||||
{
|
||||
List<Vector2> output = new List<Vector2>();
|
||||
|
||||
if (count == 0)
|
||||
return output;
|
||||
|
||||
Stack<Vector2[]> toFlatten = new Stack<Vector2[]>();
|
||||
Stack<Vector2[]> freeBuffers = new Stack<Vector2[]>();
|
||||
|
||||
// "toFlatten" contains all the curves which are not yet approximated well enough.
|
||||
// We use a stack to emulate recursion without the risk of running into a stack overflow.
|
||||
// (More specifically, we iteratively and adaptively refine our curve with a
|
||||
// <a href="https://en.wikipedia.org/wiki/Depth-first_search">Depth-first search</a>
|
||||
// over the tree resulting from the subdivisions we make.)
|
||||
toFlatten.Push(controlPoints.ToArray());
|
||||
|
||||
Vector2[] leftChild = subdivisionBuffer2;
|
||||
|
||||
while (toFlatten.Count > 0)
|
||||
{
|
||||
Vector2[] parent = toFlatten.Pop();
|
||||
if (isFlatEnough(parent))
|
||||
{
|
||||
// If the control points we currently operate on are sufficiently "flat", we use
|
||||
// an extension to De Casteljau's algorithm to obtain a piecewise-linear approximation
|
||||
// of the bezier curve represented by our control points, consisting of the same amount
|
||||
// of points as there are control points.
|
||||
approximate(parent, output);
|
||||
freeBuffers.Push(parent);
|
||||
continue;
|
||||
}
|
||||
|
||||
// If we do not yet have a sufficiently "flat" (in other words, detailed) approximation we keep
|
||||
// subdividing the curve we are currently operating on.
|
||||
Vector2[] rightChild = freeBuffers.Count > 0 ? freeBuffers.Pop() : new Vector2[count];
|
||||
subdivide(parent, leftChild, rightChild);
|
||||
|
||||
// We re-use the buffer of the parent for one of the children, so that we save one allocation per iteration.
|
||||
for (int i = 0; i < count; ++i)
|
||||
parent[i] = leftChild[i];
|
||||
|
||||
toFlatten.Push(rightChild);
|
||||
toFlatten.Push(parent);
|
||||
}
|
||||
|
||||
output.Add(controlPoints[count - 1]);
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,99 +0,0 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using OpenTK;
|
||||
using osu.Framework.MathUtils;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace osu.Game.Modes.Osu.Objects
|
||||
{
|
||||
public class CircularArcApproximator
|
||||
{
|
||||
private Vector2 a;
|
||||
private Vector2 b;
|
||||
private Vector2 c;
|
||||
|
||||
private int amountPoints;
|
||||
|
||||
private const float tolerance = 0.1f;
|
||||
|
||||
public CircularArcApproximator(Vector2 a, Vector2 b, Vector2 c)
|
||||
{
|
||||
this.a = a;
|
||||
this.b = b;
|
||||
this.c = c;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a piecewise-linear approximation of a circular arc curve.
|
||||
/// </summary>
|
||||
/// <returns>A list of vectors representing the piecewise-linear approximation.</returns>
|
||||
public List<Vector2> CreateArc()
|
||||
{
|
||||
float aSq = (b - c).LengthSquared;
|
||||
float bSq = (a - c).LengthSquared;
|
||||
float cSq = (a - b).LengthSquared;
|
||||
|
||||
// If we have a degenerate triangle where a side-length is almost zero, then give up and fall
|
||||
// back to a more numerically stable method.
|
||||
if (Precision.AlmostEquals(aSq, 0) || Precision.AlmostEquals(bSq, 0) || Precision.AlmostEquals(cSq, 0))
|
||||
return new List<Vector2>();
|
||||
|
||||
float s = aSq * (bSq + cSq - aSq);
|
||||
float t = bSq * (aSq + cSq - bSq);
|
||||
float u = cSq * (aSq + bSq - cSq);
|
||||
|
||||
float sum = s + t + u;
|
||||
|
||||
// If we have a degenerate triangle with an almost-zero size, then give up and fall
|
||||
// back to a more numerically stable method.
|
||||
if (Precision.AlmostEquals(sum, 0))
|
||||
return new List<Vector2>();
|
||||
|
||||
Vector2 centre = (s * a + t * b + u * c) / sum;
|
||||
Vector2 dA = a - centre;
|
||||
Vector2 dC = c - centre;
|
||||
|
||||
float r = dA.Length;
|
||||
|
||||
double thetaStart = Math.Atan2(dA.Y, dA.X);
|
||||
double thetaEnd = Math.Atan2(dC.Y, dC.X);
|
||||
|
||||
while (thetaEnd < thetaStart)
|
||||
thetaEnd += 2 * Math.PI;
|
||||
|
||||
double dir = 1;
|
||||
double thetaRange = thetaEnd - thetaStart;
|
||||
|
||||
// Decide in which direction to draw the circle, depending on which side of
|
||||
// AC B lies.
|
||||
Vector2 orthoAtoC = c - a;
|
||||
orthoAtoC = new Vector2(orthoAtoC.Y, -orthoAtoC.X);
|
||||
if (Vector2.Dot(orthoAtoC, b - a) < 0)
|
||||
{
|
||||
dir = -dir;
|
||||
thetaRange = 2 * Math.PI - thetaRange;
|
||||
}
|
||||
|
||||
// We select the amount of points for the approximation by requiring the discrete curvature
|
||||
// to be smaller than the provided tolerance. The exact angle required to meet the tolerance
|
||||
// is: 2 * Math.Acos(1 - TOLERANCE / r)
|
||||
// The special case is required for extremely short sliders where the radius is smaller than
|
||||
// the tolerance. This is a pathological rather than a realistic case.
|
||||
amountPoints = 2 * r <= tolerance ? 2 : Math.Max(2, (int)Math.Ceiling(thetaRange / (2 * Math.Acos(1 - tolerance / r))));
|
||||
|
||||
List<Vector2> output = new List<Vector2>(amountPoints);
|
||||
|
||||
for (int i = 0; i < amountPoints; ++i)
|
||||
{
|
||||
double fract = (double)i / (amountPoints - 1);
|
||||
double theta = thetaStart + dir * fract * thetaRange;
|
||||
Vector2 o = new Vector2((float)Math.Cos(theta), (float)Math.Sin(theta)) * r;
|
||||
output.Add(centre + o);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
using osu.Game.Modes.Objects.Types;
|
||||
|
||||
namespace osu.Game.Modes.Osu.Objects.Drawables.Connections
|
||||
{
|
||||
@ -63,7 +64,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables.Connections
|
||||
{
|
||||
Vector2 startPosition = prevHitObject.EndPosition;
|
||||
Vector2 endPosition = currHitObject.Position;
|
||||
double startTime = prevHitObject.EndTime;
|
||||
double startTime = (prevHitObject as IHasEndTime)?.EndTime ?? prevHitObject.StartTime;
|
||||
double endTime = currHitObject.StartTime;
|
||||
|
||||
Vector2 distanceVector = endPosition - startPosition;
|
||||
|
@ -7,6 +7,7 @@ using osu.Framework.Graphics.Transforms;
|
||||
using osu.Game.Modes.Objects.Drawables;
|
||||
using osu.Game.Modes.Osu.Objects.Drawables.Pieces;
|
||||
using OpenTK;
|
||||
using osu.Game.Modes.Objects.Types;
|
||||
|
||||
namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
{
|
||||
@ -35,11 +36,11 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
{
|
||||
glow = new GlowPiece
|
||||
{
|
||||
Colour = osuObject.Colour
|
||||
Colour = osuObject.ComboColour
|
||||
},
|
||||
circle = new CirclePiece
|
||||
{
|
||||
Colour = osuObject.Colour,
|
||||
Colour = osuObject.ComboColour,
|
||||
Hit = () =>
|
||||
{
|
||||
if (Judgement.Result.HasValue) return false;
|
||||
@ -57,11 +58,11 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
flash = new FlashPiece(),
|
||||
explode = new ExplodePiece
|
||||
{
|
||||
Colour = osuObject.Colour,
|
||||
Colour = osuObject.ComboColour,
|
||||
},
|
||||
ApproachCircle = new ApproachCircle
|
||||
{
|
||||
Colour = osuObject.Colour,
|
||||
Colour = osuObject.ComboColour,
|
||||
}
|
||||
};
|
||||
|
||||
@ -116,13 +117,16 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
|
||||
ApproachCircle.FadeOut();
|
||||
|
||||
glow.Delay(osuObject.Duration);
|
||||
double endTime = (osuObject as IHasEndTime)?.EndTime ?? osuObject.StartTime;
|
||||
double duration = endTime - osuObject.StartTime;
|
||||
|
||||
glow.Delay(duration);
|
||||
glow.FadeOut(400);
|
||||
|
||||
switch (state)
|
||||
{
|
||||
case ArmedState.Idle:
|
||||
Delay(osuObject.Duration + TIME_PREEMPT);
|
||||
Delay(duration + TIME_PREEMPT);
|
||||
FadeOut(TIME_FADEOUT);
|
||||
break;
|
||||
case ArmedState.Miss:
|
||||
|
@ -60,7 +60,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
Position = s.StackedPosition,
|
||||
ComboIndex = s.ComboIndex,
|
||||
Scale = s.Scale,
|
||||
Colour = s.Colour,
|
||||
ComboColour = s.ComboColour,
|
||||
Sample = s.Sample,
|
||||
}),
|
||||
};
|
||||
@ -72,7 +72,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
|
||||
AddNested(initialCircle);
|
||||
|
||||
var repeatDuration = s.Curve.Length / s.Velocity;
|
||||
var repeatDuration = s.Curve.Distance / s.Velocity;
|
||||
foreach (var tick in s.Ticks)
|
||||
{
|
||||
var repeatStartTime = s.StartTime + tick.RepeatIndex * repeatDuration;
|
||||
@ -104,7 +104,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
double progress = MathHelper.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
|
||||
|
||||
int repeat = slider.RepeatAt(progress);
|
||||
progress = slider.CurveProgressAt(progress);
|
||||
progress = slider.ProgressAt(progress);
|
||||
|
||||
if (repeat > currentRepeat)
|
||||
{
|
||||
@ -125,7 +125,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
|
||||
protected override void CheckJudgement(bool userTriggered)
|
||||
{
|
||||
if (!userTriggered && Time.Current >= HitObject.EndTime)
|
||||
if (!userTriggered && Time.Current >= slider.EndTime)
|
||||
{
|
||||
var ticksCount = ticks.Children.Count() + 1;
|
||||
var ticksHit = ticks.Children.Count(t => t.Judgement.Result == HitResult.Hit);
|
||||
@ -162,7 +162,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
|
||||
ball.FadeIn();
|
||||
|
||||
Delay(HitObject.Duration, true);
|
||||
Delay(slider.Duration, true);
|
||||
|
||||
body.FadeOut(160);
|
||||
ball.FadeOut(160);
|
||||
|
@ -48,7 +48,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
new Box
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Colour = sliderTick.Colour,
|
||||
Colour = sliderTick.ComboColour,
|
||||
Alpha = 0.3f,
|
||||
}
|
||||
};
|
||||
|
@ -46,7 +46,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
Alpha = 0,
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
DiscColour = s.Colour
|
||||
DiscColour = s.ComboColour
|
||||
},
|
||||
circleContainer = new Container
|
||||
{
|
||||
@ -80,7 +80,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
if (Progress >= 1)
|
||||
disc.Complete = true;
|
||||
|
||||
if (!userTriggered && Time.Current >= HitObject.EndTime)
|
||||
if (!userTriggered && Time.Current >= spinner.EndTime)
|
||||
{
|
||||
if (Progress >= 1)
|
||||
{
|
||||
@ -100,7 +100,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
else
|
||||
{
|
||||
Judgement.Score = OsuScoreResult.Miss;
|
||||
if (Time.Current >= HitObject.EndTime)
|
||||
if (Time.Current >= spinner.EndTime)
|
||||
Judgement.Result = HitResult.Miss;
|
||||
}
|
||||
}
|
||||
@ -138,7 +138,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables
|
||||
|
||||
base.UpdateState(state);
|
||||
|
||||
Delay(HitObject.Duration, true);
|
||||
Delay(spinner.Duration, true);
|
||||
|
||||
FadeOut(160);
|
||||
|
||||
|
@ -51,7 +51,7 @@ namespace osu.Game.Modes.Osu.Objects.Drawables.Pieces
|
||||
{
|
||||
new Box
|
||||
{
|
||||
Colour = slider.Colour,
|
||||
Colour = slider.ComboColour,
|
||||
Alpha = 0.4f,
|
||||
Width = width,
|
||||
Height = width,
|
||||
|
@ -110,10 +110,10 @@ namespace osu.Game.Modes.Osu.Objects.Drawables.Pieces
|
||||
{
|
||||
progress -= border_portion;
|
||||
|
||||
bytes[i * 4] = (byte)(slider.Colour.R * 255);
|
||||
bytes[i * 4 + 1] = (byte)(slider.Colour.G * 255);
|
||||
bytes[i * 4 + 2] = (byte)(slider.Colour.B * 255);
|
||||
bytes[i * 4 + 3] = (byte)((opacity_at_edge - (opacity_at_edge - opacity_at_centre) * progress / gradient_portion) * (slider.Colour.A * 255));
|
||||
bytes[i * 4] = (byte)(slider.ComboColour.R * 255);
|
||||
bytes[i * 4 + 1] = (byte)(slider.ComboColour.G * 255);
|
||||
bytes[i * 4 + 2] = (byte)(slider.ComboColour.B * 255);
|
||||
bytes[i * 4 + 3] = (byte)((opacity_at_edge - (opacity_at_edge - opacity_at_centre) * progress / gradient_portion) * (slider.ComboColour.A * 255));
|
||||
}
|
||||
}
|
||||
|
||||
|
13
osu.Game.Modes.Osu/Objects/HitObjectType.cs
Normal file
13
osu.Game.Modes.Osu/Objects/HitObjectType.cs
Normal file
@ -0,0 +1,13 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
namespace osu.Game.Modes.Osu.Objects
|
||||
{
|
||||
public enum HitObjectType
|
||||
{
|
||||
Circle,
|
||||
Slider,
|
||||
Spinner,
|
||||
SliderTick
|
||||
}
|
||||
}
|
@ -1,15 +1,16 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using osu.Game.Modes.Objects;
|
||||
using OpenTK;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Modes.Osu.Objects.Drawables;
|
||||
using osu.Game.Modes.Objects.Types;
|
||||
using OpenTK.Graphics;
|
||||
|
||||
namespace osu.Game.Modes.Osu.Objects
|
||||
{
|
||||
public abstract class OsuHitObject : HitObject
|
||||
public abstract class OsuHitObject : HitObject, IHasCombo, IHasPosition
|
||||
{
|
||||
public const double OBJECT_RADIUS = 64;
|
||||
|
||||
@ -36,6 +37,10 @@ namespace osu.Game.Modes.Osu.Objects
|
||||
|
||||
public abstract HitObjectType Type { get; }
|
||||
|
||||
public Color4 ComboColour { get; set; }
|
||||
public virtual bool NewCombo { get; set; }
|
||||
public int ComboIndex { get; set; }
|
||||
|
||||
public double HitWindowFor(OsuScoreResult result)
|
||||
{
|
||||
switch (result)
|
||||
@ -62,23 +67,9 @@ namespace osu.Game.Modes.Osu.Objects
|
||||
return OsuScoreResult.Miss;
|
||||
}
|
||||
|
||||
public override void SetDefaultsFromBeatmap(Beatmap beatmap)
|
||||
public virtual void SetDefaultsFromBeatmap(Beatmap<OsuHitObject> beatmap)
|
||||
{
|
||||
base.SetDefaultsFromBeatmap(beatmap);
|
||||
|
||||
Scale = (1.0f - 0.7f * (beatmap.BeatmapInfo.BaseDifficulty.CircleSize - 5) / 5) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
[Flags]
|
||||
public enum HitObjectType
|
||||
{
|
||||
Circle = 1 << 0,
|
||||
Slider = 1 << 1,
|
||||
NewCombo = 1 << 2,
|
||||
Spinner = 1 << 3,
|
||||
ColourHax = 122,
|
||||
Hold = 1 << 7,
|
||||
SliderTick = 1 << 8,
|
||||
}
|
||||
}
|
||||
|
@ -1,105 +0,0 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using osu.Game.Beatmaps.Samples;
|
||||
using osu.Game.Modes.Objects;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Modes.Osu.Objects
|
||||
{
|
||||
public class OsuHitObjectParser : HitObjectParser
|
||||
{
|
||||
public override HitObject Parse(string text)
|
||||
{
|
||||
string[] split = text.Split(',');
|
||||
var type = (HitObjectType)int.Parse(split[3]);
|
||||
bool combo = type.HasFlag(HitObjectType.NewCombo);
|
||||
type &= (HitObjectType)0xF;
|
||||
type &= ~HitObjectType.NewCombo;
|
||||
OsuHitObject result;
|
||||
switch (type)
|
||||
{
|
||||
case HitObjectType.Circle:
|
||||
result = new HitCircle
|
||||
{
|
||||
Position = new Vector2(int.Parse(split[0]), int.Parse(split[1]))
|
||||
};
|
||||
break;
|
||||
case HitObjectType.Slider:
|
||||
CurveTypes curveType = CurveTypes.Catmull;
|
||||
double length = 0;
|
||||
List<Vector2> points = new List<Vector2> { new Vector2(int.Parse(split[0]), int.Parse(split[1])) };
|
||||
|
||||
string[] pointsplit = split[5].Split('|');
|
||||
foreach (string t in pointsplit)
|
||||
{
|
||||
if (t.Length == 1)
|
||||
{
|
||||
switch (t)
|
||||
{
|
||||
case @"C":
|
||||
curveType = CurveTypes.Catmull;
|
||||
break;
|
||||
case @"B":
|
||||
curveType = CurveTypes.Bezier;
|
||||
break;
|
||||
case @"L":
|
||||
curveType = CurveTypes.Linear;
|
||||
break;
|
||||
case @"P":
|
||||
curveType = CurveTypes.PerfectCurve;
|
||||
break;
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
string[] temp = t.Split(':');
|
||||
Vector2 v = new Vector2(
|
||||
(int)Convert.ToDouble(temp[0], CultureInfo.InvariantCulture),
|
||||
(int)Convert.ToDouble(temp[1], CultureInfo.InvariantCulture)
|
||||
);
|
||||
points.Add(v);
|
||||
}
|
||||
|
||||
int repeatCount = Convert.ToInt32(split[6], CultureInfo.InvariantCulture);
|
||||
|
||||
if (repeatCount > 9000)
|
||||
throw new ArgumentOutOfRangeException(nameof(repeatCount), @"Repeat count is way too high");
|
||||
|
||||
if (split.Length > 7)
|
||||
length = Convert.ToDouble(split[7], CultureInfo.InvariantCulture);
|
||||
|
||||
result = new Slider
|
||||
{
|
||||
ControlPoints = points,
|
||||
Length = length,
|
||||
CurveType = curveType,
|
||||
RepeatCount = repeatCount,
|
||||
Position = new Vector2(int.Parse(split[0]), int.Parse(split[1]))
|
||||
};
|
||||
break;
|
||||
case HitObjectType.Spinner:
|
||||
result = new Spinner
|
||||
{
|
||||
Length = Convert.ToDouble(split[5], CultureInfo.InvariantCulture) - Convert.ToDouble(split[2], CultureInfo.InvariantCulture),
|
||||
Position = new Vector2(512, 384) / 2,
|
||||
};
|
||||
break;
|
||||
default:
|
||||
throw new InvalidOperationException($@"Unknown hit object type {type}");
|
||||
}
|
||||
result.StartTime = Convert.ToDouble(split[2], CultureInfo.InvariantCulture);
|
||||
result.Sample = new HitSampleInfo
|
||||
{
|
||||
Type = (SampleType)int.Parse(split[4]),
|
||||
Set = SampleSet.Soft,
|
||||
};
|
||||
result.NewCombo = combo;
|
||||
// TODO: "addition" field
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
@ -5,41 +5,33 @@ using OpenTK;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.Samples;
|
||||
using osu.Game.Beatmaps.Timing;
|
||||
using osu.Game.Modes.Objects.Types;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Modes.Objects;
|
||||
|
||||
namespace osu.Game.Modes.Osu.Objects
|
||||
{
|
||||
public class Slider : OsuHitObject
|
||||
public class Slider : OsuHitObject, IHasCurve
|
||||
{
|
||||
public override double EndTime => StartTime + RepeatCount * Curve.Length / Velocity;
|
||||
public IHasCurve CurveObject { get; set; }
|
||||
|
||||
public SliderCurve Curve => CurveObject.Curve;
|
||||
|
||||
public double EndTime => StartTime + RepeatCount * Curve.Distance / Velocity;
|
||||
public double Duration => EndTime - StartTime;
|
||||
|
||||
public override Vector2 EndPosition => PositionAt(1);
|
||||
|
||||
/// <summary>
|
||||
/// Computes the position on the slider at a given progress that ranges from 0 (beginning of the slider)
|
||||
/// to 1 (end of the slider). This includes repeat logic.
|
||||
/// </summary>
|
||||
/// <param name="progress">Ranges from 0 (beginning of the slider) to 1 (end of the slider).</param>
|
||||
/// <returns></returns>
|
||||
public Vector2 PositionAt(double progress) => Curve.PositionAt(CurveProgressAt(progress));
|
||||
public Vector2 PositionAt(double progress) => CurveObject.PositionAt(progress);
|
||||
public double ProgressAt(double progress) => CurveObject.ProgressAt(progress);
|
||||
public int RepeatAt(double progress) => CurveObject.RepeatAt(progress);
|
||||
|
||||
/// <summary>
|
||||
/// Find the current progress along the curve, accounting for repeat logic.
|
||||
/// </summary>
|
||||
public double CurveProgressAt(double progress)
|
||||
{
|
||||
var p = progress * RepeatCount % 1;
|
||||
if (RepeatAt(progress) % 2 == 1)
|
||||
p = 1 - p;
|
||||
return p;
|
||||
}
|
||||
public List<Vector2> ControlPoints => CurveObject.ControlPoints;
|
||||
public CurveType CurveType => CurveObject.CurveType;
|
||||
public double Distance => CurveObject.Distance;
|
||||
|
||||
/// <summary>
|
||||
/// Determine which repeat of the slider we are on at a given progress.
|
||||
/// Range is 0..RepeatCount where 0 is the first run.
|
||||
/// </summary>
|
||||
public int RepeatAt(double progress) => (int)(progress * RepeatCount);
|
||||
public int RepeatCount => CurveObject.RepeatCount;
|
||||
|
||||
private int stackHeight;
|
||||
public override int StackHeight
|
||||
@ -52,28 +44,10 @@ namespace osu.Game.Modes.Osu.Objects
|
||||
}
|
||||
}
|
||||
|
||||
public List<Vector2> ControlPoints
|
||||
{
|
||||
get { return Curve.ControlPoints; }
|
||||
set { Curve.ControlPoints = value; }
|
||||
}
|
||||
|
||||
public double Length
|
||||
{
|
||||
get { return Curve.Length; }
|
||||
set { Curve.Length = value; }
|
||||
}
|
||||
|
||||
public CurveTypes CurveType
|
||||
{
|
||||
get { return Curve.CurveType; }
|
||||
set { Curve.CurveType = value; }
|
||||
}
|
||||
|
||||
public double Velocity;
|
||||
public double TickDistance;
|
||||
|
||||
public override void SetDefaultsFromBeatmap(Beatmap beatmap)
|
||||
public override void SetDefaultsFromBeatmap(Beatmap<OsuHitObject> beatmap)
|
||||
{
|
||||
base.SetDefaultsFromBeatmap(beatmap);
|
||||
|
||||
@ -88,17 +62,13 @@ namespace osu.Game.Modes.Osu.Objects
|
||||
TickDistance = baseVelocity / baseDifficulty.SliderTickRate;
|
||||
}
|
||||
|
||||
public int RepeatCount = 1;
|
||||
|
||||
internal readonly SliderCurve Curve = new SliderCurve();
|
||||
|
||||
public IEnumerable<SliderTick> Ticks
|
||||
{
|
||||
get
|
||||
{
|
||||
if (TickDistance == 0) yield break;
|
||||
|
||||
var length = Curve.Length;
|
||||
var length = Curve.Distance;
|
||||
var tickDistance = Math.Min(TickDistance, length);
|
||||
var repeatDuration = length / Velocity;
|
||||
|
||||
@ -124,7 +94,7 @@ namespace osu.Game.Modes.Osu.Objects
|
||||
Position = Curve.PositionAt(distanceProgress),
|
||||
StackHeight = StackHeight,
|
||||
Scale = Scale,
|
||||
Colour = Colour,
|
||||
ComboColour = ComboColour,
|
||||
Sample = new HitSampleInfo
|
||||
{
|
||||
Type = SampleType.None,
|
||||
@ -138,12 +108,4 @@ namespace osu.Game.Modes.Osu.Objects
|
||||
|
||||
public override HitObjectType Type => HitObjectType.Slider;
|
||||
}
|
||||
|
||||
public enum CurveTypes
|
||||
{
|
||||
Catmull,
|
||||
Bezier,
|
||||
Linear,
|
||||
PerfectCurve
|
||||
}
|
||||
}
|
||||
|
@ -1,202 +0,0 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
using System.Linq;
|
||||
using osu.Framework.MathUtils;
|
||||
|
||||
namespace osu.Game.Modes.Osu.Objects
|
||||
{
|
||||
public class SliderCurve
|
||||
{
|
||||
public double Length;
|
||||
|
||||
public List<Vector2> ControlPoints;
|
||||
|
||||
public CurveTypes CurveType = CurveTypes.PerfectCurve;
|
||||
|
||||
public Vector2 Offset;
|
||||
|
||||
private List<Vector2> calculatedPath = new List<Vector2>();
|
||||
private List<double> cumulativeLength = new List<double>();
|
||||
|
||||
private List<Vector2> calculateSubpath(List<Vector2> subControlPoints)
|
||||
{
|
||||
switch (CurveType)
|
||||
{
|
||||
case CurveTypes.Linear:
|
||||
return subControlPoints;
|
||||
case CurveTypes.PerfectCurve:
|
||||
//we can only use CircularArc iff we have exactly three control points and no dissection.
|
||||
if (ControlPoints.Count != 3 || subControlPoints.Count != 3)
|
||||
break;
|
||||
|
||||
// Here we have exactly 3 control points. Attempt to fit a circular arc.
|
||||
List<Vector2> subpath = new CircularArcApproximator(subControlPoints[0], subControlPoints[1], subControlPoints[2]).CreateArc();
|
||||
|
||||
// If for some reason a circular arc could not be fit to the 3 given points, fall back to a numerically stable bezier approximation.
|
||||
if (subpath.Count == 0)
|
||||
break;
|
||||
|
||||
return subpath;
|
||||
}
|
||||
|
||||
return new BezierApproximator(subControlPoints).CreateBezier();
|
||||
}
|
||||
|
||||
private void calculatePath()
|
||||
{
|
||||
calculatedPath.Clear();
|
||||
|
||||
// Sliders may consist of various subpaths separated by two consecutive vertices
|
||||
// with the same position. The following loop parses these subpaths and computes
|
||||
// their shape independently, consecutively appending them to calculatedPath.
|
||||
List<Vector2> subControlPoints = new List<Vector2>();
|
||||
for (int i = 0; i < ControlPoints.Count; ++i)
|
||||
{
|
||||
subControlPoints.Add(ControlPoints[i]);
|
||||
if (i == ControlPoints.Count - 1 || ControlPoints[i] == ControlPoints[i + 1])
|
||||
{
|
||||
List<Vector2> subpath = calculateSubpath(subControlPoints);
|
||||
foreach (Vector2 t in subpath)
|
||||
if (calculatedPath.Count == 0 || calculatedPath.Last() != t)
|
||||
calculatedPath.Add(t);
|
||||
|
||||
subControlPoints.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateCumulativeLengthAndTrimPath()
|
||||
{
|
||||
double l = 0;
|
||||
|
||||
cumulativeLength.Clear();
|
||||
cumulativeLength.Add(l);
|
||||
|
||||
for (int i = 0; i < calculatedPath.Count - 1; ++i)
|
||||
{
|
||||
Vector2 diff = calculatedPath[i + 1] - calculatedPath[i];
|
||||
double d = diff.Length;
|
||||
|
||||
// Shorten slider curves that are too long compared to what's
|
||||
// in the .osu file.
|
||||
if (Length - l < d)
|
||||
{
|
||||
calculatedPath[i + 1] = calculatedPath[i] + diff * (float)((Length - l) / d);
|
||||
calculatedPath.RemoveRange(i + 2, calculatedPath.Count - 2 - i);
|
||||
|
||||
l = Length;
|
||||
cumulativeLength.Add(l);
|
||||
break;
|
||||
}
|
||||
|
||||
l += d;
|
||||
cumulativeLength.Add(l);
|
||||
}
|
||||
|
||||
//TODO: Figure out if the following code is needed in some cases. Judging by the map
|
||||
// "Transform" http://osu.ppy.sh/s/484689 it seems like we should _not_ be doing this.
|
||||
// Lengthen slider curves that are too short compared to what's
|
||||
// in the .osu file.
|
||||
/*if (l < Length && calculatedPath.Count > 1)
|
||||
{
|
||||
Vector2 diff = calculatedPath[calculatedPath.Count - 1] - calculatedPath[calculatedPath.Count - 2];
|
||||
double d = diff.Length;
|
||||
|
||||
if (d <= 0)
|
||||
return;
|
||||
|
||||
calculatedPath[calculatedPath.Count - 1] += diff * (float)((Length - l) / d);
|
||||
cumulativeLength[calculatedPath.Count - 1] = Length;
|
||||
}*/
|
||||
}
|
||||
|
||||
public void Calculate()
|
||||
{
|
||||
calculatePath();
|
||||
calculateCumulativeLengthAndTrimPath();
|
||||
}
|
||||
|
||||
private int indexOfDistance(double d)
|
||||
{
|
||||
int i = cumulativeLength.BinarySearch(d);
|
||||
if (i < 0) i = ~i;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
private double progressToDistance(double progress)
|
||||
{
|
||||
return MathHelper.Clamp(progress, 0, 1) * Length;
|
||||
}
|
||||
|
||||
private Vector2 interpolateVertices(int i, double d)
|
||||
{
|
||||
if (calculatedPath.Count == 0)
|
||||
return Vector2.Zero;
|
||||
|
||||
if (i <= 0)
|
||||
return calculatedPath.First();
|
||||
else if (i >= calculatedPath.Count)
|
||||
return calculatedPath.Last();
|
||||
|
||||
Vector2 p0 = calculatedPath[i - 1];
|
||||
Vector2 p1 = calculatedPath[i];
|
||||
|
||||
double d0 = cumulativeLength[i - 1];
|
||||
double d1 = cumulativeLength[i];
|
||||
|
||||
// Avoid division by and almost-zero number in case two points are extremely close to each other.
|
||||
if (Precision.AlmostEquals(d0, d1))
|
||||
return p0;
|
||||
|
||||
double w = (d - d0) / (d1 - d0);
|
||||
return p0 + (p1 - p0) * (float)w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the slider curve until a given progress that ranges from 0 (beginning of the slider)
|
||||
/// to 1 (end of the slider) and stores the generated path in the given list.
|
||||
/// </summary>
|
||||
/// <param name="path">The list to be filled with the computed curve.</param>
|
||||
/// <param name="p0">Start progress. Ranges from 0 (beginning of the slider) to 1 (end of the slider).</param>
|
||||
/// <param name="p1">End progress. Ranges from 0 (beginning of the slider) to 1 (end of the slider).</param>
|
||||
public void GetPathToProgress(List<Vector2> path, double p0, double p1)
|
||||
{
|
||||
if (calculatedPath.Count == 0 && ControlPoints.Count > 0)
|
||||
Calculate();
|
||||
|
||||
double d0 = progressToDistance(p0);
|
||||
double d1 = progressToDistance(p1);
|
||||
|
||||
path.Clear();
|
||||
|
||||
int i = 0;
|
||||
for (; i < calculatedPath.Count && cumulativeLength[i] < d0; ++i) { }
|
||||
|
||||
path.Add(interpolateVertices(i, d0) + Offset);
|
||||
|
||||
for (; i < calculatedPath.Count && cumulativeLength[i] <= d1; ++i)
|
||||
path.Add(calculatedPath[i] + Offset);
|
||||
|
||||
path.Add(interpolateVertices(i, d1) + Offset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the position on the slider at a given progress that ranges from 0 (beginning of the curve)
|
||||
/// to 1 (end of the curve).
|
||||
/// </summary>
|
||||
/// <param name="progress">Ranges from 0 (beginning of the curve) to 1 (end of the curve).</param>
|
||||
/// <returns></returns>
|
||||
public Vector2 PositionAt(double progress)
|
||||
{
|
||||
if (calculatedPath.Count == 0 && ControlPoints.Count > 0)
|
||||
Calculate();
|
||||
|
||||
double d = progressToDistance(progress);
|
||||
return interpolateVertices(indexOfDistance(d), d) + Offset;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,14 +1,17 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Game.Modes.Objects.Types;
|
||||
|
||||
namespace osu.Game.Modes.Osu.Objects
|
||||
{
|
||||
public class Spinner : OsuHitObject
|
||||
public class Spinner : OsuHitObject, IHasEndTime
|
||||
{
|
||||
public double Length;
|
||||
|
||||
public override double EndTime => StartTime + Length;
|
||||
public double EndTime { get; set; }
|
||||
public double Duration => EndTime - StartTime;
|
||||
|
||||
public override HitObjectType Type => HitObjectType.Spinner;
|
||||
|
||||
public override bool NewCombo => true;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user