2018-03-14 19:52:48 +08:00
|
|
|
|
// 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.Audio.Track;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-03-15 17:24:57 +08:00
|
|
|
|
using osu.Framework.Timing;
|
2018-03-14 19:52:48 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
|
|
|
|
using osu.Game.Rulesets;
|
|
|
|
|
using osu.Game.Rulesets.Edit;
|
|
|
|
|
using osu.Game.Rulesets.Edit.Tools;
|
|
|
|
|
using osu.Game.Rulesets.Osu;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2018-03-19 19:42:06 +08:00
|
|
|
|
using osu.Game.Screens.Edit.Screens.Compose;
|
2018-03-14 19:52:48 +08:00
|
|
|
|
using osu.Game.Tests.Beatmaps;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Tests.Visual
|
|
|
|
|
{
|
|
|
|
|
public class TestCaseEditorSeekSnapping : OsuTestCase
|
|
|
|
|
{
|
|
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(HitObjectComposer) };
|
|
|
|
|
|
|
|
|
|
private Track track;
|
|
|
|
|
private HitObjectComposer composer;
|
|
|
|
|
|
2018-03-19 19:42:06 +08:00
|
|
|
|
private readonly BindableBeatDivisor beatDivisor = new BindableBeatDivisor(4);
|
|
|
|
|
|
2018-03-15 17:24:57 +08:00
|
|
|
|
private DecoupleableInterpolatingFramedClock clock;
|
|
|
|
|
|
2018-03-19 15:27:52 +08:00
|
|
|
|
private DependencyContainer dependencies;
|
|
|
|
|
|
|
|
|
|
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent)
|
|
|
|
|
=> dependencies = new DependencyContainer(parent);
|
|
|
|
|
|
2018-03-14 19:52:48 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuGameBase osuGame)
|
|
|
|
|
{
|
2018-03-15 17:24:57 +08:00
|
|
|
|
clock = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
|
2018-03-19 15:27:52 +08:00
|
|
|
|
dependencies.CacheAs<IAdjustableClock>(clock);
|
|
|
|
|
dependencies.CacheAs<IFrameBasedClock>(clock);
|
2018-03-19 19:42:06 +08:00
|
|
|
|
dependencies.Cache(beatDivisor);
|
2018-03-15 17:24:57 +08:00
|
|
|
|
|
2018-03-14 19:52:48 +08:00
|
|
|
|
var testBeatmap = new Beatmap
|
|
|
|
|
{
|
|
|
|
|
ControlPointInfo = new ControlPointInfo
|
|
|
|
|
{
|
|
|
|
|
TimingPoints =
|
|
|
|
|
{
|
|
|
|
|
new TimingControlPoint { Time = 0, BeatLength = 200},
|
|
|
|
|
new TimingControlPoint { Time = 100, BeatLength = 400 },
|
|
|
|
|
new TimingControlPoint { Time = 175, BeatLength = 800 },
|
|
|
|
|
new TimingControlPoint { Time = 350, BeatLength = 200 },
|
2018-03-15 14:40:52 +08:00
|
|
|
|
new TimingControlPoint { Time = 450, BeatLength = 100 },
|
|
|
|
|
new TimingControlPoint { Time = 500, BeatLength = 307.69230769230802 }
|
2018-03-14 19:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
HitObjects =
|
|
|
|
|
{
|
|
|
|
|
new HitCircle { StartTime = 0 },
|
|
|
|
|
new HitCircle { StartTime = 5000 }
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
osuGame.Beatmap.Value = new TestWorkingBeatmap(testBeatmap);
|
|
|
|
|
track = osuGame.Beatmap.Value.Track;
|
|
|
|
|
|
|
|
|
|
Child = new GridContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
2018-03-19 15:27:52 +08:00
|
|
|
|
new Drawable[] { composer = new TestHitObjectComposer(new OsuRuleset()) },
|
2018-03-15 17:24:57 +08:00
|
|
|
|
new Drawable[] { new TimingPointVisualiser(testBeatmap, track) { Clock = clock } },
|
2018-03-14 19:52:48 +08:00
|
|
|
|
},
|
|
|
|
|
RowDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.Distributed),
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-03-15 14:40:52 +08:00
|
|
|
|
testSeekNoSnapping();
|
|
|
|
|
testSeekSnappingOnBeat();
|
|
|
|
|
testSeekSnappingInBetweenBeat();
|
|
|
|
|
testSeekForwardNoSnapping();
|
|
|
|
|
testSeekForwardSnappingOnBeat();
|
2018-03-14 22:08:43 +08:00
|
|
|
|
testSeekForwardSnappingFromInBetweenBeat();
|
2018-03-15 14:40:52 +08:00
|
|
|
|
testSeekBackwardSnappingOnBeat();
|
|
|
|
|
testSeekBackwardSnappingFromInBetweenBeat();
|
|
|
|
|
testSeekingWithFloatingPointBeatLength();
|
2018-03-14 19:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests whether time is correctly seeked without snapping.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testSeekNoSnapping()
|
|
|
|
|
{
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
|
|
// Forwards
|
|
|
|
|
AddStep("Seek(0)", () => composer.SeekTo(0));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 0", () => clock.CurrentTime == 0);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(33)", () => composer.SeekTo(33));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 33", () => clock.CurrentTime == 33);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(89)", () => composer.SeekTo(89));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 89", () => clock.CurrentTime == 89);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
|
|
|
|
|
// Backwards
|
|
|
|
|
AddStep("Seek(25)", () => composer.SeekTo(25));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 25", () => clock.CurrentTime == 25);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(0)", () => composer.SeekTo(0));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 0", () => clock.CurrentTime == 0);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests whether seeking to exact beat times puts us on the beat time.
|
|
|
|
|
/// These are the white/yellow ticks on the graph.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testSeekSnappingOnBeat()
|
|
|
|
|
{
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
|
|
AddStep("Seek(0), Snap", () => composer.SeekTo(0, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 0", () => clock.CurrentTime == 0);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(50), Snap", () => composer.SeekTo(50, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 50", () => clock.CurrentTime == 50);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(100), Snap", () => composer.SeekTo(100, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 100", () => clock.CurrentTime == 100);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(175), Snap", () => composer.SeekTo(175, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 175", () => clock.CurrentTime == 175);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(350), Snap", () => composer.SeekTo(350, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 350", () => clock.CurrentTime == 350);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(400), Snap", () => composer.SeekTo(400, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 400", () => clock.CurrentTime == 400);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(450), Snap", () => composer.SeekTo(450, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 450", () => clock.CurrentTime == 450);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests whether seeking to somewhere in the middle between beats puts us on the expected beats.
|
|
|
|
|
/// For example, snapping between a white/yellow beat should put us on either the yellow or white, depending on which one we're closer too.
|
|
|
|
|
/// If
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testSeekSnappingInBetweenBeat()
|
|
|
|
|
{
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
|
|
AddStep("Seek(24), Snap", () => composer.SeekTo(24, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 0", () => clock.CurrentTime == 0);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(26), Snap", () => composer.SeekTo(26, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 50", () => clock.CurrentTime == 50);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(150), Snap", () => composer.SeekTo(150, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 100", () => clock.CurrentTime == 100);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(170), Snap", () => composer.SeekTo(170, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 175", () => clock.CurrentTime == 175);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(274), Snap", () => composer.SeekTo(274, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 175", () => clock.CurrentTime == 175);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("Seek(276), Snap", () => composer.SeekTo(276, true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 350", () => clock.CurrentTime == 350);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2018-03-15 14:40:52 +08:00
|
|
|
|
/// Tests that when seeking forward with no beat snapping, beats are never explicitly snapped to, nor the next timing point (if we've skipped it).
|
2018-03-14 19:52:48 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
private void testSeekForwardNoSnapping()
|
|
|
|
|
{
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
|
|
AddStep("SeekForward", () => composer.SeekForward());
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 50", () => clock.CurrentTime == 50);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("SeekForward", () => composer.SeekForward());
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 100", () => clock.CurrentTime == 100);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("SeekForward", () => composer.SeekForward());
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 200", () => clock.CurrentTime == 200);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("SeekForward", () => composer.SeekForward());
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 400", () => clock.CurrentTime == 400);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
AddStep("SeekForward", () => composer.SeekForward());
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 450", () => clock.CurrentTime == 450);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that when seeking forward with beat snapping, all beats are snapped to and timing points are never skipped.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testSeekForwardSnappingOnBeat()
|
|
|
|
|
{
|
|
|
|
|
reset();
|
|
|
|
|
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 50", () => clock.CurrentTime == 50);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 100", () => clock.CurrentTime == 100);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 175", () => clock.CurrentTime == 175);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 350", () => clock.CurrentTime == 350);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 400", () => clock.CurrentTime == 400);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 450", () => clock.CurrentTime == 450);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that when seeking forward from in-between two beats, the next beat or timing point is snapped to, and no beats are skipped.
|
2018-03-14 22:08:43 +08:00
|
|
|
|
/// This will also test being extremely close to the next beat/timing point, to ensure rounding is not an issue.
|
2018-03-14 19:52:48 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
private void testSeekForwardSnappingFromInBetweenBeat()
|
|
|
|
|
{
|
|
|
|
|
reset();
|
|
|
|
|
|
2018-03-14 22:08:43 +08:00
|
|
|
|
AddStep("Seek(49)", () => composer.SeekTo(49));
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 50", () => clock.CurrentTime == 50);
|
2018-03-14 22:08:43 +08:00
|
|
|
|
AddStep("Seek(49.999)", () => composer.SeekTo(49.999));
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 50", () => clock.CurrentTime == 50);
|
2018-03-14 22:08:43 +08:00
|
|
|
|
AddStep("Seek(99)", () => composer.SeekTo(99));
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 100", () => clock.CurrentTime == 100);
|
2018-03-14 22:08:43 +08:00
|
|
|
|
AddStep("Seek(99.999)", () => composer.SeekTo(99.999));
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 100", () => clock.CurrentTime == 100);
|
2018-03-14 22:08:43 +08:00
|
|
|
|
AddStep("Seek(174)", () => composer.SeekTo(174));
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 175", () => clock.CurrentTime == 175);
|
2018-03-14 22:08:43 +08:00
|
|
|
|
AddStep("Seek(349)", () => composer.SeekTo(349));
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 350", () => clock.CurrentTime == 350);
|
2018-03-14 22:08:43 +08:00
|
|
|
|
AddStep("Seek(399)", () => composer.SeekTo(399));
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 400", () => clock.CurrentTime == 400);
|
2018-03-14 22:08:43 +08:00
|
|
|
|
AddStep("Seek(449)", () => composer.SeekTo(449));
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekForward, Snap", () => composer.SeekForward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 450", () => clock.CurrentTime == 450);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-15 14:40:52 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that when seeking backward with no beat snapping, beats are never explicitly snapped to, nor the next timing point (if we've skipped it).
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testSeekBackwardNoSnapping()
|
|
|
|
|
{
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
|
|
AddStep("Seek(450)", () => composer.SeekTo(450));
|
|
|
|
|
AddStep("SeekBackward", () => composer.SeekBackward());
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 425", () => clock.CurrentTime == 425);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekBackward", () => composer.SeekBackward());
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 375", () => clock.CurrentTime == 375);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekBackward", () => composer.SeekBackward());
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 325", () => clock.CurrentTime == 325);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekBackward", () => composer.SeekBackward());
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 125", () => clock.CurrentTime == 125);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekBackward", () => composer.SeekBackward());
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 25", () => clock.CurrentTime == 25);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekBackward", () => composer.SeekBackward());
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 0", () => clock.CurrentTime == 0);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that when seeking backward with beat snapping, all beats are snapped to and timing points are never skipped.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testSeekBackwardSnappingOnBeat()
|
|
|
|
|
{
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
|
|
AddStep("Seek(450)", () => composer.SeekTo(450));
|
|
|
|
|
AddStep("SeekBackward, Snap", () => composer.SeekBackward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 400", () => clock.CurrentTime == 400);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekBackward, Snap", () => composer.SeekBackward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 350", () => clock.CurrentTime == 350);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekBackward, Snap", () => composer.SeekBackward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 175", () => clock.CurrentTime == 175);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekBackward, Snap", () => composer.SeekBackward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 100", () => clock.CurrentTime == 100);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekBackward, Snap", () => composer.SeekBackward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 50", () => clock.CurrentTime == 50);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("SeekBackward, Snap", () => composer.SeekBackward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 0", () => clock.CurrentTime == 0);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that when seeking backward from in-between two beats, the previous beat or timing point is snapped to, and no beats are skipped.
|
|
|
|
|
/// This will also test being extremely close to the previous beat/timing point, to ensure rounding is not an issue.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testSeekBackwardSnappingFromInBetweenBeat()
|
|
|
|
|
{
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
|
|
AddStep("Seek(451)", () => composer.SeekTo(451));
|
|
|
|
|
AddStep("SeekBackward, Snap", () => composer.SeekBackward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 450", () => clock.CurrentTime == 450);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("Seek(450.999)", () => composer.SeekTo(450.999));
|
|
|
|
|
AddStep("SeekBackward, Snap", () => composer.SeekBackward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 450", () => clock.CurrentTime == 450);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("Seek(401)", () => composer.SeekTo(401));
|
|
|
|
|
AddStep("SeekBackward, Snap", () => composer.SeekBackward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 400", () => clock.CurrentTime == 400);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
AddStep("Seek(401.999)", () => composer.SeekTo(401.999));
|
|
|
|
|
AddStep("SeekBackward, Snap", () => composer.SeekBackward(true));
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 400", () => clock.CurrentTime == 400);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Tests that there are no rounding issues when snapping to beats within a timing point with a floating-point beatlength.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void testSeekingWithFloatingPointBeatLength()
|
|
|
|
|
{
|
|
|
|
|
reset();
|
|
|
|
|
|
|
|
|
|
double lastTime = 0;
|
|
|
|
|
|
|
|
|
|
AddStep("Seek(0)", () => composer.SeekTo(0));
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
|
|
|
{
|
|
|
|
|
AddStep("SeekForward, Snap", () =>
|
|
|
|
|
{
|
2018-03-15 17:24:57 +08:00
|
|
|
|
lastTime = clock.CurrentTime;
|
2018-03-15 14:40:52 +08:00
|
|
|
|
composer.SeekForward(true);
|
|
|
|
|
});
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time > lastTime", () => clock.CurrentTime > lastTime);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < 20; i++)
|
|
|
|
|
{
|
|
|
|
|
AddStep("SeekBackward, Snap", () =>
|
|
|
|
|
{
|
2018-03-15 17:24:57 +08:00
|
|
|
|
lastTime = clock.CurrentTime;
|
2018-03-15 14:40:52 +08:00
|
|
|
|
composer.SeekBackward(true);
|
|
|
|
|
});
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time < lastTime", () => clock.CurrentTime < lastTime);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-15 17:24:57 +08:00
|
|
|
|
AddAssert("Time = 0", () => clock.CurrentTime == 0);
|
2018-03-15 14:40:52 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-03-14 19:52:48 +08:00
|
|
|
|
private void reset()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Reset", () => composer.SeekTo(0));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TestHitObjectComposer : HitObjectComposer
|
|
|
|
|
{
|
2018-03-19 15:27:52 +08:00
|
|
|
|
public TestHitObjectComposer(Ruleset ruleset)
|
|
|
|
|
: base(ruleset)
|
2018-03-14 19:52:48 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override IReadOnlyList<ICompositionTool> CompositionTools => new ICompositionTool[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TimingPointVisualiser : CompositeDrawable
|
|
|
|
|
{
|
|
|
|
|
private readonly Track track;
|
|
|
|
|
|
|
|
|
|
private readonly Drawable tracker;
|
|
|
|
|
|
|
|
|
|
public TimingPointVisualiser(Beatmap beatmap, Track track)
|
|
|
|
|
{
|
|
|
|
|
this.track = track;
|
|
|
|
|
|
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Width = 0.75f;
|
|
|
|
|
|
|
|
|
|
FillFlowContainer timelineContainer;
|
|
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Name = "Background",
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = Color4.Black.Opacity(85f)
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Name = "Tracks",
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Padding = new MarginPadding(15),
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
tracker = new Box
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
RelativePositionAxes = Axes.X,
|
|
|
|
|
Width = 2,
|
|
|
|
|
Colour = Color4.Red,
|
|
|
|
|
},
|
|
|
|
|
timelineContainer = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Spacing = new Vector2(0, 5)
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
var timingPoints = beatmap.ControlPointInfo.TimingPoints;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < timingPoints.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
TimingControlPoint next = i == timingPoints.Count - 1 ? null : timingPoints[i + 1];
|
|
|
|
|
timelineContainer.Add(new TimingPointTimeline(timingPoints[i], next?.Time ?? beatmap.HitObjects.Last().StartTime, track.Length));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2018-03-15 17:24:57 +08:00
|
|
|
|
tracker.X = (float)(Time.Current / track.Length);
|
2018-03-14 19:52:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TimingPointTimeline : CompositeDrawable
|
|
|
|
|
{
|
|
|
|
|
public TimingPointTimeline(TimingControlPoint timingPoint, double endTime, double fullDuration)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Box createMainTick(double time) => new Box
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
RelativePositionAxes = Axes.X,
|
|
|
|
|
X = (float)(time / fullDuration),
|
|
|
|
|
Height = 10,
|
|
|
|
|
Width = 2
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Box createBeatTick(double time) => new Box
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
RelativePositionAxes = Axes.X,
|
|
|
|
|
X = (float)(time / fullDuration),
|
|
|
|
|
Height = 5,
|
|
|
|
|
Width = 2,
|
|
|
|
|
Colour = time > endTime ? Color4.Gray : Color4.Yellow
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
AddInternal(createMainTick(timingPoint.Time));
|
|
|
|
|
AddInternal(createMainTick(endTime));
|
|
|
|
|
|
|
|
|
|
for (double t = timingPoint.Time + timingPoint.BeatLength / 4; t < fullDuration; t += timingPoint.BeatLength / 4)
|
|
|
|
|
AddInternal(createBeatTick(t));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|