mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 04:52:57 +08:00
Merge remote-tracking branch 'origin/master' into fix-mask-disposal
# Conflicts: # osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/PathControlPointVisualiser.cs # osu.Game.Rulesets.Osu/Edit/Blueprints/Sliders/Components/SliderCirclePiece.cs # osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs # osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSliderHead.cs # osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSliderTail.cs # osu.Game.Rulesets.Osu/Objects/Slider.cs
This commit is contained in:
commit
29422345f7
6
.gitignore
vendored
6
.gitignore
vendored
@ -252,7 +252,11 @@ paket-files/
|
||||
.fake/
|
||||
|
||||
# JetBrains Rider
|
||||
.idea/
|
||||
.idea/.idea.osu/.idea/*.xml
|
||||
.idea/.idea.osu/.idea/codeStyles/*.xml
|
||||
.idea/.idea.osu/.idea/dataSources/*.xml
|
||||
.idea/.idea.osu/.idea/dictionaries/*.xml
|
||||
.idea/.idea.osu/*.iml
|
||||
*.sln.iml
|
||||
|
||||
# CodeRush
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 9ee64e369fe6fdafc6aed40f5a35b5f01eb82c53
|
||||
Subproject commit 651e598b016b43e31ab1c1b29d5b30c92361b8d9
|
@ -5,6 +5,7 @@ using System.Linq;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Catch.Objects;
|
||||
using osu.Game.Rulesets.Catch.UI;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Screens.Play;
|
||||
using osu.Game.Tests.Visual;
|
||||
@ -37,13 +38,11 @@ namespace osu.Game.Rulesets.Catch.Tests
|
||||
beatmap.HitObjects.Add(new JuiceStream
|
||||
{
|
||||
X = 0.5f - width / 2,
|
||||
ControlPoints = new[]
|
||||
Path = new SliderPath(PathType.Linear, new[]
|
||||
{
|
||||
Vector2.Zero,
|
||||
new Vector2(width * CatchPlayfield.BASE_WIDTH, 0)
|
||||
},
|
||||
PathType = PathType.Linear,
|
||||
Distance = width * CatchPlayfield.BASE_WIDTH,
|
||||
}),
|
||||
StartTime = i * 2000,
|
||||
NewCombo = i % 8 == 0
|
||||
});
|
||||
|
@ -34,9 +34,7 @@ namespace osu.Game.Rulesets.Catch.Beatmaps
|
||||
{
|
||||
StartTime = obj.StartTime,
|
||||
Samples = obj.Samples,
|
||||
ControlPoints = curveData.ControlPoints,
|
||||
PathType = curveData.PathType,
|
||||
Distance = curveData.Distance,
|
||||
Path = curveData.Path,
|
||||
NodeSamples = curveData.NodeSamples,
|
||||
RepeatCount = curveData.RepeatCount,
|
||||
X = (positionData?.X ?? 0) / CatchPlayfield.BASE_WIDTH,
|
||||
|
@ -10,7 +10,6 @@ using osu.Game.Beatmaps.ControlPoints;
|
||||
using osu.Game.Rulesets.Catch.UI;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Catch.Objects
|
||||
{
|
||||
@ -138,28 +137,18 @@ namespace osu.Game.Rulesets.Catch.Objects
|
||||
|
||||
public double Duration => EndTime - StartTime;
|
||||
|
||||
public double Distance
|
||||
private SliderPath path;
|
||||
|
||||
public SliderPath Path
|
||||
{
|
||||
get { return Path.Distance; }
|
||||
set { Path.Distance = value; }
|
||||
get => path;
|
||||
set => path = value;
|
||||
}
|
||||
|
||||
public SliderPath Path { get; } = new SliderPath();
|
||||
|
||||
public Vector2[] ControlPoints
|
||||
{
|
||||
get { return Path.ControlPoints; }
|
||||
set { Path.ControlPoints = value; }
|
||||
}
|
||||
public double Distance => Path.Distance;
|
||||
|
||||
public List<List<SampleInfo>> NodeSamples { get; set; } = new List<List<SampleInfo>>();
|
||||
|
||||
public PathType PathType
|
||||
{
|
||||
get { return Path.PathType; }
|
||||
set { Path.PathType = value; }
|
||||
}
|
||||
|
||||
public double? LegacyLastTickOffset { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ namespace osu.Game.Rulesets.Catch.UI
|
||||
|
||||
protected override bool UserScrollSpeedAdjustment => false;
|
||||
|
||||
protected override SpeedChangeVisualisationMethod VisualisationMethod => SpeedChangeVisualisationMethod.Constant;
|
||||
protected override ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Constant;
|
||||
|
||||
public CatchPlayfield(BeatmapDifficulty difficulty, Func<CatchHitObject, DrawableHitObject<CatchHitObject>> getVisualRepresentation)
|
||||
{
|
||||
|
@ -18,6 +18,7 @@ using System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Rulesets.Judgements;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables.Pieces;
|
||||
@ -108,13 +109,12 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
StartTime = Time.Current + 1000,
|
||||
Position = new Vector2(239, 176),
|
||||
ControlPoints = new[]
|
||||
Path = new SliderPath(PathType.PerfectCurve, new[]
|
||||
{
|
||||
Vector2.Zero,
|
||||
new Vector2(154, 28),
|
||||
new Vector2(52, -34)
|
||||
},
|
||||
Distance = 700,
|
||||
}, 700),
|
||||
RepeatCount = repeats,
|
||||
NodeSamples = createEmptySamples(repeats),
|
||||
StackHeight = 10
|
||||
@ -141,12 +141,11 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
StartTime = Time.Current + 1000,
|
||||
Position = new Vector2(-(distance / 2), 0),
|
||||
ControlPoints = new[]
|
||||
Path = new SliderPath(PathType.PerfectCurve, new[]
|
||||
{
|
||||
Vector2.Zero,
|
||||
new Vector2(distance, 0),
|
||||
},
|
||||
Distance = distance,
|
||||
}, distance),
|
||||
RepeatCount = repeats,
|
||||
NodeSamples = createEmptySamples(repeats),
|
||||
StackHeight = stackHeight
|
||||
@ -161,13 +160,12 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
StartTime = Time.Current + 1000,
|
||||
Position = new Vector2(-200, 0),
|
||||
ControlPoints = new[]
|
||||
Path = new SliderPath(PathType.PerfectCurve, new[]
|
||||
{
|
||||
Vector2.Zero,
|
||||
new Vector2(200, 200),
|
||||
new Vector2(400, 0)
|
||||
},
|
||||
Distance = 600,
|
||||
}, 600),
|
||||
RepeatCount = repeats,
|
||||
NodeSamples = createEmptySamples(repeats)
|
||||
};
|
||||
@ -181,10 +179,9 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
var slider = new Slider
|
||||
{
|
||||
PathType = PathType.Linear,
|
||||
StartTime = Time.Current + 1000,
|
||||
Position = new Vector2(-200, 0),
|
||||
ControlPoints = new[]
|
||||
Path = new SliderPath(PathType.Linear, new[]
|
||||
{
|
||||
Vector2.Zero,
|
||||
new Vector2(150, 75),
|
||||
@ -192,8 +189,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
new Vector2(300, -200),
|
||||
new Vector2(400, 0),
|
||||
new Vector2(430, 0)
|
||||
},
|
||||
Distance = 793.4417,
|
||||
}),
|
||||
RepeatCount = repeats,
|
||||
NodeSamples = createEmptySamples(repeats)
|
||||
};
|
||||
@ -207,18 +203,16 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
var slider = new Slider
|
||||
{
|
||||
PathType = PathType.Bezier,
|
||||
StartTime = Time.Current + 1000,
|
||||
Position = new Vector2(-200, 0),
|
||||
ControlPoints = new[]
|
||||
Path = new SliderPath(PathType.Bezier, new[]
|
||||
{
|
||||
Vector2.Zero,
|
||||
new Vector2(150, 75),
|
||||
new Vector2(200, 100),
|
||||
new Vector2(300, -200),
|
||||
new Vector2(430, 0)
|
||||
},
|
||||
Distance = 480,
|
||||
}),
|
||||
RepeatCount = repeats,
|
||||
NodeSamples = createEmptySamples(repeats)
|
||||
};
|
||||
@ -232,10 +226,9 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
var slider = new Slider
|
||||
{
|
||||
PathType = PathType.Linear,
|
||||
StartTime = Time.Current + 1000,
|
||||
Position = new Vector2(0, 0),
|
||||
ControlPoints = new[]
|
||||
Path = new SliderPath(PathType.Linear, new[]
|
||||
{
|
||||
Vector2.Zero,
|
||||
new Vector2(-200, 0),
|
||||
@ -243,8 +236,7 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
new Vector2(0, -200),
|
||||
new Vector2(-200, -200),
|
||||
new Vector2(0, -200)
|
||||
},
|
||||
Distance = 1000,
|
||||
}),
|
||||
RepeatCount = repeats,
|
||||
NodeSamples = createEmptySamples(repeats)
|
||||
};
|
||||
@ -264,15 +256,13 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
{
|
||||
StartTime = Time.Current + 1000,
|
||||
Position = new Vector2(-100, 0),
|
||||
PathType = PathType.Catmull,
|
||||
ControlPoints = new[]
|
||||
Path = new SliderPath(PathType.Catmull, new[]
|
||||
{
|
||||
Vector2.Zero,
|
||||
new Vector2(50, -50),
|
||||
new Vector2(150, 50),
|
||||
new Vector2(200, 0)
|
||||
},
|
||||
Distance = 300,
|
||||
}),
|
||||
RepeatCount = repeats,
|
||||
NodeSamples = repeatSamples
|
||||
};
|
||||
|
@ -6,6 +6,7 @@ using System.Collections.Generic;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
|
||||
@ -35,14 +36,12 @@ namespace osu.Game.Rulesets.Osu.Tests
|
||||
var slider = new Slider
|
||||
{
|
||||
Position = new Vector2(256, 192),
|
||||
ControlPoints = new[]
|
||||
Path = new SliderPath(PathType.Bezier, new[]
|
||||
{
|
||||
Vector2.Zero,
|
||||
new Vector2(150, 150),
|
||||
new Vector2(300, 0)
|
||||
},
|
||||
PathType = PathType.Bezier,
|
||||
Distance = 350
|
||||
})
|
||||
};
|
||||
|
||||
slider.ApplyDefaults(new ControlPointInfo(), new BeatmapDifficulty { CircleSize = 2 });
|
||||
|
@ -35,9 +35,7 @@ namespace osu.Game.Rulesets.Osu.Beatmaps
|
||||
{
|
||||
StartTime = original.StartTime,
|
||||
Samples = original.Samples,
|
||||
ControlPoints = curveData.ControlPoints,
|
||||
PathType = curveData.PathType,
|
||||
Distance = curveData.Distance,
|
||||
Path = curveData.Path,
|
||||
NodeSamples = curveData.NodeSamples,
|
||||
RepeatCount = curveData.RepeatCount,
|
||||
Position = positionData?.Position ?? Vector2.Zero,
|
||||
|
@ -1,7 +1,6 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -9,6 +8,7 @@ using osu.Framework.Graphics.Lines;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using OpenTK;
|
||||
|
||||
@ -55,16 +55,16 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
{
|
||||
base.Update();
|
||||
|
||||
Position = slider.StackedPosition + slider.ControlPoints[index];
|
||||
Position = slider.StackedPosition + slider.Path.ControlPoints[index];
|
||||
|
||||
marker.Colour = isSegmentSeparator ? colours.Red : colours.Yellow;
|
||||
|
||||
path.ClearVertices();
|
||||
|
||||
if (index != slider.ControlPoints.Length - 1)
|
||||
if (index != slider.Path.ControlPoints.Length - 1)
|
||||
{
|
||||
path.AddVertex(Vector2.Zero);
|
||||
path.AddVertex(slider.ControlPoints[index + 1] - slider.ControlPoints[index]);
|
||||
path.AddVertex(slider.Path.ControlPoints[index + 1] - slider.Path.ControlPoints[index]);
|
||||
}
|
||||
|
||||
path.OriginPosition = path.PositionInBoundingBox(Vector2.Zero);
|
||||
@ -76,7 +76,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
|
||||
protected override bool OnDrag(DragEvent e)
|
||||
{
|
||||
var newControlPoints = slider.ControlPoints.ToArray();
|
||||
var newControlPoints = slider.Path.ControlPoints.ToArray();
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
@ -96,8 +96,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
if (isSegmentSeparatorWithPrevious)
|
||||
newControlPoints[index - 1] = newControlPoints[index];
|
||||
|
||||
slider.ControlPoints = newControlPoints;
|
||||
slider.Path.Calculate(true);
|
||||
slider.Path = new SliderPath(slider.Path.Type, newControlPoints);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -106,8 +105,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
|
||||
private bool isSegmentSeparator => isSegmentSeparatorWithNext || isSegmentSeparatorWithPrevious;
|
||||
|
||||
private bool isSegmentSeparatorWithNext => index < slider.ControlPoints.Length - 1 && slider.ControlPoints[index + 1] == slider.ControlPoints[index];
|
||||
private bool isSegmentSeparatorWithNext => index < slider.Path.ControlPoints.Length - 1 && slider.Path.ControlPoints[index + 1] == slider.Path.ControlPoints[index];
|
||||
|
||||
private bool isSegmentSeparatorWithPrevious => index > 0 && slider.ControlPoints[index - 1] == slider.ControlPoints[index];
|
||||
private bool isSegmentSeparatorWithPrevious => index > 0 && slider.Path.ControlPoints[index - 1] == slider.Path.ControlPoints[index];
|
||||
}
|
||||
}
|
||||
|
@ -30,9 +30,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
|
||||
private void updatePathControlPoints()
|
||||
{
|
||||
while (slider.ControlPoints.Length > pieces.Count)
|
||||
while (slider.Path.ControlPoints.Length > pieces.Count)
|
||||
pieces.Add(new PathControlPointPiece(slider, pieces.Count));
|
||||
while (slider.ControlPoints.Length < pieces.Count)
|
||||
while (slider.Path.ControlPoints.Length < pieces.Count)
|
||||
pieces.Remove(pieces[pieces.Count - 1]);
|
||||
}
|
||||
}
|
||||
|
@ -43,8 +43,6 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
{
|
||||
base.Update();
|
||||
|
||||
slider.Path.Calculate();
|
||||
|
||||
var vertices = new List<Vector2>();
|
||||
slider.Path.GetPathToProgress(vertices, 0, 1);
|
||||
|
||||
|
@ -1,16 +1,15 @@
|
||||
// Copyright (c) 2007-2018 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.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.IEnumerableExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components;
|
||||
using OpenTK;
|
||||
@ -119,12 +118,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
||||
|
||||
private void updateSlider()
|
||||
{
|
||||
for (int i = 0; i < segments.Count; i++)
|
||||
segments[i].Calculate(i == segments.Count - 1 ? (Vector2?)cursor : null);
|
||||
|
||||
HitObject.ControlPoints = segments.SelectMany(s => s.ControlPoints).Concat(cursor.Yield()).ToArray();
|
||||
HitObject.PathType = HitObject.ControlPoints.Length > 2 ? PathType.Bezier : PathType.Linear;
|
||||
HitObject.Distance = segments.Sum(s => s.Distance);
|
||||
var newControlPoints = segments.SelectMany(s => s.ControlPoints).Concat(cursor.Yield()).ToArray();
|
||||
HitObject.Path = new SliderPath(newControlPoints.Length > 2 ? PathType.Bezier : PathType.Linear, newControlPoints);
|
||||
}
|
||||
|
||||
private void setState(PlacementState newState)
|
||||
@ -140,41 +135,12 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders
|
||||
|
||||
private class Segment
|
||||
{
|
||||
public float Distance { get; private set; }
|
||||
|
||||
public readonly List<Vector2> ControlPoints = new List<Vector2>();
|
||||
|
||||
public Segment(Vector2 offset)
|
||||
{
|
||||
ControlPoints.Add(offset);
|
||||
}
|
||||
|
||||
public void Calculate(Vector2? cursor = null)
|
||||
{
|
||||
Span<Vector2> allControlPoints = stackalloc Vector2[ControlPoints.Count + (cursor.HasValue ? 1 : 0)];
|
||||
|
||||
for (int i = 0; i < ControlPoints.Count; i++)
|
||||
allControlPoints[i] = ControlPoints[i];
|
||||
if (cursor.HasValue)
|
||||
allControlPoints[allControlPoints.Length - 1] = cursor.Value;
|
||||
|
||||
List<Vector2> result;
|
||||
|
||||
switch (allControlPoints.Length)
|
||||
{
|
||||
case 1:
|
||||
case 2:
|
||||
result = PathApproximator.ApproximateLinear(allControlPoints);
|
||||
break;
|
||||
default:
|
||||
result = PathApproximator.ApproximateBezier(allControlPoints);
|
||||
break;
|
||||
}
|
||||
|
||||
Distance = 0;
|
||||
for (int i = 0; i < result.Count - 1; i++)
|
||||
Distance += Vector2.Distance(result[i], result[i + 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,12 +32,11 @@ namespace osu.Game.Rulesets.Osu.Mods
|
||||
slider.NestedHitObjects.OfType<SliderTick>().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Position.Y));
|
||||
slider.NestedHitObjects.OfType<RepeatPoint>().ForEach(h => h.Position = new Vector2(h.Position.X, OsuPlayfield.BASE_SIZE.Y - h.Position.Y));
|
||||
|
||||
var newControlPoints = new Vector2[slider.ControlPoints.Length];
|
||||
for (int i = 0; i < slider.ControlPoints.Length; i++)
|
||||
newControlPoints[i] = new Vector2(slider.ControlPoints[i].X, -slider.ControlPoints[i].Y);
|
||||
var newControlPoints = new Vector2[slider.Path.ControlPoints.Length];
|
||||
for (int i = 0; i < slider.Path.ControlPoints.Length; i++)
|
||||
newControlPoints[i] = new Vector2(slider.Path.ControlPoints[i].X, -slider.Path.ControlPoints[i].Y);
|
||||
|
||||
slider.ControlPoints = newControlPoints;
|
||||
slider.Path?.Calculate(); // Recalculate the slider curve
|
||||
slider.Path = new SliderPath(slider.Path.Type, newControlPoints, slider.Path.ExpectedDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -51,34 +51,22 @@ namespace osu.Game.Rulesets.Osu.Objects
|
||||
}
|
||||
}
|
||||
|
||||
public SliderPath Path { get; } = new SliderPath();
|
||||
private SliderPath path;
|
||||
|
||||
public readonly Bindable<Vector2[]> ControlPointsBindable = new Bindable<Vector2[]>(Array.Empty<Vector2>());
|
||||
|
||||
public Vector2[] ControlPoints
|
||||
public SliderPath Path
|
||||
{
|
||||
get => ControlPointsBindable;
|
||||
get => path;
|
||||
set
|
||||
{
|
||||
ControlPointsBindable.Value = value;
|
||||
Path.ControlPoints = value;
|
||||
path = value;
|
||||
|
||||
PathChanged?.Invoke(value);
|
||||
if (TailCircle != null)
|
||||
TailCircle.Position = EndPosition;
|
||||
}
|
||||
}
|
||||
|
||||
public PathType PathType
|
||||
{
|
||||
get { return Path.PathType; }
|
||||
set { Path.PathType = value; }
|
||||
}
|
||||
|
||||
public double Distance
|
||||
{
|
||||
get { return Path.Distance; }
|
||||
set { Path.Distance = value; }
|
||||
}
|
||||
public double Distance => Path.Distance;
|
||||
|
||||
public override Vector2 Position
|
||||
{
|
||||
|
@ -41,7 +41,7 @@ namespace osu.Game.Rulesets.Taiko.UI
|
||||
|
||||
protected override bool UserScrollSpeedAdjustment => false;
|
||||
|
||||
protected override SpeedChangeVisualisationMethod VisualisationMethod => SpeedChangeVisualisationMethod.Overlapping;
|
||||
protected override ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Overlapping;
|
||||
|
||||
private readonly Container<HitExplosion> hitExplosionContainer;
|
||||
private readonly Container<KiaiHitExplosion> kiaiExplosionContainer;
|
||||
|
@ -11,6 +11,7 @@ using OpenTK;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Osu;
|
||||
using osu.Game.Rulesets.Osu.Edit;
|
||||
using osu.Game.Rulesets.Osu.Edit.Blueprints.HitCircles;
|
||||
@ -53,12 +54,11 @@ namespace osu.Game.Tests.Visual
|
||||
new Slider
|
||||
{
|
||||
Position = new Vector2(128, 256),
|
||||
ControlPoints = new[]
|
||||
Path = new SliderPath(PathType.Linear, new[]
|
||||
{
|
||||
Vector2.Zero,
|
||||
new Vector2(216, 0),
|
||||
},
|
||||
Distance = 216,
|
||||
}),
|
||||
Scale = 0.5f,
|
||||
}
|
||||
},
|
||||
|
@ -114,11 +114,11 @@ namespace osu.Game.Tests.Visual
|
||||
|
||||
private class TestPlayfield : ScrollingPlayfield
|
||||
{
|
||||
public new readonly ScrollingDirection Direction;
|
||||
public new ScrollingDirection Direction => base.Direction;
|
||||
|
||||
public TestPlayfield(ScrollingDirection direction)
|
||||
{
|
||||
Direction = direction;
|
||||
base.Direction.Value = direction;
|
||||
|
||||
Padding = new MarginPadding(2);
|
||||
|
||||
|
@ -5,7 +5,7 @@ using System.ComponentModel;
|
||||
|
||||
namespace osu.Game.Configuration
|
||||
{
|
||||
public enum SpeedChangeVisualisationMethod
|
||||
public enum ScrollVisualisationMethod
|
||||
{
|
||||
[Description("Sequential")]
|
||||
Sequential,
|
@ -245,10 +245,10 @@ namespace osu.Game.Overlays
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (current?.TrackLoaded ?? false)
|
||||
{
|
||||
var track = current.Track;
|
||||
var track = current?.TrackLoaded ?? false ? current.Track : null;
|
||||
|
||||
if (track?.IsDummyDevice == false)
|
||||
{
|
||||
progressBar.EndTime = track.Length;
|
||||
progressBar.CurrentTime = track.CurrentTime;
|
||||
|
||||
@ -258,7 +258,11 @@ namespace osu.Game.Overlays
|
||||
next();
|
||||
}
|
||||
else
|
||||
{
|
||||
progressBar.CurrentTime = 0;
|
||||
progressBar.EndTime = 1;
|
||||
playButton.Icon = FontAwesome.fa_play_circle_o;
|
||||
}
|
||||
}
|
||||
|
||||
private void play()
|
||||
|
@ -50,9 +50,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Catch
|
||||
X = position.X,
|
||||
NewCombo = FirstObject || newCombo,
|
||||
ComboOffset = comboOffset,
|
||||
ControlPoints = controlPoints,
|
||||
Distance = length,
|
||||
PathType = pathType,
|
||||
Path = new SliderPath(pathType, controlPoints, length),
|
||||
NodeSamples = nodeSamples,
|
||||
RepeatCount = repeatCount
|
||||
};
|
||||
|
@ -3,7 +3,6 @@
|
||||
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using System.Collections.Generic;
|
||||
using OpenTK;
|
||||
using osu.Game.Audio;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Beatmaps.ControlPoints;
|
||||
@ -20,11 +19,9 @@ namespace osu.Game.Rulesets.Objects.Legacy
|
||||
/// <summary>
|
||||
/// <see cref="ConvertSlider"/>s don't need a curve since they're converted to ruleset-specific hitobjects.
|
||||
/// </summary>
|
||||
public SliderPath Path { get; } = null;
|
||||
public Vector2[] ControlPoints { get; set; }
|
||||
public PathType PathType { get; set; }
|
||||
public SliderPath Path { get; set; }
|
||||
|
||||
public double Distance { get; set; }
|
||||
public double Distance => Path.Distance;
|
||||
|
||||
public List<List<SampleInfo>> NodeSamples { get; set; }
|
||||
public int RepeatCount { get; set; }
|
||||
|
@ -31,9 +31,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Mania
|
||||
return new ConvertSlider
|
||||
{
|
||||
X = position.X,
|
||||
ControlPoints = controlPoints,
|
||||
Distance = length,
|
||||
PathType = pathType,
|
||||
Path = new SliderPath(pathType, controlPoints, length),
|
||||
NodeSamples = nodeSamples,
|
||||
RepeatCount = repeatCount
|
||||
};
|
||||
|
@ -51,9 +51,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Osu
|
||||
Position = position,
|
||||
NewCombo = FirstObject || newCombo,
|
||||
ComboOffset = comboOffset,
|
||||
ControlPoints = controlPoints,
|
||||
Distance = Math.Max(0, length),
|
||||
PathType = pathType,
|
||||
Path = new SliderPath(pathType, controlPoints, Math.Max(0, length)),
|
||||
NodeSamples = nodeSamples,
|
||||
RepeatCount = repeatCount
|
||||
};
|
||||
|
@ -27,9 +27,7 @@ namespace osu.Game.Rulesets.Objects.Legacy.Taiko
|
||||
{
|
||||
return new ConvertSlider
|
||||
{
|
||||
ControlPoints = controlPoints,
|
||||
Distance = length,
|
||||
PathType = pathType,
|
||||
Path = new SliderPath(pathType, controlPoints, length),
|
||||
NodeSamples = nodeSamples,
|
||||
RepeatCount = repeatCount
|
||||
};
|
||||
|
@ -4,28 +4,140 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json;
|
||||
using osu.Framework.MathUtils;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Objects
|
||||
{
|
||||
public class SliderPath
|
||||
public struct SliderPath : IEquatable<SliderPath>
|
||||
{
|
||||
public double Distance;
|
||||
/// <summary>
|
||||
/// The user-set distance of the path. If non-null, <see cref="Distance"/> will match this value,
|
||||
/// and the path will be shortened/lengthened to match this length.
|
||||
/// </summary>
|
||||
public readonly double? ExpectedDistance;
|
||||
|
||||
public Vector2[] ControlPoints = Array.Empty<Vector2>();
|
||||
/// <summary>
|
||||
/// The type of path.
|
||||
/// </summary>
|
||||
public readonly PathType Type;
|
||||
|
||||
public PathType PathType = PathType.PerfectCurve;
|
||||
[JsonProperty]
|
||||
private Vector2[] controlPoints;
|
||||
|
||||
public Vector2 Offset;
|
||||
private List<Vector2> calculatedPath;
|
||||
private List<double> cumulativeLength;
|
||||
|
||||
private readonly List<Vector2> calculatedPath = new List<Vector2>();
|
||||
private readonly List<double> cumulativeLength = new List<double>();
|
||||
private bool isInitialised;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="SliderPath"/>.
|
||||
/// </summary>
|
||||
/// <param name="type">The type of path.</param>
|
||||
/// <param name="controlPoints">The control points of the path.</param>
|
||||
/// <param name="expectedDistance">A user-set distance of the path that may be shorter or longer than the true distance between all
|
||||
/// <paramref name="controlPoints"/>. The path will be shortened/lengthened to match this length.
|
||||
/// If null, the path will use the true distance between all <paramref name="controlPoints"/>.</param>
|
||||
[JsonConstructor]
|
||||
public SliderPath(PathType type, Vector2[] controlPoints, double? expectedDistance = null)
|
||||
{
|
||||
this = default;
|
||||
this.controlPoints = controlPoints;
|
||||
|
||||
Type = type;
|
||||
ExpectedDistance = expectedDistance;
|
||||
|
||||
ensureInitialised();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The control points of the path.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public ReadOnlySpan<Vector2> ControlPoints
|
||||
{
|
||||
get
|
||||
{
|
||||
ensureInitialised();
|
||||
return controlPoints.AsSpan();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The distance of the path after lengthening/shortening to account for <see cref="ExpectedDistance"/>.
|
||||
/// </summary>
|
||||
[JsonIgnore]
|
||||
public double Distance
|
||||
{
|
||||
get
|
||||
{
|
||||
ensureInitialised();
|
||||
return cumulativeLength.Count == 0 ? 0 : cumulativeLength[cumulativeLength.Count - 1];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the slider path 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 path.</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)
|
||||
{
|
||||
ensureInitialised();
|
||||
|
||||
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));
|
||||
|
||||
for (; i < calculatedPath.Count && cumulativeLength[i] <= d1; ++i)
|
||||
path.Add(calculatedPath[i]);
|
||||
|
||||
path.Add(interpolateVertices(i, d1));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the position on the slider at a given progress that ranges from 0 (beginning of the path)
|
||||
/// to 1 (end of the path).
|
||||
/// </summary>
|
||||
/// <param name="progress">Ranges from 0 (beginning of the path) to 1 (end of the path).</param>
|
||||
/// <returns></returns>
|
||||
public Vector2 PositionAt(double progress)
|
||||
{
|
||||
ensureInitialised();
|
||||
|
||||
double d = progressToDistance(progress);
|
||||
return interpolateVertices(indexOfDistance(d), d);
|
||||
}
|
||||
|
||||
private void ensureInitialised()
|
||||
{
|
||||
if (isInitialised)
|
||||
return;
|
||||
isInitialised = true;
|
||||
|
||||
controlPoints = controlPoints ?? Array.Empty<Vector2>();
|
||||
calculatedPath = new List<Vector2>();
|
||||
cumulativeLength = new List<double>();
|
||||
|
||||
calculatePath();
|
||||
calculateCumulativeLength();
|
||||
}
|
||||
|
||||
private List<Vector2> calculateSubpath(ReadOnlySpan<Vector2> subControlPoints)
|
||||
{
|
||||
switch (PathType)
|
||||
switch (Type)
|
||||
{
|
||||
case PathType.Linear:
|
||||
return PathApproximator.ApproximateLinear(subControlPoints);
|
||||
@ -66,7 +178,7 @@ namespace osu.Game.Rulesets.Objects
|
||||
|
||||
if (i == ControlPoints.Length - 1 || ControlPoints[i] == ControlPoints[i + 1])
|
||||
{
|
||||
ReadOnlySpan<Vector2> cpSpan = ControlPoints.AsSpan().Slice(start, end - start);
|
||||
ReadOnlySpan<Vector2> cpSpan = ControlPoints.Slice(start, end - start);
|
||||
|
||||
foreach (Vector2 t in calculateSubpath(cpSpan))
|
||||
if (calculatedPath.Count == 0 || calculatedPath.Last() != t)
|
||||
@ -77,49 +189,6 @@ namespace osu.Game.Rulesets.Objects
|
||||
}
|
||||
}
|
||||
|
||||
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 paths that are too long compared to what's
|
||||
// in the .osu file.
|
||||
if (Distance - l < d)
|
||||
{
|
||||
calculatedPath[i + 1] = calculatedPath[i] + diff * (float)((Distance - l) / d);
|
||||
calculatedPath.RemoveRange(i + 2, calculatedPath.Count - 2 - i);
|
||||
|
||||
l = Distance;
|
||||
cumulativeLength.Add(l);
|
||||
break;
|
||||
}
|
||||
|
||||
l += d;
|
||||
cumulativeLength.Add(l);
|
||||
}
|
||||
|
||||
// Lengthen slider paths that are too short compared to what's
|
||||
// in the .osu file.
|
||||
if (l < Distance && 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)((Distance - l) / d);
|
||||
cumulativeLength[calculatedPath.Count - 1] = Distance;
|
||||
}
|
||||
}
|
||||
|
||||
private void calculateCumulativeLength()
|
||||
{
|
||||
double l = 0;
|
||||
@ -132,21 +201,33 @@ namespace osu.Game.Rulesets.Objects
|
||||
Vector2 diff = calculatedPath[i + 1] - calculatedPath[i];
|
||||
double d = diff.Length;
|
||||
|
||||
// Shorted slider paths that are too long compared to the expected distance
|
||||
if (ExpectedDistance.HasValue && ExpectedDistance - l < d)
|
||||
{
|
||||
calculatedPath[i + 1] = calculatedPath[i] + diff * (float)((ExpectedDistance - l) / d);
|
||||
calculatedPath.RemoveRange(i + 2, calculatedPath.Count - 2 - i);
|
||||
|
||||
l = ExpectedDistance.Value;
|
||||
cumulativeLength.Add(l);
|
||||
break;
|
||||
}
|
||||
|
||||
l += d;
|
||||
cumulativeLength.Add(l);
|
||||
}
|
||||
|
||||
Distance = l;
|
||||
}
|
||||
// Lengthen slider paths that are too short compared to the expected distance
|
||||
if (ExpectedDistance.HasValue && l < ExpectedDistance && calculatedPath.Count > 1)
|
||||
{
|
||||
Vector2 diff = calculatedPath[calculatedPath.Count - 1] - calculatedPath[calculatedPath.Count - 2];
|
||||
double d = diff.Length;
|
||||
|
||||
public void Calculate(bool updateDistance = false)
|
||||
{
|
||||
calculatePath();
|
||||
if (d <= 0)
|
||||
return;
|
||||
|
||||
if (!updateDistance)
|
||||
calculateCumulativeLengthAndTrimPath();
|
||||
else
|
||||
calculateCumulativeLength();
|
||||
calculatedPath[calculatedPath.Count - 1] += diff * (float)((ExpectedDistance - l) / d);
|
||||
cumulativeLength[calculatedPath.Count - 1] = ExpectedDistance.Value;
|
||||
}
|
||||
}
|
||||
|
||||
private int indexOfDistance(double d)
|
||||
@ -169,7 +250,7 @@ namespace osu.Game.Rulesets.Objects
|
||||
|
||||
if (i <= 0)
|
||||
return calculatedPath.First();
|
||||
else if (i >= calculatedPath.Count)
|
||||
if (i >= calculatedPath.Count)
|
||||
return calculatedPath.Last();
|
||||
|
||||
Vector2 p0 = calculatedPath[i - 1];
|
||||
@ -186,47 +267,20 @@ namespace osu.Game.Rulesets.Objects
|
||||
return p0 + (p1 - p0) * (float)w;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the slider path 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 path.</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)
|
||||
public bool Equals(SliderPath other)
|
||||
{
|
||||
if (calculatedPath.Count == 0 && ControlPoints.Length > 0)
|
||||
Calculate();
|
||||
if (ControlPoints == null && other.ControlPoints != null)
|
||||
return false;
|
||||
if (other.ControlPoints == null && ControlPoints != null)
|
||||
return false;
|
||||
|
||||
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);
|
||||
return ControlPoints.SequenceEqual(other.ControlPoints) && ExpectedDistance.Equals(other.ExpectedDistance) && Type == other.Type;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the position on the slider at a given progress that ranges from 0 (beginning of the path)
|
||||
/// to 1 (end of the path).
|
||||
/// </summary>
|
||||
/// <param name="progress">Ranges from 0 (beginning of the path) to 1 (end of the path).</param>
|
||||
/// <returns></returns>
|
||||
public Vector2 PositionAt(double progress)
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (calculatedPath.Count == 0 && ControlPoints.Length > 0)
|
||||
Calculate();
|
||||
|
||||
double d = progressToDistance(progress);
|
||||
return interpolateVertices(indexOfDistance(d), d) + Offset;
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
return obj is SliderPath other && Equals(other);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,16 +14,6 @@ namespace osu.Game.Rulesets.Objects.Types
|
||||
/// The curve.
|
||||
/// </summary>
|
||||
SliderPath Path { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The control points that shape the curve.
|
||||
/// </summary>
|
||||
Vector2[] ControlPoints { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The type of curve.
|
||||
/// </summary>
|
||||
PathType PathType { get; }
|
||||
}
|
||||
|
||||
public static class HasCurveExtensions
|
||||
|
@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
|
||||
{
|
||||
public class ConstantScrollAlgorithm : IScrollAlgorithm
|
||||
{
|
||||
public double GetDisplayStartTime(double time, double timeRange) => time - timeRange;
|
||||
|
||||
public float GetLength(double startTime, double endTime, double timeRange, float scrollLength)
|
||||
{
|
||||
// At the hitobject's end time, the hitobject will be positioned such that its end rests at the origin.
|
||||
// This results in a negative-position value, and the absolute of it indicates the length of the hitobject.
|
||||
return -PositionAt(startTime, endTime, timeRange, scrollLength);
|
||||
}
|
||||
|
||||
public float PositionAt(double time, double currentTime, double timeRange, float scrollLength)
|
||||
=> (float)((time - currentTime) / timeRange * scrollLength);
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,44 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
|
||||
{
|
||||
public interface IScrollAlgorithm
|
||||
{
|
||||
/// <summary>
|
||||
/// Given a point in time, computes the time at which it enters the time range.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// E.g. For a constant time range of 5000ms, the time at which t=7000ms enters the time range is 2000ms.
|
||||
/// </remarks>
|
||||
/// <param name="time">The point in time.</param>
|
||||
/// <param name="timeRange">The amount of visible time.</param>
|
||||
/// <returns>The time at which <paramref name="time"/> enters <see cref="timeRange"/>.</returns>
|
||||
double GetDisplayStartTime(double time, double timeRange);
|
||||
|
||||
/// <summary>
|
||||
/// Computes the spatial length within a start and end time.
|
||||
/// </summary>
|
||||
/// <param name="startTime">The start time.</param>
|
||||
/// <param name="endTime">The end time.</param>
|
||||
/// <param name="timeRange">The amount of visible time.</param>
|
||||
/// <param name="scrollLength">The absolute spatial length through <see cref="timeRange"/>.</param>
|
||||
/// <returns>The absolute spatial length.</returns>
|
||||
float GetLength(double startTime, double endTime, double timeRange, float scrollLength);
|
||||
|
||||
/// <summary>
|
||||
/// Given the current time, computes the spatial position of a point in time.
|
||||
/// </summary>
|
||||
/// <param name="time">The time to compute the spatial position of.</param>
|
||||
/// <param name="currentTime">The current time.</param>
|
||||
/// <param name="timeRange">The amount of visible time.</param>
|
||||
/// <param name="scrollLength">The absolute spatial length through <see cref="timeRange"/>.</param>
|
||||
/// <returns>The absolute spatial position.</returns>
|
||||
float PositionAt(double time, double currentTime, double timeRange, float scrollLength);
|
||||
|
||||
/// <summary>
|
||||
/// Resets this <see cref="IScrollAlgorithm"/> to a default state.
|
||||
/// </summary>
|
||||
void Reset();
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Lists;
|
||||
using osu.Game.Rulesets.Timing;
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
|
||||
{
|
||||
public class OverlappingScrollAlgorithm : IScrollAlgorithm
|
||||
{
|
||||
private readonly MultiplierControlPoint searchPoint;
|
||||
|
||||
private readonly SortedList<MultiplierControlPoint> controlPoints;
|
||||
|
||||
public OverlappingScrollAlgorithm(SortedList<MultiplierControlPoint> controlPoints)
|
||||
{
|
||||
this.controlPoints = controlPoints;
|
||||
|
||||
searchPoint = new MultiplierControlPoint();
|
||||
}
|
||||
|
||||
public double GetDisplayStartTime(double time, double timeRange)
|
||||
{
|
||||
// The total amount of time that the hitobject will remain visible within the timeRange, which decreases as the speed multiplier increases
|
||||
double visibleDuration = timeRange / controlPointAt(time).Multiplier;
|
||||
return time - visibleDuration;
|
||||
}
|
||||
|
||||
public float GetLength(double startTime, double endTime, double timeRange, float scrollLength)
|
||||
{
|
||||
// At the hitobject's end time, the hitobject will be positioned such that its end rests at the origin.
|
||||
// This results in a negative-position value, and the absolute of it indicates the length of the hitobject.
|
||||
return -PositionAt(startTime, endTime, timeRange, scrollLength);
|
||||
}
|
||||
|
||||
public float PositionAt(double time, double currentTime, double timeRange, float scrollLength)
|
||||
=> (float)((time - currentTime) / timeRange * controlPointAt(time).Multiplier * scrollLength);
|
||||
|
||||
public void Reset()
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the <see cref="MultiplierControlPoint"/> which affects the speed of hitobjects at a specific time.
|
||||
/// </summary>
|
||||
/// <param name="time">The time which the <see cref="MultiplierControlPoint"/> should affect.</param>
|
||||
/// <returns>The <see cref="MultiplierControlPoint"/>.</returns>
|
||||
private MultiplierControlPoint controlPointAt(double time)
|
||||
{
|
||||
if (controlPoints.Count == 0)
|
||||
return new MultiplierControlPoint(double.NegativeInfinity);
|
||||
|
||||
if (time < controlPoints[0].StartTime)
|
||||
return controlPoints[0];
|
||||
|
||||
searchPoint.StartTime = time;
|
||||
int index = controlPoints.BinarySearch(searchPoint);
|
||||
|
||||
if (index < 0)
|
||||
index = ~index - 1;
|
||||
|
||||
return controlPoints[index];
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
// Copyright (c) 2007-2018 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 osu.Game.Rulesets.Timing;
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Algorithms
|
||||
{
|
||||
public class SequentialScrollAlgorithm : IScrollAlgorithm
|
||||
{
|
||||
private readonly Dictionary<double, double> positionCache;
|
||||
|
||||
private readonly IReadOnlyList<MultiplierControlPoint> controlPoints;
|
||||
|
||||
public SequentialScrollAlgorithm(IReadOnlyList<MultiplierControlPoint> controlPoints)
|
||||
{
|
||||
this.controlPoints = controlPoints;
|
||||
|
||||
positionCache = new Dictionary<double, double>();
|
||||
}
|
||||
|
||||
public double GetDisplayStartTime(double time, double timeRange) => time - timeRange - 1000;
|
||||
|
||||
public float GetLength(double startTime, double endTime, double timeRange, float scrollLength)
|
||||
{
|
||||
var objectLength = relativePositionAtCached(endTime, timeRange) - relativePositionAtCached(startTime, timeRange);
|
||||
return (float)(objectLength * scrollLength);
|
||||
}
|
||||
|
||||
public float PositionAt(double time, double currentTime, double timeRange, float scrollLength)
|
||||
{
|
||||
// Caching is not used here as currentTime is unlikely to have been previously cached
|
||||
double timelinePosition = relativePositionAt(currentTime, timeRange);
|
||||
return (float)((relativePositionAtCached(time, timeRange) - timelinePosition) * scrollLength);
|
||||
}
|
||||
|
||||
private double relativePositionAtCached(double time, double timeRange)
|
||||
{
|
||||
if (!positionCache.TryGetValue(time, out double existing))
|
||||
positionCache[time] = existing = relativePositionAt(time, timeRange);
|
||||
return existing;
|
||||
}
|
||||
|
||||
public void Reset() => positionCache.Clear();
|
||||
|
||||
/// <summary>
|
||||
/// Finds the position which corresponds to a point in time.
|
||||
/// This is a non-linear operation that depends on all the control points up to and including the one active at the time value.
|
||||
/// </summary>
|
||||
/// <param name="time">The time to find the position at.</param>
|
||||
/// <param name="timeRange">The amount of time visualised by the scrolling area.</param>
|
||||
/// <returns>A positive value indicating the position at <paramref name="time"/>.</returns>
|
||||
private double relativePositionAt(double time, double timeRange)
|
||||
{
|
||||
if (controlPoints.Count == 0)
|
||||
return time / timeRange;
|
||||
|
||||
double length = 0;
|
||||
|
||||
// We need to consider all timing points until the specified time and not just the currently-active one,
|
||||
// since each timing point individually affects the positions of _all_ hitobjects after its start time
|
||||
for (int i = 0; i < controlPoints.Count; i++)
|
||||
{
|
||||
var current = controlPoints[i];
|
||||
var next = i < controlPoints.Count - 1 ? controlPoints[i + 1] : null;
|
||||
|
||||
// We don't need to consider any control points beyond the current time, since it will not yet
|
||||
// affect any hitobjects
|
||||
if (i > 0 && current.StartTime > time)
|
||||
continue;
|
||||
|
||||
// Duration of the current control point
|
||||
var currentDuration = (next?.StartTime ?? double.PositiveInfinity) - current.StartTime;
|
||||
|
||||
// We want to consider the minimal amount of time that this control point has affected,
|
||||
// which may be either its duration, or the amount of time that has passed within it
|
||||
var durationInCurrent = Math.Min(currentDuration, time - current.StartTime);
|
||||
|
||||
// Figure out how much of the time range the duration represents, and adjust it by the speed multiplier
|
||||
length += durationInCurrent / timeRange * current.Multiplier;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
}
|
||||
}
|
@ -7,8 +7,9 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Lists;
|
||||
using osu.Game.Configuration;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Timing;
|
||||
using osu.Game.Rulesets.UI.Scrolling.Visualisers;
|
||||
using osu.Game.Rulesets.UI.Scrolling.Algorithms;
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling
|
||||
{
|
||||
@ -30,11 +31,11 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
|
||||
public readonly Bindable<ScrollingDirection> Direction = new Bindable<ScrollingDirection>();
|
||||
|
||||
private readonly IScrollAlgorithm algorithm;
|
||||
|
||||
private Cached initialStateCache = new Cached();
|
||||
|
||||
private readonly ISpeedChangeVisualiser speedChangeVisualiser;
|
||||
|
||||
public ScrollingHitObjectContainer(SpeedChangeVisualisationMethod visualisationMethod)
|
||||
public ScrollingHitObjectContainer(ScrollVisualisationMethod visualisationMethod)
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
@ -43,14 +44,14 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
|
||||
switch (visualisationMethod)
|
||||
{
|
||||
case SpeedChangeVisualisationMethod.Sequential:
|
||||
speedChangeVisualiser = new SequentialSpeedChangeVisualiser(ControlPoints);
|
||||
case ScrollVisualisationMethod.Sequential:
|
||||
algorithm = new SequentialScrollAlgorithm(ControlPoints);
|
||||
break;
|
||||
case SpeedChangeVisualisationMethod.Overlapping:
|
||||
speedChangeVisualiser = new OverlappingSpeedChangeVisualiser(ControlPoints);
|
||||
case ScrollVisualisationMethod.Overlapping:
|
||||
algorithm = new OverlappingScrollAlgorithm(ControlPoints);
|
||||
break;
|
||||
case SpeedChangeVisualisationMethod.Constant:
|
||||
speedChangeVisualiser = new ConstantSpeedChangeVisualiser();
|
||||
case ScrollVisualisationMethod.Constant:
|
||||
algorithm = new ConstantScrollAlgorithm();
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -91,23 +92,87 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
return base.Invalidate(invalidation, source, shallPropagate);
|
||||
}
|
||||
|
||||
private float scrollLength;
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
if (!initialStateCache.IsValid)
|
||||
{
|
||||
speedChangeVisualiser.ComputeInitialStates(Objects, Direction, TimeRange, DrawSize);
|
||||
switch (Direction.Value)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
case ScrollingDirection.Down:
|
||||
scrollLength = DrawSize.Y;
|
||||
break;
|
||||
default:
|
||||
scrollLength = DrawSize.X;
|
||||
break;
|
||||
}
|
||||
|
||||
algorithm.Reset();
|
||||
|
||||
foreach (var obj in Objects)
|
||||
computeInitialStateRecursive(obj);
|
||||
initialStateCache.Validate();
|
||||
}
|
||||
}
|
||||
|
||||
private void computeInitialStateRecursive(DrawableHitObject hitObject)
|
||||
{
|
||||
hitObject.LifetimeStart = algorithm.GetDisplayStartTime(hitObject.HitObject.StartTime, TimeRange);
|
||||
|
||||
if (hitObject.HitObject is IHasEndTime endTime)
|
||||
{
|
||||
switch (Direction.Value)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
case ScrollingDirection.Down:
|
||||
hitObject.Height = algorithm.GetLength(hitObject.HitObject.StartTime, endTime.EndTime, TimeRange, scrollLength);
|
||||
break;
|
||||
case ScrollingDirection.Left:
|
||||
case ScrollingDirection.Right:
|
||||
hitObject.Width = algorithm.GetLength(hitObject.HitObject.StartTime, endTime.EndTime, TimeRange, scrollLength);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var obj in hitObject.NestedHitObjects)
|
||||
{
|
||||
computeInitialStateRecursive(obj);
|
||||
|
||||
// Nested hitobjects don't need to scroll, but they do need accurate positions
|
||||
updatePosition(obj, hitObject.HitObject.StartTime);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void UpdateAfterChildrenLife()
|
||||
{
|
||||
base.UpdateAfterChildrenLife();
|
||||
|
||||
// We need to calculate this as soon as possible after lifetimes so that hitobjects get the final say in their positions
|
||||
speedChangeVisualiser.UpdatePositions(AliveObjects, Direction, Time.Current, TimeRange, DrawSize);
|
||||
// We need to calculate hitobject positions as soon as possible after lifetimes so that hitobjects get the final say in their positions
|
||||
foreach (var obj in AliveObjects)
|
||||
updatePosition(obj, Time.Current);
|
||||
}
|
||||
|
||||
private void updatePosition(DrawableHitObject hitObject, double currentTime)
|
||||
{
|
||||
switch (Direction.Value)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
hitObject.Y = algorithm.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
|
||||
break;
|
||||
case ScrollingDirection.Down:
|
||||
hitObject.Y = -algorithm.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
|
||||
break;
|
||||
case ScrollingDirection.Left:
|
||||
hitObject.X = algorithm.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
|
||||
break;
|
||||
case ScrollingDirection.Right:
|
||||
hitObject.X = -algorithm.PositionAt(hitObject.HitObject.StartTime, currentTime, TimeRange, scrollLength);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -63,7 +63,7 @@ namespace osu.Game.Rulesets.UI.Scrolling
|
||||
/// </summary>
|
||||
protected readonly Bindable<ScrollingDirection> Direction = new Bindable<ScrollingDirection>();
|
||||
|
||||
protected virtual SpeedChangeVisualisationMethod VisualisationMethod => SpeedChangeVisualisationMethod.Sequential;
|
||||
protected virtual ScrollVisualisationMethod VisualisationMethod => ScrollVisualisationMethod.Sequential;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
|
@ -1,67 +0,0 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
||||
{
|
||||
public class ConstantSpeedChangeVisualiser : ISpeedChangeVisualiser
|
||||
{
|
||||
public void ComputeInitialStates(IEnumerable<DrawableHitObject> hitObjects, ScrollingDirection direction, double timeRange, Vector2 length)
|
||||
{
|
||||
foreach (var obj in hitObjects)
|
||||
{
|
||||
obj.LifetimeStart = obj.HitObject.StartTime - timeRange;
|
||||
|
||||
if (obj.HitObject is IHasEndTime endTime)
|
||||
{
|
||||
var hitObjectLength = (endTime.EndTime - obj.HitObject.StartTime) / timeRange;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
case ScrollingDirection.Down:
|
||||
obj.Height = (float)(hitObjectLength * length.Y);
|
||||
break;
|
||||
case ScrollingDirection.Left:
|
||||
case ScrollingDirection.Right:
|
||||
obj.Width = (float)(hitObjectLength * length.X);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length);
|
||||
|
||||
// Nested hitobjects don't need to scroll, but they do need accurate positions
|
||||
UpdatePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePositions(IEnumerable<DrawableHitObject> hitObjects, ScrollingDirection direction, double currentTime, double timeRange, Vector2 length)
|
||||
{
|
||||
foreach (var obj in hitObjects)
|
||||
{
|
||||
var position = (obj.HitObject.StartTime - currentTime) / timeRange;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
obj.Y = (float)(position * length.Y);
|
||||
break;
|
||||
case ScrollingDirection.Down:
|
||||
obj.Y = (float)(-position * length.Y);
|
||||
break;
|
||||
case ScrollingDirection.Left:
|
||||
obj.X = (float)(position * length.X);
|
||||
break;
|
||||
case ScrollingDirection.Right:
|
||||
obj.X = (float)(-position * length.X);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
||||
{
|
||||
public interface ISpeedChangeVisualiser
|
||||
{
|
||||
/// <summary>
|
||||
/// Computes the states of <see cref="DrawableHitObject"/>s that remain constant while scrolling, such as lifetime and spatial length.
|
||||
/// This is invoked once whenever <paramref name="timeRange"/> or <paramref name="length"/> changes.
|
||||
/// </summary>
|
||||
/// <param name="hitObjects">The <see cref="DrawableHitObject"/>s whose states should be computed.</param>
|
||||
/// <param name="direction">The scrolling direction.</param>
|
||||
/// <param name="timeRange">The duration required to scroll through one length of the screen before any speed adjustments.</param>
|
||||
/// <param name="length">The length of the screen that is scrolled through.</param>
|
||||
void ComputeInitialStates(IEnumerable<DrawableHitObject> hitObjects, ScrollingDirection direction, double timeRange, Vector2 length);
|
||||
|
||||
/// <summary>
|
||||
/// Updates the positions of <see cref="DrawableHitObject"/>s, depending on the current time. This is invoked once per frame.
|
||||
/// </summary>
|
||||
/// <param name="hitObjects">The <see cref="DrawableHitObject"/>s whose positions should be computed.</param>
|
||||
/// <param name="direction">The scrolling direction.</param>
|
||||
/// <param name="currentTime">The current time.</param>
|
||||
/// <param name="timeRange">The duration required to scroll through one length of the screen before any speed adjustments.</param>
|
||||
/// <param name="length">The length of the screen that is scrolled through.</param>
|
||||
void UpdatePositions(IEnumerable<DrawableHitObject> hitObjects, ScrollingDirection direction, double currentTime, double timeRange, Vector2 length);
|
||||
}
|
||||
}
|
@ -1,120 +0,0 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Lists;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Timing;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
||||
{
|
||||
public class OverlappingSpeedChangeVisualiser : ISpeedChangeVisualiser
|
||||
{
|
||||
private readonly SortedList<MultiplierControlPoint> controlPoints;
|
||||
|
||||
public OverlappingSpeedChangeVisualiser(SortedList<MultiplierControlPoint> controlPoints)
|
||||
{
|
||||
this.controlPoints = controlPoints;
|
||||
}
|
||||
|
||||
public void ComputeInitialStates(IEnumerable<DrawableHitObject> hitObjects, ScrollingDirection direction, double timeRange, Vector2 length)
|
||||
{
|
||||
foreach (var obj in hitObjects)
|
||||
{
|
||||
// The total amount of time that the hitobject will remain visible within the timeRange, which decreases as the speed multiplier increases
|
||||
double visibleDuration = timeRange / controlPointAt(obj.HitObject.StartTime).Multiplier;
|
||||
|
||||
obj.LifetimeStart = obj.HitObject.StartTime - visibleDuration;
|
||||
|
||||
if (obj.HitObject is IHasEndTime endTime)
|
||||
{
|
||||
// At the hitobject's end time, the hitobject will be positioned such that its end rests at the origin.
|
||||
// This results in a negative-position value, and the absolute of it indicates the length of the hitobject.
|
||||
var hitObjectLength = -hitObjectPositionAt(obj, endTime.EndTime, timeRange);
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
case ScrollingDirection.Down:
|
||||
obj.Height = (float)(hitObjectLength * length.Y);
|
||||
break;
|
||||
case ScrollingDirection.Left:
|
||||
case ScrollingDirection.Right:
|
||||
obj.Width = (float)(hitObjectLength * length.X);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length);
|
||||
|
||||
// Nested hitobjects don't need to scroll, but they do need accurate positions
|
||||
UpdatePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePositions(IEnumerable<DrawableHitObject> hitObjects, ScrollingDirection direction, double currentTime, double timeRange, Vector2 length)
|
||||
{
|
||||
foreach (var obj in hitObjects)
|
||||
{
|
||||
var position = hitObjectPositionAt(obj, currentTime, timeRange);
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
obj.Y = (float)(position * length.Y);
|
||||
break;
|
||||
case ScrollingDirection.Down:
|
||||
obj.Y = (float)(-position * length.Y);
|
||||
break;
|
||||
case ScrollingDirection.Left:
|
||||
obj.X = (float)(position * length.X);
|
||||
break;
|
||||
case ScrollingDirection.Right:
|
||||
obj.X = (float)(-position * length.X);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Computes the position of a <see cref="DrawableHitObject"/> at a point in time.
|
||||
/// <para>
|
||||
/// At t < startTime, position > 0. <br />
|
||||
/// At t = startTime, position = 0. <br />
|
||||
/// At t > startTime, position < 0.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="obj">The <see cref="DrawableHitObject"/>.</param>
|
||||
/// <param name="time">The time to find the position of <paramref name="obj"/> at.</param>
|
||||
/// <param name="timeRange">The amount of time visualised by the scrolling area.</param>
|
||||
/// <returns>The position of <paramref name="obj"/> in the scrolling area at time = <paramref name="time"/>.</returns>
|
||||
private double hitObjectPositionAt(DrawableHitObject obj, double time, double timeRange)
|
||||
=> (obj.HitObject.StartTime - time) / timeRange * controlPointAt(obj.HitObject.StartTime).Multiplier;
|
||||
|
||||
private readonly MultiplierControlPoint searchPoint = new MultiplierControlPoint();
|
||||
|
||||
/// <summary>
|
||||
/// Finds the <see cref="MultiplierControlPoint"/> which affects the speed of hitobjects at a specific time.
|
||||
/// </summary>
|
||||
/// <param name="time">The time which the <see cref="MultiplierControlPoint"/> should affect.</param>
|
||||
/// <returns>The <see cref="MultiplierControlPoint"/>.</returns>
|
||||
private MultiplierControlPoint controlPointAt(double time)
|
||||
{
|
||||
if (controlPoints.Count == 0)
|
||||
return new MultiplierControlPoint(double.NegativeInfinity);
|
||||
|
||||
if (time < controlPoints[0].StartTime)
|
||||
return controlPoints[0];
|
||||
|
||||
searchPoint.StartTime = time;
|
||||
int index = controlPoints.BinarySearch(searchPoint);
|
||||
|
||||
if (index < 0)
|
||||
index = ~index - 1;
|
||||
|
||||
return controlPoints[index];
|
||||
}
|
||||
}
|
||||
}
|
@ -1,124 +0,0 @@
|
||||
// Copyright (c) 2007-2018 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 osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Objects.Types;
|
||||
using osu.Game.Rulesets.Timing;
|
||||
using OpenTK;
|
||||
|
||||
namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
||||
{
|
||||
public class SequentialSpeedChangeVisualiser : ISpeedChangeVisualiser
|
||||
{
|
||||
private readonly Dictionary<DrawableHitObject, double> hitObjectPositions = new Dictionary<DrawableHitObject, double>();
|
||||
|
||||
private readonly IReadOnlyList<MultiplierControlPoint> controlPoints;
|
||||
|
||||
public SequentialSpeedChangeVisualiser(IReadOnlyList<MultiplierControlPoint> controlPoints)
|
||||
{
|
||||
this.controlPoints = controlPoints;
|
||||
}
|
||||
|
||||
public void ComputeInitialStates(IEnumerable<DrawableHitObject> hitObjects, ScrollingDirection direction, double timeRange, Vector2 length)
|
||||
{
|
||||
foreach (var obj in hitObjects)
|
||||
{
|
||||
// To reduce iterations when updating hitobject positions later on, their initial positions are cached
|
||||
var startPosition = hitObjectPositions[obj] = positionAt(obj.HitObject.StartTime, timeRange);
|
||||
|
||||
// Todo: This is approximate and will be incorrect in the case of extreme speed changes
|
||||
obj.LifetimeStart = obj.HitObject.StartTime - timeRange - 1000;
|
||||
|
||||
if (obj.HitObject is IHasEndTime endTime)
|
||||
{
|
||||
var hitObjectLength = positionAt(endTime.EndTime, timeRange) - startPosition;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
case ScrollingDirection.Down:
|
||||
obj.Height = (float)(hitObjectLength * length.Y);
|
||||
break;
|
||||
case ScrollingDirection.Left:
|
||||
case ScrollingDirection.Right:
|
||||
obj.Width = (float)(hitObjectLength * length.X);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length);
|
||||
|
||||
// Nested hitobjects don't need to scroll, but they do need accurate positions
|
||||
UpdatePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length);
|
||||
}
|
||||
}
|
||||
|
||||
public void UpdatePositions(IEnumerable<DrawableHitObject> hitObjects, ScrollingDirection direction, double currentTime, double timeRange, Vector2 length)
|
||||
{
|
||||
var timelinePosition = positionAt(currentTime, timeRange);
|
||||
|
||||
foreach (var obj in hitObjects)
|
||||
{
|
||||
var finalPosition = hitObjectPositions[obj] - timelinePosition;
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
case ScrollingDirection.Up:
|
||||
obj.Y = (float)(finalPosition * length.Y);
|
||||
break;
|
||||
case ScrollingDirection.Down:
|
||||
obj.Y = (float)(-finalPosition * length.Y);
|
||||
break;
|
||||
case ScrollingDirection.Left:
|
||||
obj.X = (float)(finalPosition * length.X);
|
||||
break;
|
||||
case ScrollingDirection.Right:
|
||||
obj.X = (float)(-finalPosition * length.X);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds the position which corresponds to a point in time.
|
||||
/// This is a non-linear operation that depends on all the control points up to and including the one active at the time value.
|
||||
/// </summary>
|
||||
/// <param name="time">The time to find the position at.</param>
|
||||
/// <param name="timeRange">The amount of time visualised by the scrolling area.</param>
|
||||
/// <returns>A positive value indicating the position at <paramref name="time"/>.</returns>
|
||||
private double positionAt(double time, double timeRange)
|
||||
{
|
||||
if (controlPoints.Count == 0)
|
||||
return time / timeRange;
|
||||
|
||||
double length = 0;
|
||||
|
||||
// We need to consider all timing points until the specified time and not just the currently-active one,
|
||||
// since each timing point individually affects the positions of _all_ hitobjects after its start time
|
||||
for (int i = 0; i < controlPoints.Count; i++)
|
||||
{
|
||||
var current = controlPoints[i];
|
||||
var next = i < controlPoints.Count - 1 ? controlPoints[i + 1] : null;
|
||||
|
||||
// We don't need to consider any control points beyond the current time, since it will not yet
|
||||
// affect any hitobjects
|
||||
if (i > 0 && current.StartTime > time)
|
||||
continue;
|
||||
|
||||
// Duration of the current control point
|
||||
var currentDuration = (next?.StartTime ?? double.PositiveInfinity) - current.StartTime;
|
||||
|
||||
// We want to consider the minimal amount of time that this control point has affected,
|
||||
// which may be either its duration, or the amount of time that has passed within it
|
||||
var durationInCurrent = Math.Min(currentDuration, time - current.StartTime);
|
||||
|
||||
// Figure out how much of the time range the duration represents, and adjust it by the speed multiplier
|
||||
length += durationInCurrent / timeRange * current.Multiplier;
|
||||
}
|
||||
|
||||
return length;
|
||||
}
|
||||
}
|
||||
}
|
@ -18,7 +18,7 @@
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.1.4" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.1.4" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2018.1105.0" />
|
||||
<PackageReference Include="ppy.osu.Framework" Version="2018.1112.0" />
|
||||
<PackageReference Include="SharpCompress" Version="0.22.0" />
|
||||
<PackageReference Include="NUnit" Version="3.11.0" />
|
||||
<PackageReference Include="SharpRaven" Version="2.4.0" />
|
||||
|
Loading…
Reference in New Issue
Block a user