2019-01-24 08:43:03 +00:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2019-12-27 15:47:46 +00:00
|
|
|
|
using System.Linq;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using NUnit.Framework;
|
2019-04-10 08:54:57 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2019-12-27 15:47:46 +00:00
|
|
|
|
using osu.Framework.Threading;
|
2018-11-06 03:01:54 +00:00
|
|
|
|
using osu.Game.Configuration;
|
2019-04-10 08:54:57 +00:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
|
using osu.Game.Rulesets.Timing;
|
|
|
|
|
using osu.Game.Rulesets.UI;
|
|
|
|
|
using osu.Game.Rulesets.UI.Scrolling;
|
2019-03-24 16:02:36 +00:00
|
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-03-24 16:02:36 +00:00
|
|
|
|
namespace osu.Game.Tests.Visual.Gameplay
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
[TestFixture]
|
2019-05-14 19:37:25 +00:00
|
|
|
|
public class TestSceneScrollingHitObjects : OsuTestScene
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(Playfield) };
|
|
|
|
|
|
2019-04-10 08:54:57 +00:00
|
|
|
|
[Cached(typeof(IReadOnlyList<Mod>))]
|
|
|
|
|
private IReadOnlyList<Mod> mods { get; set; } = Array.Empty<Mod>();
|
|
|
|
|
|
2019-12-27 15:47:46 +00:00
|
|
|
|
private const int spawn_interval = 5000;
|
|
|
|
|
|
2018-11-06 06:46:36 +00:00
|
|
|
|
private readonly ScrollingTestContainer[] scrollContainers = new ScrollingTestContainer[4];
|
2018-04-13 09:19:50 +00:00
|
|
|
|
private readonly TestPlayfield[] playfields = new TestPlayfield[4];
|
2019-12-27 15:47:46 +00:00
|
|
|
|
private ScheduledDelegate hitObjectSpawnDelegate;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-12-27 15:47:46 +00:00
|
|
|
|
[SetUp]
|
2019-12-27 16:16:43 +00:00
|
|
|
|
public void Setup() => Schedule(() =>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-12-27 15:47:46 +00:00
|
|
|
|
Child = new GridContainer
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
2018-11-06 06:46:36 +00:00
|
|
|
|
scrollContainers[0] = new ScrollingTestContainer(ScrollingDirection.Up)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-12-27 15:47:46 +00:00
|
|
|
|
Child = playfields[0] = new TestPlayfield(),
|
|
|
|
|
TimeRange = spawn_interval
|
2018-11-06 06:46:36 +00:00
|
|
|
|
},
|
2019-12-26 19:17:51 +00:00
|
|
|
|
scrollContainers[1] = new ScrollingTestContainer(ScrollingDirection.Down)
|
2018-11-06 06:46:36 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-12-27 15:47:46 +00:00
|
|
|
|
Child = playfields[1] = new TestPlayfield(),
|
|
|
|
|
TimeRange = spawn_interval
|
2018-11-06 06:46:36 +00:00
|
|
|
|
},
|
2018-04-13 09:19:50 +00:00
|
|
|
|
},
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
2019-12-26 19:17:51 +00:00
|
|
|
|
scrollContainers[2] = new ScrollingTestContainer(ScrollingDirection.Left)
|
2018-11-06 06:46:36 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-12-27 15:47:46 +00:00
|
|
|
|
Child = playfields[2] = new TestPlayfield(),
|
|
|
|
|
TimeRange = spawn_interval
|
2018-11-06 06:46:36 +00:00
|
|
|
|
},
|
2019-12-26 19:17:51 +00:00
|
|
|
|
scrollContainers[3] = new ScrollingTestContainer(ScrollingDirection.Right)
|
2018-11-06 06:46:36 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2019-12-27 15:47:46 +00:00
|
|
|
|
Child = playfields[3] = new TestPlayfield(),
|
|
|
|
|
TimeRange = spawn_interval
|
2018-11-06 06:46:36 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2019-12-27 15:47:46 +00:00
|
|
|
|
};
|
2018-11-06 03:01:54 +00:00
|
|
|
|
|
2019-12-27 15:47:46 +00:00
|
|
|
|
setUpHitObjects();
|
2019-12-27 16:16:43 +00:00
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-12-27 15:47:46 +00:00
|
|
|
|
private void setUpHitObjects()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-11-06 06:46:36 +00:00
|
|
|
|
scrollContainers.ForEach(c => c.ControlPoints.Add(new MultiplierControlPoint(0)));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-12-27 15:47:46 +00:00
|
|
|
|
for (int i = 0; i <= spawn_interval; i += 1000)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
addHitObject(Time.Current + i);
|
|
|
|
|
|
2019-12-27 15:47:46 +00:00
|
|
|
|
hitObjectSpawnDelegate?.Cancel();
|
|
|
|
|
hitObjectSpawnDelegate = Scheduler.AddDelayed(() => addHitObject(Time.Current + spawn_interval), 1000, true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestScrollAlgorithms()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Constant scroll", () => setScrollAlgorithm(ScrollVisualisationMethod.Constant));
|
|
|
|
|
AddStep("Overlapping scroll", () => setScrollAlgorithm(ScrollVisualisationMethod.Overlapping));
|
|
|
|
|
AddStep("Sequential scroll", () => setScrollAlgorithm(ScrollVisualisationMethod.Sequential));
|
|
|
|
|
|
|
|
|
|
AddSliderStep("Time range", 100, 10000, spawn_interval, v => scrollContainers.Where(c => c != null).ForEach(c => c.TimeRange = v));
|
|
|
|
|
AddStep("Add control point", () => addControlPoint(Time.Current + spawn_interval));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Test]
|
|
|
|
|
public void TestScrollLifetime()
|
|
|
|
|
{
|
|
|
|
|
AddStep("Set constant scroll", () => setScrollAlgorithm(ScrollVisualisationMethod.Constant));
|
|
|
|
|
// scroll container time range must be less than the rate of spawning hitobjects
|
|
|
|
|
// otherwise the hitobjects will spawn already partly visible on screen and look wrong
|
|
|
|
|
AddStep("Set time range", () => scrollContainers.ForEach(c => c.TimeRange = spawn_interval / 2.0));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addHitObject(double time)
|
|
|
|
|
{
|
|
|
|
|
playfields.ForEach(p =>
|
|
|
|
|
{
|
|
|
|
|
var hitObject = new TestDrawableHitObject(time);
|
|
|
|
|
setAnchor(hitObject, p);
|
|
|
|
|
|
|
|
|
|
p.Add(hitObject);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addControlPoint(double time)
|
|
|
|
|
{
|
2018-11-06 06:46:36 +00:00
|
|
|
|
scrollContainers.ForEach(c =>
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-11-06 06:46:36 +00:00
|
|
|
|
c.ControlPoints.Add(new MultiplierControlPoint(time) { DifficultyPoint = { SpeedMultiplier = 3 } });
|
|
|
|
|
c.ControlPoints.Add(new MultiplierControlPoint(time + 2000) { DifficultyPoint = { SpeedMultiplier = 2 } });
|
|
|
|
|
c.ControlPoints.Add(new MultiplierControlPoint(time + 3000) { DifficultyPoint = { SpeedMultiplier = 1 } });
|
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-06 06:46:36 +00:00
|
|
|
|
playfields.ForEach(p =>
|
|
|
|
|
{
|
2018-04-13 09:19:50 +00:00
|
|
|
|
TestDrawableControlPoint createDrawablePoint(double t)
|
|
|
|
|
{
|
|
|
|
|
var obj = new TestDrawableControlPoint(p.Direction, t);
|
|
|
|
|
setAnchor(obj, p);
|
|
|
|
|
return obj;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
p.Add(createDrawablePoint(time));
|
|
|
|
|
p.Add(createDrawablePoint(time + 2000));
|
|
|
|
|
p.Add(createDrawablePoint(time + 3000));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setAnchor(DrawableHitObject obj, TestPlayfield playfield)
|
|
|
|
|
{
|
|
|
|
|
switch (playfield.Direction)
|
|
|
|
|
{
|
|
|
|
|
case ScrollingDirection.Up:
|
|
|
|
|
obj.Anchor = Anchor.TopCentre;
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
case ScrollingDirection.Down:
|
|
|
|
|
obj.Anchor = Anchor.BottomCentre;
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
case ScrollingDirection.Left:
|
|
|
|
|
obj.Anchor = Anchor.CentreLeft;
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
case ScrollingDirection.Right:
|
|
|
|
|
obj.Anchor = Anchor.CentreRight;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-12 08:36:19 +00:00
|
|
|
|
private void setScrollAlgorithm(ScrollVisualisationMethod algorithm) => scrollContainers.ForEach(c => c.ScrollAlgorithm = algorithm);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
private class TestPlayfield : ScrollingPlayfield
|
|
|
|
|
{
|
2018-11-06 06:46:36 +00:00
|
|
|
|
public new ScrollingDirection Direction => base.Direction.Value;
|
2018-11-06 03:01:54 +00:00
|
|
|
|
|
2018-11-06 06:46:36 +00:00
|
|
|
|
public TestPlayfield()
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Padding = new MarginPadding(2);
|
|
|
|
|
|
2018-09-21 05:35:50 +00:00
|
|
|
|
InternalChildren = new Drawable[]
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2018-09-21 05:35:50 +00:00
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0.5f,
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Child = HitObjectContainer
|
|
|
|
|
}
|
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TestDrawableControlPoint : DrawableHitObject<HitObject>
|
|
|
|
|
{
|
|
|
|
|
public TestDrawableControlPoint(ScrollingDirection direction, double time)
|
|
|
|
|
: base(new HitObject { StartTime = time })
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
|
|
2019-03-25 04:47:28 +00:00
|
|
|
|
AddInternal(new Box
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
2019-03-25 04:47:28 +00:00
|
|
|
|
});
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case ScrollingDirection.Up:
|
|
|
|
|
case ScrollingDirection.Down:
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
Height = 2;
|
|
|
|
|
break;
|
2019-04-01 03:44:46 +00:00
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
case ScrollingDirection.Left:
|
|
|
|
|
case ScrollingDirection.Right:
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
Width = 2;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class TestDrawableHitObject : DrawableHitObject<HitObject>
|
|
|
|
|
{
|
|
|
|
|
public TestDrawableHitObject(double time)
|
|
|
|
|
: base(new HitObject { StartTime = time })
|
|
|
|
|
{
|
2019-12-26 19:17:51 +00:00
|
|
|
|
Origin = Anchor.Custom;
|
|
|
|
|
OriginPosition = new Vector2(75 / 4.0f);
|
|
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
2019-03-25 04:47:28 +00:00
|
|
|
|
AddInternal(new Box { Size = new Vector2(75) });
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|