Ensure SliderCurve is assigned Calculated before used.

This commit is contained in:
Dean Herbert
2017-02-14 18:40:37 +09:00
parent fc192906ea
commit e88d02d3c4
3 changed files with 32 additions and 14 deletions

View File

@ -29,8 +29,6 @@ namespace osu.Game.Modes.Osu.Objects
result = new HitCircle(); result = new HitCircle();
break; break;
case HitObjectType.Slider: case HitObjectType.Slider:
Slider s = new Slider();
CurveTypes curveType = CurveTypes.Catmull; CurveTypes curveType = CurveTypes.Catmull;
int repeatCount = 0; int repeatCount = 0;
double length = 0; double length = 0;
@ -79,18 +77,13 @@ namespace osu.Game.Modes.Osu.Objects
if (split.Length > 7) if (split.Length > 7)
length = Convert.ToDouble(split[7], CultureInfo.InvariantCulture); length = Convert.ToDouble(split[7], CultureInfo.InvariantCulture);
s.RepeatCount = repeatCount; result = new Slider
s.Curve = new SliderCurve
{ {
ControlPoints = points, ControlPoints = points,
Length = length, Length = length,
CurveType = curveType CurveType = curveType,
RepeatCount = repeatCount
}; };
s.Curve.Calculate();
result = s;
break; break;
case HitObjectType.Spinner: case HitObjectType.Spinner:
result = new Spinner(); result = new Spinner();
@ -101,7 +94,8 @@ namespace osu.Game.Modes.Osu.Objects
} }
result.Position = new Vector2(int.Parse(split[0]), int.Parse(split[1])); result.Position = new Vector2(int.Parse(split[0]), int.Parse(split[1]));
result.StartTime = double.Parse(split[2]); result.StartTime = double.Parse(split[2]);
result.Sample = new HitSampleInfo { result.Sample = new HitSampleInfo
{
Type = (SampleType)int.Parse(split[4]), Type = (SampleType)int.Parse(split[4]),
Set = SampleSet.Soft, Set = SampleSet.Soft,
}; };

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using OpenTK; using OpenTK;
@ -19,11 +20,28 @@ namespace osu.Game.Modes.Osu.Objects
set set
{ {
stackHeight = value; stackHeight = value;
if (Curve != null)
Curve.Offset = StackOffset; Curve.Offset = StackOffset;
} }
} }
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 Velocity;
public override void SetDefaultsFromBeatmap(Beatmap beatmap) public override void SetDefaultsFromBeatmap(Beatmap beatmap)
@ -35,7 +53,7 @@ namespace osu.Game.Modes.Osu.Objects
public int RepeatCount; public int RepeatCount;
public SliderCurve Curve; internal readonly SliderCurve Curve = new SliderCurve();
} }
public enum CurveTypes public enum CurveTypes

View File

@ -172,6 +172,9 @@ namespace osu.Game.Modes.Osu.Objects
/// <param name="p1">End 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) public void GetPathToProgress(List<Vector2> path, double p0, double p1)
{ {
if (calculatedPath.Count == 0 && ControlPoints.Count > 0)
Calculate();
double d0 = progressToDistance(p0); double d0 = progressToDistance(p0);
double d1 = progressToDistance(p1); double d1 = progressToDistance(p1);
@ -196,6 +199,9 @@ namespace osu.Game.Modes.Osu.Objects
/// <returns></returns> /// <returns></returns>
public Vector2 PositionAt(double progress) public Vector2 PositionAt(double progress)
{ {
if (calculatedPath.Count == 0 && ControlPoints.Count > 0)
Calculate();
double d = progressToDistance(progress); double d = progressToDistance(progress);
return interpolateVertices(indexOfDistance(d), d) + Offset; return interpolateVertices(indexOfDistance(d), d) + Offset;
} }