1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-16 17:43:12 +08:00

Merge branch 'master' into fix-initial-spectator-state-callback

This commit is contained in:
Dean Herbert 2021-04-22 16:22:04 +09:00 committed by GitHub
commit daafa41dc1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
61 changed files with 1213 additions and 506 deletions

View File

@ -52,6 +52,6 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.412.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2021.412.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2021.419.0" /> <PackageReference Include="ppy.osu.Framework.Android" Version="2021.422.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@ -384,16 +384,7 @@ namespace osu.Game.Rulesets.Catch.UI
{ {
updateTrailVisibility(); updateTrailVisibility();
if (hyperDashing) this.FadeColour(hyperDashing ? hyperDashColour : Color4.White, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint);
{
this.FadeColour(hyperDashColour, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint);
this.FadeTo(0.2f, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint);
}
else
{
this.FadeColour(Color4.White, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint);
this.FadeTo(1f, HYPER_DASH_TRANSITION_DURATION, Easing.OutQuint);
}
} }
private void updateTrailVisibility() => trails.DisplayTrail = Dashing || HyperDashing; private void updateTrailVisibility() => trails.DisplayTrail = Dashing || HyperDashing;

View File

@ -10,6 +10,7 @@ using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Edit.Checks; using osu.Game.Rulesets.Osu.Edit.Checks;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.UI; using osu.Game.Rulesets.Osu.UI;
using osu.Game.Tests.Beatmaps;
using osuTK; using osuTK;
namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
@ -30,25 +31,23 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
[Test] [Test]
public void TestCircleInCenter() public void TestCircleInCenter()
{ {
var beatmap = new Beatmap<HitObject> assertOk(new Beatmap<HitObject>
{ {
HitObjects = new List<HitObject> HitObjects = new List<HitObject>
{ {
new HitCircle new HitCircle
{ {
StartTime = 3000, StartTime = 3000,
Position = playfield_centre // Playfield is 640 x 480. Position = playfield_centre
} }
} }
}; });
Assert.That(check.Run(beatmap), Is.Empty);
} }
[Test] [Test]
public void TestCircleNearEdge() public void TestCircleNearEdge()
{ {
var beatmap = new Beatmap<HitObject> assertOk(new Beatmap<HitObject>
{ {
HitObjects = new List<HitObject> HitObjects = new List<HitObject>
{ {
@ -58,15 +57,13 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
Position = new Vector2(5, 5) Position = new Vector2(5, 5)
} }
} }
}; });
Assert.That(check.Run(beatmap), Is.Empty);
} }
[Test] [Test]
public void TestCircleNearEdgeStackedOffscreen() public void TestCircleNearEdgeStackedOffscreen()
{ {
var beatmap = new Beatmap<HitObject> assertOffscreenCircle(new Beatmap<HitObject>
{ {
HitObjects = new List<HitObject> HitObjects = new List<HitObject>
{ {
@ -77,15 +74,13 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
StackHeight = 5 StackHeight = 5
} }
} }
}; });
assertOffscreenCircle(beatmap);
} }
[Test] [Test]
public void TestCircleOffscreen() public void TestCircleOffscreen()
{ {
var beatmap = new Beatmap<HitObject> assertOffscreenCircle(new Beatmap<HitObject>
{ {
HitObjects = new List<HitObject> HitObjects = new List<HitObject>
{ {
@ -95,15 +90,13 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
Position = new Vector2(0, 0) Position = new Vector2(0, 0)
} }
} }
}; });
assertOffscreenCircle(beatmap);
} }
[Test] [Test]
public void TestSliderInCenter() public void TestSliderInCenter()
{ {
var beatmap = new Beatmap<HitObject> assertOk(new Beatmap<HitObject>
{ {
HitObjects = new List<HitObject> HitObjects = new List<HitObject>
{ {
@ -118,15 +111,13 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
}), }),
} }
} }
}; });
Assert.That(check.Run(beatmap), Is.Empty);
} }
[Test] [Test]
public void TestSliderNearEdge() public void TestSliderNearEdge()
{ {
var beatmap = new Beatmap<HitObject> assertOk(new Beatmap<HitObject>
{ {
HitObjects = new List<HitObject> HitObjects = new List<HitObject>
{ {
@ -141,15 +132,13 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
}), }),
} }
} }
}; });
Assert.That(check.Run(beatmap), Is.Empty);
} }
[Test] [Test]
public void TestSliderNearEdgeStackedOffscreen() public void TestSliderNearEdgeStackedOffscreen()
{ {
var beatmap = new Beatmap<HitObject> assertOffscreenSlider(new Beatmap<HitObject>
{ {
HitObjects = new List<HitObject> HitObjects = new List<HitObject>
{ {
@ -165,15 +154,13 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
StackHeight = 5 StackHeight = 5
} }
} }
}; });
assertOffscreenSlider(beatmap);
} }
[Test] [Test]
public void TestSliderOffscreenStart() public void TestSliderOffscreenStart()
{ {
var beatmap = new Beatmap<HitObject> assertOffscreenSlider(new Beatmap<HitObject>
{ {
HitObjects = new List<HitObject> HitObjects = new List<HitObject>
{ {
@ -188,15 +175,13 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
}), }),
} }
} }
}; });
assertOffscreenSlider(beatmap);
} }
[Test] [Test]
public void TestSliderOffscreenEnd() public void TestSliderOffscreenEnd()
{ {
var beatmap = new Beatmap<HitObject> assertOffscreenSlider(new Beatmap<HitObject>
{ {
HitObjects = new List<HitObject> HitObjects = new List<HitObject>
{ {
@ -211,15 +196,13 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
}), }),
} }
} }
}; });
assertOffscreenSlider(beatmap);
} }
[Test] [Test]
public void TestSliderOffscreenPath() public void TestSliderOffscreenPath()
{ {
var beatmap = new Beatmap<HitObject> assertOffscreenSlider(new Beatmap<HitObject>
{ {
HitObjects = new List<HitObject> HitObjects = new List<HitObject>
{ {
@ -236,14 +219,17 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
}), }),
} }
} }
}; });
}
assertOffscreenSlider(beatmap); private void assertOk(IBeatmap beatmap)
{
Assert.That(check.Run(beatmap, new TestWorkingBeatmap(beatmap)), Is.Empty);
} }
private void assertOffscreenCircle(IBeatmap beatmap) private void assertOffscreenCircle(IBeatmap beatmap)
{ {
var issues = check.Run(beatmap).ToList(); var issues = check.Run(beatmap, new TestWorkingBeatmap(beatmap)).ToList();
Assert.That(issues, Has.Count.EqualTo(1)); Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckOffscreenObjects.IssueTemplateOffscreenCircle); Assert.That(issues.Single().Template is CheckOffscreenObjects.IssueTemplateOffscreenCircle);
@ -251,7 +237,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor.Checks
private void assertOffscreenSlider(IBeatmap beatmap) private void assertOffscreenSlider(IBeatmap beatmap)
{ {
var issues = check.Run(beatmap).ToList(); var issues = check.Run(beatmap, new TestWorkingBeatmap(beatmap)).ToList();
Assert.That(issues, Has.Count.EqualTo(1)); Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckOffscreenObjects.IssueTemplateOffscreenSlider); Assert.That(issues.Single().Template is CheckOffscreenObjects.IssueTemplateOffscreenSlider);

View File

@ -32,7 +32,7 @@ namespace osu.Game.Rulesets.Osu.Tests
{ {
Position = new Vector2(128, 128), Position = new Vector2(128, 128),
ComboIndex = 1, ComboIndex = 1,
}), null)); })));
} }
private HitCircle prepareObject(HitCircle circle) private HitCircle prepareObject(HitCircle circle)

View File

@ -57,7 +57,7 @@ namespace osu.Game.Rulesets.Osu.Tests
new Vector2(300, 0), new Vector2(300, 0),
}), }),
RepeatCount = 1 RepeatCount = 1
}), null)); })));
} }
[Test] [Test]

View File

@ -37,7 +37,7 @@ namespace osu.Game.Rulesets.Osu.Tests
Position = new Vector2(256, 192), Position = new Vector2(256, 192),
ComboIndex = 1, ComboIndex = 1,
Duration = 1000, Duration = 1000,
}), null)); })));
AddAssert("rotation is reset", () => dho.Result.RateAdjustedRotation == 0); AddAssert("rotation is reset", () => dho.Result.RateAdjustedRotation == 0);
} }

View File

@ -21,6 +21,7 @@ using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.Replays; using osu.Game.Rulesets.Replays;
using osu.Game.Rulesets.Scoring; using osu.Game.Rulesets.Scoring;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Play;
using osu.Game.Storyboards; using osu.Game.Storyboards;
using osu.Game.Tests.Visual; using osu.Game.Tests.Visual;
using osuTK; using osuTK;
@ -193,7 +194,7 @@ namespace osu.Game.Rulesets.Osu.Tests
addSeekStep(0); addSeekStep(0);
AddStep("adjust track rate", () => Player.GameplayClockContainer.UserPlaybackRate.Value = rate); AddStep("adjust track rate", () => ((MasterGameplayClockContainer)Player.GameplayClockContainer).UserPlaybackRate.Value = rate);
addSeekStep(1000); addSeekStep(1000);
AddAssert("progress almost same", () => Precision.AlmostEquals(expectedProgress, drawableSpinner.Progress, 0.05)); AddAssert("progress almost same", () => Precision.AlmostEquals(expectedProgress, drawableSpinner.Progress, 0.05));

View File

@ -31,9 +31,9 @@ namespace osu.Game.Rulesets.Osu.Edit.Checks
new IssueTemplateOffscreenSlider(this) new IssueTemplateOffscreenSlider(this)
}; };
public IEnumerable<Issue> Run(IBeatmap beatmap) public IEnumerable<Issue> Run(IBeatmap playableBeatmap, IWorkingBeatmap workingBeatmap)
{ {
foreach (var hitobject in beatmap.HitObjects) foreach (var hitobject in playableBeatmap.HitObjects)
{ {
switch (hitobject) switch (hitobject)
{ {

View File

@ -17,6 +17,9 @@ namespace osu.Game.Rulesets.Osu.Edit
new CheckOffscreenObjects() new CheckOffscreenObjects()
}; };
public IEnumerable<Issue> Run(IBeatmap beatmap) => checks.SelectMany(check => check.Run(beatmap)); public IEnumerable<Issue> Run(IBeatmap playableBeatmap, WorkingBeatmap workingBeatmap)
{
return checks.SelectMany(check => check.Run(playableBeatmap, workingBeatmap));
}
} }
} }

View File

@ -1,25 +1,30 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects; using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Objects.Drawables;
using osu.Game.Rulesets.Osu.UI; using osu.Game.Rulesets.Osu.UI;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osuTK; using osuTK;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
public class OsuModBarrelRoll : Mod, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject> public class OsuModBarrelRoll : Mod, IUpdatableByPlayfield, IApplicableToDrawableRuleset<OsuHitObject>, IApplicableToDrawableHitObjects
{ {
private float currentRotation;
[SettingSource("Roll speed", "Rotations per minute")] [SettingSource("Roll speed", "Rotations per minute")]
public BindableNumber<double> SpinSpeed { get; } = new BindableDouble(0.5) public BindableNumber<double> SpinSpeed { get; } = new BindableDouble(0.5)
{ {
MinValue = 0.02, MinValue = 0.02,
MaxValue = 4, MaxValue = 12,
Precision = 0.01, Precision = 0.01,
}; };
@ -35,7 +40,7 @@ namespace osu.Game.Rulesets.Osu.Mods
public void Update(Playfield playfield) public void Update(Playfield playfield)
{ {
playfield.Rotation = (Direction.Value == RotationDirection.Counterclockwise ? -1 : 1) * 360 * (float)(playfield.Time.Current / 60000 * SpinSpeed.Value); playfield.Rotation = currentRotation = (Direction.Value == RotationDirection.Counterclockwise ? -1 : 1) * 360 * (float)(playfield.Time.Current / 60000 * SpinSpeed.Value);
} }
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset) public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
@ -43,5 +48,21 @@ namespace osu.Game.Rulesets.Osu.Mods
// scale the playfield to allow all hitobjects to stay within the visible region. // scale the playfield to allow all hitobjects to stay within the visible region.
drawableRuleset.Playfield.Scale = new Vector2(OsuPlayfield.BASE_SIZE.Y / OsuPlayfield.BASE_SIZE.X); drawableRuleset.Playfield.Scale = new Vector2(OsuPlayfield.BASE_SIZE.Y / OsuPlayfield.BASE_SIZE.X);
} }
public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables)
{
foreach (var d in drawables)
{
d.OnUpdate += _ =>
{
switch (d)
{
case DrawableHitCircle circle:
circle.CirclePiece.Rotation = -currentRotation;
break;
}
};
}
}
} }
} }

View File

@ -34,9 +34,9 @@ namespace osu.Game.Rulesets.Osu.Mods
var osuObject = (OsuHitObject)drawable.HitObject; var osuObject = (OsuHitObject)drawable.HitObject;
Vector2 origin = drawable.Position; Vector2 origin = drawable.Position;
// Wiggle the repeat points with the slider instead of independently. // Wiggle the repeat points and the tail with the slider instead of independently.
// Also fixes an issue with repeat points being positioned incorrectly. // Also fixes an issue with repeat points being positioned incorrectly.
if (osuObject is SliderRepeat) if (osuObject is SliderRepeat || osuObject is SliderTailCircle)
return; return;
Random objRand = new Random((int)osuObject.StartTime); Random objRand = new Random((int)osuObject.StartTime);

View File

@ -66,7 +66,11 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
return true; return true;
}, },
}, },
CirclePiece = new SkinnableDrawable(new OsuSkinComponent(CirclePieceComponent), _ => new MainCirclePiece()), CirclePiece = new SkinnableDrawable(new OsuSkinComponent(CirclePieceComponent), _ => new MainCirclePiece())
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
ApproachCircle = new ApproachCircle ApproachCircle = new ApproachCircle
{ {
Alpha = 0, Alpha = 0,

View File

@ -42,7 +42,7 @@ namespace osu.Game.Rulesets.Osu.UI
base.PopIn(); base.PopIn();
GameplayCursor.ActiveCursor.Hide(); GameplayCursor.ActiveCursor.Hide();
cursorScaleContainer.MoveTo(GameplayCursor.ActiveCursor.Position); cursorScaleContainer.Position = ToLocalSpace(GameplayCursor.ActiveCursor.ScreenSpaceDrawQuad.Centre);
clickToResumeCursor.Appear(); clickToResumeCursor.Appear();
if (localCursorContainer == null) if (localCursorContainer == null)

View File

@ -18,7 +18,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
{ {
StartTime = 400, StartTime = 400,
Major = true Major = true
}), null)); })));
AddHitObject(barLine); AddHitObject(barLine);
RemoveHitObject(barLine); RemoveHitObject(barLine);
@ -26,7 +26,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
{ {
StartTime = 200, StartTime = 200,
Major = false Major = false
}), null)); })));
AddHitObject(barLine); AddHitObject(barLine);
} }
} }

View File

@ -20,7 +20,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
Duration = 500, Duration = 500,
IsStrong = false, IsStrong = false,
TickRate = 2 TickRate = 2
}), null)); })));
AddHitObject(drumRoll); AddHitObject(drumRoll);
RemoveHitObject(drumRoll); RemoveHitObject(drumRoll);
@ -31,7 +31,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
Duration = 400, Duration = 400,
IsStrong = true, IsStrong = true,
TickRate = 16 TickRate = 16
}), null)); })));
AddHitObject(drumRoll); AddHitObject(drumRoll);
} }

View File

@ -19,7 +19,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
Type = HitType.Rim, Type = HitType.Rim,
IsStrong = false, IsStrong = false,
StartTime = 300 StartTime = 300
}), null)); })));
AddHitObject(hit); AddHitObject(hit);
RemoveHitObject(hit); RemoveHitObject(hit);
@ -29,7 +29,7 @@ namespace osu.Game.Rulesets.Taiko.Tests
Type = HitType.Centre, Type = HitType.Centre,
IsStrong = true, IsStrong = true,
StartTime = 500 StartTime = 500
}), null)); })));
AddHitObject(hit); AddHitObject(hit);
} }

View File

@ -168,6 +168,8 @@ namespace osu.Game.Tests.Beatmaps.Formats
protected override Texture GetBackground() => throw new NotImplementedException(); protected override Texture GetBackground() => throw new NotImplementedException();
protected override Track GetBeatmapTrack() => throw new NotImplementedException(); protected override Track GetBeatmapTrack() => throw new NotImplementedException();
public override Stream GetStream(string storagePath) => throw new NotImplementedException();
} }
} }
} }

View File

@ -0,0 +1,114 @@
// 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.
using System.Linq;
using Moq;
using NUnit.Framework;
using osu.Framework.Audio.Track;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks;
using osu.Game.Rulesets.Objects;
namespace osu.Game.Tests.Editing.Checks
{
[TestFixture]
public class CheckAudioQualityTest
{
private CheckAudioQuality check;
private IBeatmap beatmap;
[SetUp]
public void Setup()
{
check = new CheckAudioQuality();
beatmap = new Beatmap<HitObject>
{
BeatmapInfo = new BeatmapInfo
{
Metadata = new BeatmapMetadata { AudioFile = "abc123.jpg" }
}
};
}
[Test]
public void TestMissing()
{
// While this is a problem, it is out of scope for this check and is caught by a different one.
beatmap.Metadata.AudioFile = null;
var mock = new Mock<IWorkingBeatmap>();
mock.SetupGet(w => w.Beatmap).Returns(beatmap);
mock.SetupGet(w => w.Track).Returns((Track)null);
Assert.That(check.Run(beatmap, mock.Object), Is.Empty);
}
[Test]
public void TestAcceptable()
{
var mock = getMockWorkingBeatmap(192);
Assert.That(check.Run(beatmap, mock.Object), Is.Empty);
}
[Test]
public void TestNullBitrate()
{
var mock = getMockWorkingBeatmap(null);
var issues = check.Run(beatmap, mock.Object).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckAudioQuality.IssueTemplateNoBitrate);
}
[Test]
public void TestZeroBitrate()
{
var mock = getMockWorkingBeatmap(0);
var issues = check.Run(beatmap, mock.Object).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckAudioQuality.IssueTemplateNoBitrate);
}
[Test]
public void TestTooHighBitrate()
{
var mock = getMockWorkingBeatmap(320);
var issues = check.Run(beatmap, mock.Object).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckAudioQuality.IssueTemplateTooHighBitrate);
}
[Test]
public void TestTooLowBitrate()
{
var mock = getMockWorkingBeatmap(64);
var issues = check.Run(beatmap, mock.Object).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckAudioQuality.IssueTemplateTooLowBitrate);
}
/// <summary>
/// Returns the mock of the working beatmap with the given audio properties.
/// </summary>
/// <param name="audioBitrate">The bitrate of the audio file the beatmap uses.</param>
private Mock<IWorkingBeatmap> getMockWorkingBeatmap(int? audioBitrate)
{
var mockTrack = new Mock<Track>();
mockTrack.SetupGet(t => t.Bitrate).Returns(audioBitrate);
var mockWorkingBeatmap = new Mock<IWorkingBeatmap>();
mockWorkingBeatmap.SetupGet(w => w.Beatmap).Returns(beatmap);
mockWorkingBeatmap.SetupGet(w => w.Track).Returns(mockTrack.Object);
return mockWorkingBeatmap;
}
}
}

View File

@ -0,0 +1,130 @@
// 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.
using System.Collections.Generic;
using System.IO;
using System.Linq;
using JetBrains.Annotations;
using Moq;
using NUnit.Framework;
using osu.Framework.Graphics.Textures;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks;
using osu.Game.Rulesets.Objects;
using FileInfo = osu.Game.IO.FileInfo;
namespace osu.Game.Tests.Editing.Checks
{
[TestFixture]
public class CheckBackgroundQualityTest
{
private CheckBackgroundQuality check;
private IBeatmap beatmap;
[SetUp]
public void Setup()
{
check = new CheckBackgroundQuality();
beatmap = new Beatmap<HitObject>
{
BeatmapInfo = new BeatmapInfo
{
Metadata = new BeatmapMetadata { BackgroundFile = "abc123.jpg" },
BeatmapSet = new BeatmapSetInfo
{
Files = new List<BeatmapSetFileInfo>(new[]
{
new BeatmapSetFileInfo
{
Filename = "abc123.jpg",
FileInfo = new FileInfo
{
Hash = "abcdef"
}
}
})
}
}
};
}
[Test]
public void TestMissing()
{
// While this is a problem, it is out of scope for this check and is caught by a different one.
beatmap.Metadata.BackgroundFile = null;
var mock = getMockWorkingBeatmap(null, System.Array.Empty<byte>());
Assert.That(check.Run(beatmap, mock.Object), Is.Empty);
}
[Test]
public void TestAcceptable()
{
var mock = getMockWorkingBeatmap(new Texture(1920, 1080));
Assert.That(check.Run(beatmap, mock.Object), Is.Empty);
}
[Test]
public void TestTooHighResolution()
{
var mock = getMockWorkingBeatmap(new Texture(3840, 2160));
var issues = check.Run(beatmap, mock.Object).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckBackgroundQuality.IssueTemplateTooHighResolution);
}
[Test]
public void TestLowResolution()
{
var mock = getMockWorkingBeatmap(new Texture(640, 480));
var issues = check.Run(beatmap, mock.Object).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckBackgroundQuality.IssueTemplateLowResolution);
}
[Test]
public void TestTooLowResolution()
{
var mock = getMockWorkingBeatmap(new Texture(100, 100));
var issues = check.Run(beatmap, mock.Object).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckBackgroundQuality.IssueTemplateTooLowResolution);
}
[Test]
public void TestTooUncompressed()
{
var mock = getMockWorkingBeatmap(new Texture(1920, 1080), new byte[1024 * 1024 * 3]);
var issues = check.Run(beatmap, mock.Object).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckBackgroundQuality.IssueTemplateTooUncompressed);
}
/// <summary>
/// Returns the mock of the working beatmap with the given background and filesize.
/// </summary>
/// <param name="background">The texture of the background.</param>
/// <param name="fileBytes">The bytes that represent the background file.</param>
private Mock<IWorkingBeatmap> getMockWorkingBeatmap(Texture background, [CanBeNull] byte[] fileBytes = null)
{
var stream = new MemoryStream(fileBytes ?? new byte[1024 * 1024]);
var mock = new Mock<IWorkingBeatmap>();
mock.SetupGet(w => w.Beatmap).Returns(beatmap);
mock.SetupGet(w => w.Background).Returns(background);
mock.Setup(w => w.GetStream(It.IsAny<string>())).Returns(stream);
return mock;
}
}
}

View File

@ -5,21 +5,23 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.IO;
using osu.Game.Rulesets.Edit.Checks; using osu.Game.Rulesets.Edit.Checks;
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Tests.Beatmaps;
namespace osu.Game.Tests.Editing.Checks namespace osu.Game.Tests.Editing.Checks
{ {
[TestFixture] [TestFixture]
public class CheckBackgroundTest public class CheckFilePresenceTest
{ {
private CheckBackground check; private CheckBackgroundPresence check;
private IBeatmap beatmap; private IBeatmap beatmap;
[SetUp] [SetUp]
public void Setup() public void Setup()
{ {
check = new CheckBackground(); check = new CheckBackgroundPresence();
beatmap = new Beatmap<HitObject> beatmap = new Beatmap<HitObject>
{ {
BeatmapInfo = new BeatmapInfo BeatmapInfo = new BeatmapInfo
@ -29,7 +31,11 @@ namespace osu.Game.Tests.Editing.Checks
{ {
Files = new List<BeatmapSetFileInfo>(new[] Files = new List<BeatmapSetFileInfo>(new[]
{ {
new BeatmapSetFileInfo { Filename = "abc123.jpg" } new BeatmapSetFileInfo
{
Filename = "abc123.jpg",
FileInfo = new FileInfo { Hash = "abcdef" }
}
}) })
} }
} }
@ -39,7 +45,7 @@ namespace osu.Game.Tests.Editing.Checks
[Test] [Test]
public void TestBackgroundSetAndInFiles() public void TestBackgroundSetAndInFiles()
{ {
Assert.That(check.Run(beatmap), Is.Empty); Assert.That(check.Run(beatmap, new TestWorkingBeatmap(beatmap)), Is.Empty);
} }
[Test] [Test]
@ -47,10 +53,10 @@ namespace osu.Game.Tests.Editing.Checks
{ {
beatmap.BeatmapInfo.BeatmapSet.Files.Clear(); beatmap.BeatmapInfo.BeatmapSet.Files.Clear();
var issues = check.Run(beatmap).ToList(); var issues = check.Run(beatmap, new TestWorkingBeatmap(beatmap)).ToList();
Assert.That(issues, Has.Count.EqualTo(1)); Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckBackground.IssueTemplateDoesNotExist); Assert.That(issues.Single().Template is CheckFilePresence.IssueTemplateDoesNotExist);
} }
[Test] [Test]
@ -58,10 +64,10 @@ namespace osu.Game.Tests.Editing.Checks
{ {
beatmap.Metadata.BackgroundFile = null; beatmap.Metadata.BackgroundFile = null;
var issues = check.Run(beatmap).ToList(); var issues = check.Run(beatmap, new TestWorkingBeatmap(beatmap)).ToList();
Assert.That(issues, Has.Count.EqualTo(1)); Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckBackground.IssueTemplateNoneSet); Assert.That(issues.Single().Template is CheckFilePresence.IssueTemplateNoneSet);
} }
} }
} }

View File

@ -1,32 +0,0 @@
// 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.
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual;
namespace osu.Game.Tests.Gameplay
{
[HeadlessTest]
public class TestSceneGameplayClockContainer : OsuTestScene
{
[Test]
public void TestStartThenElapsedTime()
{
GameplayClockContainer gcc = null;
AddStep("create container", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
working.LoadTrack();
Add(gcc = new GameplayClockContainer(working, 0));
});
AddStep("start track", () => gcc.Start());
AddUntilStep("elapsed greater than zero", () => gcc.GameplayClock.ElapsedFrameTime > 0);
}
}
}

View File

@ -0,0 +1,58 @@
// 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.
using NUnit.Framework;
using osu.Framework.Testing;
using osu.Game.Rulesets.Osu;
using osu.Game.Screens.Play;
using osu.Game.Tests.Visual;
namespace osu.Game.Tests.Gameplay
{
[HeadlessTest]
public class TestSceneMasterGameplayClockContainer : OsuTestScene
{
[Test]
public void TestStartThenElapsedTime()
{
GameplayClockContainer gcc = null;
AddStep("create container", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
working.LoadTrack();
Add(gcc = new MasterGameplayClockContainer(working, 0));
});
AddStep("start clock", () => gcc.Start());
AddUntilStep("elapsed greater than zero", () => gcc.GameplayClock.ElapsedFrameTime > 0);
}
[Test]
public void TestElapseThenReset()
{
GameplayClockContainer gcc = null;
AddStep("create container", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
working.LoadTrack();
Add(gcc = new MasterGameplayClockContainer(working, 0));
});
AddStep("start clock", () => gcc.Start());
AddUntilStep("current time greater 2000", () => gcc.GameplayClock.CurrentTime > 2000);
double timeAtReset = 0;
AddStep("reset clock", () =>
{
timeAtReset = gcc.GameplayClock.CurrentTime;
gcc.Reset();
});
AddAssert("current time < time at reset", () => gcc.GameplayClock.CurrentTime < timeAtReset);
}
}
}

View File

@ -20,6 +20,7 @@ using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods; using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu; using osu.Game.Rulesets.Osu;
using osu.Game.Rulesets.Osu.Mods; using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Rulesets.UI;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Skinning; using osu.Game.Skinning;
using osu.Game.Storyboards; using osu.Game.Storyboards;
@ -67,17 +68,47 @@ namespace osu.Game.Tests.Gameplay
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo); var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
working.LoadTrack(); working.LoadTrack();
Add(gameplayContainer = new GameplayClockContainer(working, 0)); Add(gameplayContainer = new MasterGameplayClockContainer(working, 0)
gameplayContainer.Add(sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
{ {
Clock = gameplayContainer.GameplayClock IsPaused = { Value = true },
Child = new FrameStabilityContainer
{
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
}
});
});
AddStep("reset clock", () => gameplayContainer.Start());
AddUntilStep("sample played", () => sample.RequestedPlaying);
AddUntilStep("sample has lifetime end", () => sample.LifetimeEnd < double.MaxValue);
}
[Test]
public void TestSampleHasLifetimeEndWithInitialClockTime()
{
GameplayClockContainer gameplayContainer = null;
DrawableStoryboardSample sample = null;
AddStep("create container", () =>
{
var working = CreateWorkingBeatmap(new OsuRuleset().RulesetInfo);
working.LoadTrack();
Add(gameplayContainer = new MasterGameplayClockContainer(working, 1000, true)
{
IsPaused = { Value = true },
Child = new FrameStabilityContainer
{
Child = sample = new DrawableStoryboardSample(new StoryboardSampleInfo(string.Empty, 0, 1))
}
}); });
}); });
AddStep("start time", () => gameplayContainer.Start()); AddStep("start time", () => gameplayContainer.Start());
AddUntilStep("sample playback succeeded", () => sample.LifetimeEnd < double.MaxValue); AddUntilStep("sample not played", () => !sample.RequestedPlaying);
AddUntilStep("sample has lifetime end", () => sample.LifetimeEnd < double.MaxValue);
} }
[TestCase(typeof(OsuModDoubleTime), 1.5)] [TestCase(typeof(OsuModDoubleTime), 1.5)]
@ -114,7 +145,7 @@ namespace osu.Game.Tests.Gameplay
var beatmapSkinSourceContainer = new BeatmapSkinProvidingContainer(Beatmap.Value.Skin); var beatmapSkinSourceContainer = new BeatmapSkinProvidingContainer(Beatmap.Value.Skin);
Add(gameplayContainer = new GameplayClockContainer(Beatmap.Value, 0) Add(gameplayContainer = new MasterGameplayClockContainer(Beatmap.Value, 0)
{ {
Child = beatmapSkinSourceContainer Child = beatmapSkinSourceContainer
}); });

View File

@ -130,9 +130,9 @@ namespace osu.Game.Tests.Visual.Gameplay
public double GameplayClockTime => GameplayClockContainer.GameplayClock.CurrentTime; public double GameplayClockTime => GameplayClockContainer.GameplayClock.CurrentTime;
protected override void UpdateAfterChildren() protected override void Update()
{ {
base.UpdateAfterChildren(); base.Update();
if (!FirstFrameClockTime.HasValue) if (!FirstFrameClockTime.HasValue)
{ {

View File

@ -33,7 +33,7 @@ namespace osu.Game.Tests.Visual.Gameplay
var working = CreateWorkingBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo)); var working = CreateWorkingBeatmap(CreateBeatmap(new OsuRuleset().RulesetInfo));
working.LoadTrack(); working.LoadTrack();
Child = gameplayClockContainer = new GameplayClockContainer(working, 0) Child = gameplayClockContainer = new MasterGameplayClockContainer(working, 0)
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] Children = new Drawable[]
@ -80,7 +80,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddStep("move mouse", () => InputManager.MoveMouseTo(skip.ScreenSpaceDrawQuad.Centre)); AddStep("move mouse", () => InputManager.MoveMouseTo(skip.ScreenSpaceDrawQuad.Centre));
AddStep("click", () => AddStep("click", () =>
{ {
increment = skip_time - gameplayClock.CurrentTime - GameplayClockContainer.MINIMUM_SKIP_TIME / 2; increment = skip_time - gameplayClock.CurrentTime - MasterGameplayClockContainer.MINIMUM_SKIP_TIME / 2;
InputManager.Click(MouseButton.Left); InputManager.Click(MouseButton.Left);
}); });
AddStep("click", () => InputManager.Click(MouseButton.Left)); AddStep("click", () => InputManager.Click(MouseButton.Left));

View File

@ -167,7 +167,7 @@ namespace osu.Game.Tests.Visual.UserInterface
GetModButton(mod).SelectNext(1); GetModButton(mod).SelectNext(1);
public void SetModSettingsWidth(float newWidth) => public void SetModSettingsWidth(float newWidth) =>
ModSettingsContainer.Width = newWidth; ModSettingsContainer.Parent.Width = newWidth;
} }
public class TestRulesetInfo : RulesetInfo public class TestRulesetInfo : RulesetInfo

View File

@ -52,6 +52,8 @@ namespace osu.Game.Tests
protected override Waveform GetWaveform() => new Waveform(trackStore.GetStream(firstAudioFile)); protected override Waveform GetWaveform() => new Waveform(trackStore.GetStream(firstAudioFile));
public override Stream GetStream(string storagePath) => null;
protected override Track GetBeatmapTrack() => trackStore.Get(firstAudioFile); protected override Track GetBeatmapTrack() => trackStore.Get(firstAudioFile);
private string firstAudioFile private string firstAudioFile

View File

@ -526,6 +526,7 @@ namespace osu.Game.Beatmaps
protected override IBeatmap GetBeatmap() => beatmap; protected override IBeatmap GetBeatmap() => beatmap;
protected override Texture GetBackground() => null; protected override Texture GetBackground() => null;
protected override Track GetBeatmapTrack() => null; protected override Track GetBeatmapTrack() => null;
public override Stream GetStream(string storagePath) => null;
} }
} }

View File

@ -3,7 +3,7 @@
using System; using System;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.IO;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Framework.Logging; using osu.Framework.Logging;
@ -36,7 +36,7 @@ namespace osu.Game.Beatmaps
try try
{ {
using (var stream = new LineBufferedReader(resources.Files.GetStream(getPathForFile(BeatmapInfo.Path)))) using (var stream = new LineBufferedReader(GetStream(BeatmapSetInfo.GetPathForFile(BeatmapInfo.Path))))
return Decoder.GetDecoder<Beatmap>(stream).Decode(stream); return Decoder.GetDecoder<Beatmap>(stream).Decode(stream);
} }
catch (Exception e) catch (Exception e)
@ -46,8 +46,6 @@ namespace osu.Game.Beatmaps
} }
} }
private string getPathForFile(string filename) => BeatmapSetInfo.Files.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
protected override bool BackgroundStillValid(Texture b) => false; // bypass lazy logic. we want to return a new background each time for refcounting purposes. protected override bool BackgroundStillValid(Texture b) => false; // bypass lazy logic. we want to return a new background each time for refcounting purposes.
protected override Texture GetBackground() protected override Texture GetBackground()
@ -57,7 +55,7 @@ namespace osu.Game.Beatmaps
try try
{ {
return resources.LargeTextureStore.Get(getPathForFile(Metadata.BackgroundFile)); return resources.LargeTextureStore.Get(BeatmapSetInfo.GetPathForFile(Metadata.BackgroundFile));
} }
catch (Exception e) catch (Exception e)
{ {
@ -73,7 +71,7 @@ namespace osu.Game.Beatmaps
try try
{ {
return resources.Tracks.Get(getPathForFile(Metadata.AudioFile)); return resources.Tracks.Get(BeatmapSetInfo.GetPathForFile(Metadata.AudioFile));
} }
catch (Exception e) catch (Exception e)
{ {
@ -89,7 +87,7 @@ namespace osu.Game.Beatmaps
try try
{ {
var trackData = resources.Files.GetStream(getPathForFile(Metadata.AudioFile)); var trackData = GetStream(BeatmapSetInfo.GetPathForFile(Metadata.AudioFile));
return trackData == null ? null : new Waveform(trackData); return trackData == null ? null : new Waveform(trackData);
} }
catch (Exception e) catch (Exception e)
@ -105,7 +103,7 @@ namespace osu.Game.Beatmaps
try try
{ {
using (var stream = new LineBufferedReader(resources.Files.GetStream(getPathForFile(BeatmapInfo.Path)))) using (var stream = new LineBufferedReader(GetStream(BeatmapSetInfo.GetPathForFile(BeatmapInfo.Path))))
{ {
var decoder = Decoder.GetDecoder<Storyboard>(stream); var decoder = Decoder.GetDecoder<Storyboard>(stream);
@ -114,7 +112,7 @@ namespace osu.Game.Beatmaps
storyboard = decoder.Decode(stream); storyboard = decoder.Decode(stream);
else else
{ {
using (var secondaryStream = new LineBufferedReader(resources.Files.GetStream(getPathForFile(BeatmapSetInfo.StoryboardFile)))) using (var secondaryStream = new LineBufferedReader(GetStream(BeatmapSetInfo.GetPathForFile(BeatmapSetInfo.StoryboardFile))))
storyboard = decoder.Decode(stream, secondaryStream); storyboard = decoder.Decode(stream, secondaryStream);
} }
} }
@ -142,6 +140,8 @@ namespace osu.Game.Beatmaps
return null; return null;
} }
} }
public override Stream GetStream(string storagePath) => resources.Files.GetStream(storagePath);
} }
} }
} }

View File

@ -59,6 +59,13 @@ namespace osu.Game.Beatmaps
public string StoryboardFile => Files?.Find(f => f.Filename.EndsWith(".osb", StringComparison.OrdinalIgnoreCase))?.Filename; public string StoryboardFile => Files?.Find(f => f.Filename.EndsWith(".osb", StringComparison.OrdinalIgnoreCase))?.Filename;
/// <summary>
/// Returns the storage path for the file in this beatmapset with the given filename, if any exists, otherwise null.
/// The path returned is relative to the user file storage.
/// </summary>
/// <param name="filename">The name of the file to get the storage path of.</param>
public string GetPathForFile(string filename) => Files?.SingleOrDefault(f => string.Equals(f.Filename, filename, StringComparison.OrdinalIgnoreCase))?.FileInfo.StoragePath;
public List<BeatmapSetFileInfo> Files { get; set; } public List<BeatmapSetFileInfo> Files { get; set; }
public override string ToString() => Metadata?.ToString() ?? base.ToString(); public override string ToString() => Metadata?.ToString() ?? base.ToString();

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using System.Threading; using System.Threading;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Audio; using osu.Framework.Audio;
@ -48,6 +49,8 @@ namespace osu.Game.Beatmaps
protected override Track GetBeatmapTrack() => GetVirtualTrack(); protected override Track GetBeatmapTrack() => GetVirtualTrack();
public override Stream GetStream(string storagePath) => null;
private class DummyRulesetInfo : RulesetInfo private class DummyRulesetInfo : RulesetInfo
{ {
public override Ruleset CreateInstance() => new DummyRuleset(); public override Ruleset CreateInstance() => new DummyRuleset();

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
using osu.Game.Rulesets; using osu.Game.Rulesets;
@ -41,6 +42,11 @@ namespace osu.Game.Beatmaps
/// </summary> /// </summary>
ISkin Skin { get; } ISkin Skin { get; }
/// <summary>
/// Retrieves the <see cref="Track"/> which this <see cref="WorkingBeatmap"/> has loaded.
/// </summary>
Track Track { get; }
/// <summary> /// <summary>
/// Constructs a playable <see cref="IBeatmap"/> from <see cref="Beatmap"/> using the applicable converters for a specific <see cref="RulesetInfo"/>. /// Constructs a playable <see cref="IBeatmap"/> from <see cref="Beatmap"/> using the applicable converters for a specific <see cref="RulesetInfo"/>.
/// <para> /// <para>
@ -67,5 +73,11 @@ namespace osu.Game.Beatmaps
/// </remarks> /// </remarks>
/// <returns>A fresh track instance, which will also be available via <see cref="Track"/>.</returns> /// <returns>A fresh track instance, which will also be available via <see cref="Track"/>.</returns>
Track LoadTrack(); Track LoadTrack();
/// <summary>
/// Returns the stream of the file from the given storage path.
/// </summary>
/// <param name="storagePath">The storage path to the file.</param>
Stream GetStream(string storagePath);
} }
} }

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.IO;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -326,6 +327,8 @@ namespace osu.Game.Beatmaps
protected virtual ISkin GetSkin() => new DefaultSkin(); protected virtual ISkin GetSkin() => new DefaultSkin();
private readonly RecyclableLazy<ISkin> skin; private readonly RecyclableLazy<ISkin> skin;
public abstract Stream GetStream(string storagePath);
public class RecyclableLazy<T> public class RecyclableLazy<T>
{ {
private Lazy<T> lazy; private Lazy<T> lazy;

View File

@ -245,18 +245,24 @@ namespace osu.Game.Overlays.Mods
}, },
} }
}, },
ModSettingsContainer = new ModSettingsContainer new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Anchor = Anchor.BottomRight, Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight, Origin = Anchor.BottomRight,
Width = 0.3f,
Alpha = 0,
Padding = new MarginPadding(30), Padding = new MarginPadding(30),
Width = 0.3f,
Children = new Drawable[]
{
ModSettingsContainer = new ModSettingsContainer
{
Alpha = 0,
SelectedMods = { BindTarget = SelectedMods }, SelectedMods = { BindTarget = SelectedMods },
}, },
} }
}, },
}
},
}, },
new Drawable[] new Drawable[]
{ {

View File

@ -129,9 +129,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input
rotation.BindTo(handler.Rotation); rotation.BindTo(handler.Rotation);
rotation.BindValueChanged(val => rotation.BindValueChanged(val =>
{ {
tabletContainer.RotateTo(-val.NewValue, 800, Easing.OutQuint);
usableAreaContainer.RotateTo(val.NewValue, 100, Easing.OutQuint) usableAreaContainer.RotateTo(val.NewValue, 100, Easing.OutQuint)
.OnComplete(_ => checkBounds()); // required as we are using SSDQ. .OnComplete(_ => checkBounds()); // required as we are using SSDQ.
}); }, true);
tablet.BindTo(handler.Tablet); tablet.BindTo(handler.Tablet);
tablet.BindValueChanged(_ => Scheduler.AddOnce(updateTabletDetails)); tablet.BindValueChanged(_ => Scheduler.AddOnce(updateTabletDetails));
@ -183,8 +184,10 @@ namespace osu.Game.Overlays.Settings.Sections.Input
if (!(tablet.Value?.Size is Vector2 size)) if (!(tablet.Value?.Size is Vector2 size))
return; return;
float fitX = size.X / (DrawWidth - Padding.Left - Padding.Right); float maxDimension = size.LengthFast;
float fitY = size.Y / DrawHeight;
float fitX = maxDimension / (DrawWidth - Padding.Left - Padding.Right);
float fitY = maxDimension / DrawHeight;
float adjust = MathF.Max(fitX, fitY); float adjust = MathF.Max(fitX, fitY);

View File

@ -16,9 +16,18 @@ namespace osu.Game.Rulesets.Edit
{ {
private readonly List<ICheck> checks = new List<ICheck> private readonly List<ICheck> checks = new List<ICheck>
{ {
new CheckBackground(), // Resources
new CheckBackgroundPresence(),
new CheckBackgroundQuality(),
// Audio
new CheckAudioPresence(),
new CheckAudioQuality()
}; };
public IEnumerable<Issue> Run(IBeatmap beatmap) => checks.SelectMany(check => check.Run(beatmap)); public IEnumerable<Issue> Run(IBeatmap playableBeatmap, WorkingBeatmap workingBeatmap)
{
return checks.SelectMany(check => check.Run(playableBeatmap, workingBeatmap));
}
} }
} }

View File

@ -0,0 +1,15 @@
// 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.
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
{
public class CheckAudioPresence : CheckFilePresence
{
protected override CheckCategory Category => CheckCategory.Audio;
protected override string TypeOfFile => "audio";
protected override string GetFilename(IBeatmap playableBeatmap) => playableBeatmap.Metadata?.AudioFile;
}
}

View File

@ -0,0 +1,75 @@
// 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.
using System.Collections.Generic;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
{
public class CheckAudioQuality : ICheck
{
// This is a requirement as stated in the Ranking Criteria.
// See https://osu.ppy.sh/wiki/en/Ranking_Criteria#rules.4
private const int max_bitrate = 192;
// "A song's audio file /.../ must be of reasonable quality. Try to find the highest quality source file available"
// There not existing a version with a bitrate of 128 kbps or higher is extremely rare.
private const int min_bitrate = 128;
public CheckMetadata Metadata { get; } = new CheckMetadata(CheckCategory.Audio, "Too high or low audio bitrate");
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
new IssueTemplateTooHighBitrate(this),
new IssueTemplateTooLowBitrate(this),
new IssueTemplateNoBitrate(this)
};
public IEnumerable<Issue> Run(IBeatmap playableBeatmap, IWorkingBeatmap workingBeatmap)
{
var audioFile = playableBeatmap.Metadata?.AudioFile;
if (audioFile == null)
yield break;
var track = workingBeatmap.Track;
if (track?.Bitrate == null || track.Bitrate.Value == 0)
yield return new IssueTemplateNoBitrate(this).Create();
else if (track.Bitrate.Value > max_bitrate)
yield return new IssueTemplateTooHighBitrate(this).Create(track.Bitrate.Value);
else if (track.Bitrate.Value < min_bitrate)
yield return new IssueTemplateTooLowBitrate(this).Create(track.Bitrate.Value);
}
public class IssueTemplateTooHighBitrate : IssueTemplate
{
public IssueTemplateTooHighBitrate(ICheck check)
: base(check, IssueType.Problem, "The audio bitrate ({0} kbps) exceeds {1} kbps.")
{
}
public Issue Create(int bitrate) => new Issue(this, bitrate, max_bitrate);
}
public class IssueTemplateTooLowBitrate : IssueTemplate
{
public IssueTemplateTooLowBitrate(ICheck check)
: base(check, IssueType.Problem, "The audio bitrate ({0} kbps) is lower than {1} kbps.")
{
}
public Issue Create(int bitrate) => new Issue(this, bitrate, min_bitrate);
}
public class IssueTemplateNoBitrate : IssueTemplate
{
public IssueTemplateNoBitrate(ICheck check)
: base(check, IssueType.Error, "The audio bitrate could not be retrieved.")
{
}
public Issue Create() => new Issue(this);
}
}
}

View File

@ -1,61 +0,0 @@
// 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.
using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
{
public class CheckBackground : ICheck
{
public CheckMetadata Metadata { get; } = new CheckMetadata(CheckCategory.Resources, "Missing background");
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
new IssueTemplateNoneSet(this),
new IssueTemplateDoesNotExist(this)
};
public IEnumerable<Issue> Run(IBeatmap beatmap)
{
if (beatmap.Metadata.BackgroundFile == null)
{
yield return new IssueTemplateNoneSet(this).Create();
yield break;
}
// If the background is set, also make sure it still exists.
var set = beatmap.BeatmapInfo.BeatmapSet;
var file = set.Files.FirstOrDefault(f => f.Filename == beatmap.Metadata.BackgroundFile);
if (file != null)
yield break;
yield return new IssueTemplateDoesNotExist(this).Create(beatmap.Metadata.BackgroundFile);
}
public class IssueTemplateNoneSet : IssueTemplate
{
public IssueTemplateNoneSet(ICheck check)
: base(check, IssueType.Problem, "No background has been set.")
{
}
public Issue Create() => new Issue(this);
}
public class IssueTemplateDoesNotExist : IssueTemplate
{
public IssueTemplateDoesNotExist(ICheck check)
: base(check, IssueType.Problem, "The background file \"{0}\" does not exist.")
{
}
public Issue Create(string filename) => new Issue(this, filename);
}
}
}

View File

@ -0,0 +1,15 @@
// 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.
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
{
public class CheckBackgroundPresence : CheckFilePresence
{
protected override CheckCategory Category => CheckCategory.Resources;
protected override string TypeOfFile => "background";
protected override string GetFilename(IBeatmap playableBeatmap) => playableBeatmap.Metadata?.BackgroundFile;
}
}

View File

@ -0,0 +1,98 @@
// 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.
using System.Collections.Generic;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
{
public class CheckBackgroundQuality : ICheck
{
// These are the requirements as stated in the Ranking Criteria.
// See https://osu.ppy.sh/wiki/en/Ranking_Criteria#rules.5
private const int min_width = 160;
private const int max_width = 2560;
private const int min_height = 120;
private const int max_height = 1440;
private const double max_filesize_mb = 2.5d;
// It's usually possible to find a higher resolution of the same image if lower than these.
private const int low_width = 960;
private const int low_height = 540;
public CheckMetadata Metadata { get; } = new CheckMetadata(CheckCategory.Resources, "Too high or low background resolution");
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
new IssueTemplateTooHighResolution(this),
new IssueTemplateTooLowResolution(this),
new IssueTemplateTooUncompressed(this)
};
public IEnumerable<Issue> Run(IBeatmap playableBeatmap, IWorkingBeatmap workingBeatmap)
{
var backgroundFile = playableBeatmap.Metadata?.BackgroundFile;
if (backgroundFile == null)
yield break;
var texture = workingBeatmap.Background;
if (texture == null)
yield break;
if (texture.Width > max_width || texture.Height > max_height)
yield return new IssueTemplateTooHighResolution(this).Create(texture.Width, texture.Height);
if (texture.Width < min_width || texture.Height < min_height)
yield return new IssueTemplateTooLowResolution(this).Create(texture.Width, texture.Height);
else if (texture.Width < low_width || texture.Height < low_height)
yield return new IssueTemplateLowResolution(this).Create(texture.Width, texture.Height);
string storagePath = playableBeatmap.BeatmapInfo.BeatmapSet.GetPathForFile(backgroundFile);
double filesizeMb = workingBeatmap.GetStream(storagePath).Length / (1024d * 1024d);
if (filesizeMb > max_filesize_mb)
yield return new IssueTemplateTooUncompressed(this).Create(filesizeMb);
}
public class IssueTemplateTooHighResolution : IssueTemplate
{
public IssueTemplateTooHighResolution(ICheck check)
: base(check, IssueType.Problem, "The background resolution ({0} x {1}) exceeds {2} x {3}.")
{
}
public Issue Create(double width, double height) => new Issue(this, width, height, max_width, max_height);
}
public class IssueTemplateTooLowResolution : IssueTemplate
{
public IssueTemplateTooLowResolution(ICheck check)
: base(check, IssueType.Problem, "The background resolution ({0} x {1}) is lower than {2} x {3}.")
{
}
public Issue Create(double width, double height) => new Issue(this, width, height, min_width, min_height);
}
public class IssueTemplateLowResolution : IssueTemplate
{
public IssueTemplateLowResolution(ICheck check)
: base(check, IssueType.Warning, "The background resolution ({0} x {1}) is lower than {2} x {3}.")
{
}
public Issue Create(double width, double height) => new Issue(this, width, height, low_width, low_height);
}
public class IssueTemplateTooUncompressed : IssueTemplate
{
public IssueTemplateTooUncompressed(ICheck check)
: base(check, IssueType.Problem, "The background filesize ({0:0.##} MB) exceeds {1} MB.")
{
}
public Issue Create(double actualMb) => new Issue(this, actualMb, max_filesize_mb);
}
}
}

View File

@ -0,0 +1,63 @@
// 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.
using System.Collections.Generic;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
{
public abstract class CheckFilePresence : ICheck
{
protected abstract CheckCategory Category { get; }
protected abstract string TypeOfFile { get; }
protected abstract string GetFilename(IBeatmap playableBeatmap);
public CheckMetadata Metadata => new CheckMetadata(Category, $"Missing {TypeOfFile}");
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
new IssueTemplateNoneSet(this),
new IssueTemplateDoesNotExist(this)
};
public IEnumerable<Issue> Run(IBeatmap playableBeatmap, IWorkingBeatmap workingBeatmap)
{
var filename = GetFilename(playableBeatmap);
if (filename == null)
{
yield return new IssueTemplateNoneSet(this).Create(TypeOfFile);
yield break;
}
// If the file is set, also make sure it still exists.
var storagePath = playableBeatmap.BeatmapInfo.BeatmapSet.GetPathForFile(filename);
if (storagePath != null)
yield break;
yield return new IssueTemplateDoesNotExist(this).Create(TypeOfFile, filename);
}
public class IssueTemplateNoneSet : IssueTemplate
{
public IssueTemplateNoneSet(ICheck check)
: base(check, IssueType.Problem, "No {0} has been set.")
{
}
public Issue Create(string typeOfFile) => new Issue(this, typeOfFile);
}
public class IssueTemplateDoesNotExist : IssueTemplate
{
public IssueTemplateDoesNotExist(ICheck check)
: base(check, IssueType.Problem, "The {0} file \"{1}\" does not exist.")
{
}
public Issue Create(string typeOfFile, string filename) => new Issue(this, typeOfFile, filename);
}
}
}

View File

@ -24,7 +24,8 @@ namespace osu.Game.Rulesets.Edit.Checks.Components
/// <summary> /// <summary>
/// Runs this check and returns any issues detected for the provided beatmap. /// Runs this check and returns any issues detected for the provided beatmap.
/// </summary> /// </summary>
/// <param name="beatmap">The beatmap to run the check on.</param> /// <param name="playableBeatmap">The playable beatmap of the beatmap to run the check on.</param>
public IEnumerable<Issue> Run(IBeatmap beatmap); /// <param name="workingBeatmap">The working beatmap of the beatmap to run the check on.</param>
public IEnumerable<Issue> Run(IBeatmap playableBeatmap, IWorkingBeatmap workingBeatmap);
} }
} }

View File

@ -12,6 +12,6 @@ namespace osu.Game.Rulesets.Edit
/// </summary> /// </summary>
public interface IBeatmapVerifier public interface IBeatmapVerifier
{ {
public IEnumerable<Issue> Run(IBeatmap beatmap); public IEnumerable<Issue> Run(IBeatmap playableBeatmap, WorkingBeatmap workingBeatmap);
} }
} }

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.Specialized; using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq; using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -39,7 +40,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// <summary> /// <summary>
/// The <see cref="HitObject"/> currently represented by this <see cref="DrawableHitObject"/>. /// The <see cref="HitObject"/> currently represented by this <see cref="DrawableHitObject"/>.
/// </summary> /// </summary>
public HitObject HitObject { get; private set; } public HitObject HitObject => lifetimeEntry?.HitObject;
/// <summary> /// <summary>
/// The parenting <see cref="DrawableHitObject"/>, if any. /// The parenting <see cref="DrawableHitObject"/>, if any.
@ -108,7 +109,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// <summary> /// <summary>
/// The scoring result of this <see cref="DrawableHitObject"/>. /// The scoring result of this <see cref="DrawableHitObject"/>.
/// </summary> /// </summary>
public JudgementResult Result { get; private set; } public JudgementResult Result => lifetimeEntry?.Result;
/// <summary> /// <summary>
/// The relative X position of this hit object for sample playback balance adjustment. /// The relative X position of this hit object for sample playback balance adjustment.
@ -141,13 +142,14 @@ namespace osu.Game.Rulesets.Objects.Drawables
public IBindable<ArmedState> State => state; public IBindable<ArmedState> State => state;
/// <summary> /// <summary>
/// Whether <see cref="HitObject"/> is currently applied. /// Whether a <see cref="HitObjectLifetimeEntry"/> is currently applied.
/// </summary> /// </summary>
private bool hasHitObjectApplied; private bool hasEntryApplied;
/// <summary> /// <summary>
/// The <see cref="HitObjectLifetimeEntry"/> controlling the lifetime of the currently-attached <see cref="HitObject"/>. /// The <see cref="HitObjectLifetimeEntry"/> controlling the lifetime of the currently-attached <see cref="HitObject"/>.
/// </summary> /// </summary>
/// <remarks>Even if it is not null, it may not be fully applied until loaded (<see cref="hasEntryApplied"/> is false).</remarks>
[CanBeNull] [CanBeNull]
private HitObjectLifetimeEntry lifetimeEntry; private HitObjectLifetimeEntry lifetimeEntry;
@ -164,11 +166,15 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </summary> /// </summary>
/// <param name="initialHitObject"> /// <param name="initialHitObject">
/// The <see cref="HitObject"/> to be initially applied to this <see cref="DrawableHitObject"/>. /// The <see cref="HitObject"/> to be initially applied to this <see cref="DrawableHitObject"/>.
/// If <c>null</c>, a hitobject is expected to be later applied via <see cref="Apply"/> (or automatically via pooling). /// If <c>null</c>, a hitobject is expected to be later applied via <see cref="Apply(osu.Game.Rulesets.Objects.HitObjectLifetimeEntry)"/> (or automatically via pooling).
/// </param> /// </param>
protected DrawableHitObject([CanBeNull] HitObject initialHitObject = null) protected DrawableHitObject([CanBeNull] HitObject initialHitObject = null)
{ {
HitObject = initialHitObject; if (initialHitObject != null)
{
lifetimeEntry = new SyntheticHitObjectEntry(initialHitObject);
ensureEntryHasResult();
}
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
@ -184,8 +190,8 @@ namespace osu.Game.Rulesets.Objects.Drawables
{ {
base.LoadAsyncComplete(); base.LoadAsyncComplete();
if (HitObject != null) if (lifetimeEntry != null && !hasEntryApplied)
Apply(HitObject, lifetimeEntry); Apply(lifetimeEntry);
} }
protected override void LoadComplete() protected override void LoadComplete()
@ -198,37 +204,47 @@ namespace osu.Game.Rulesets.Objects.Drawables
} }
/// <summary> /// <summary>
/// Applies a new <see cref="HitObject"/> to be represented by this <see cref="DrawableHitObject"/>. /// Applies a hit object to be represented by this <see cref="DrawableHitObject"/>.
/// </summary> /// </summary>
/// <param name="hitObject">The <see cref="HitObject"/> to apply.</param> [Obsolete("Use either overload of Apply that takes a single argument of type HitObject or HitObjectLifetimeEntry")]
/// <param name="lifetimeEntry">The <see cref="HitObjectLifetimeEntry"/> controlling the lifetime of <paramref name="hitObject"/>.</param>
public void Apply([NotNull] HitObject hitObject, [CanBeNull] HitObjectLifetimeEntry lifetimeEntry) public void Apply([NotNull] HitObject hitObject, [CanBeNull] HitObjectLifetimeEntry lifetimeEntry)
{
if (lifetimeEntry != null)
Apply(lifetimeEntry);
else
Apply(hitObject);
}
/// <summary>
/// Applies a new <see cref="HitObject"/> to be represented by this <see cref="DrawableHitObject"/>.
/// A new <see cref="HitObjectLifetimeEntry"/> is automatically created and applied to this <see cref="DrawableHitObject"/>.
/// </summary>
public void Apply([NotNull] HitObject hitObject)
{
if (hitObject == null)
throw new ArgumentNullException($"Cannot apply a null {nameof(HitObject)}.");
Apply(new SyntheticHitObjectEntry(hitObject));
}
/// <summary>
/// Applies a new <see cref="HitObjectLifetimeEntry"/> to be represented by this <see cref="DrawableHitObject"/>.
/// </summary>
public void Apply([NotNull] HitObjectLifetimeEntry newEntry)
{ {
free(); free();
HitObject = hitObject ?? throw new InvalidOperationException($"Cannot apply a null {nameof(HitObject)}."); lifetimeEntry = newEntry;
this.lifetimeEntry = lifetimeEntry; // LifetimeStart is already computed using HitObjectLifetimeEntry's InitialLifetimeOffset.
// We override this with DHO's InitialLifetimeOffset for a non-pooled DHO.
if (newEntry is SyntheticHitObjectEntry)
lifetimeEntry.LifetimeStart = HitObject.StartTime - InitialLifetimeOffset;
if (lifetimeEntry != null)
{
// Transfer lifetime from the entry.
LifetimeStart = lifetimeEntry.LifetimeStart; LifetimeStart = lifetimeEntry.LifetimeStart;
LifetimeEnd = lifetimeEntry.LifetimeEnd; LifetimeEnd = lifetimeEntry.LifetimeEnd;
// Copy any existing result from the entry (required for rewind / judgement revert). ensureEntryHasResult();
Result = lifetimeEntry.Result;
}
else
LifetimeStart = HitObject.StartTime - InitialLifetimeOffset;
// Ensure this DHO has a result.
Result ??= CreateResult(HitObject.CreateJudgement())
?? throw new InvalidOperationException($"{GetType().ReadableName()} must provide a {nameof(JudgementResult)} through {nameof(CreateResult)}.");
// Copy back the result to the entry for potential future retrieval.
if (lifetimeEntry != null)
lifetimeEntry.Result = Result;
foreach (var h in HitObject.NestedHitObjects) foreach (var h in HitObject.NestedHitObjects)
{ {
@ -278,16 +294,15 @@ namespace osu.Game.Rulesets.Objects.Drawables
updateState(ArmedState.Idle, true); updateState(ArmedState.Idle, true);
} }
hasHitObjectApplied = true; hasEntryApplied = true;
} }
/// <summary> /// <summary>
/// Removes the currently applied <see cref="HitObject"/> /// Removes the currently applied <see cref="lifetimeEntry"/>
/// </summary> /// </summary>
private void free() private void free()
{ {
if (!hasHitObjectApplied) if (!hasEntryApplied) return;
return;
StartTimeBindable.UnbindFrom(HitObject.StartTimeBindable); StartTimeBindable.UnbindFrom(HitObject.StartTimeBindable);
if (HitObject is IHasComboInformation combo) if (HitObject is IHasComboInformation combo)
@ -319,14 +334,12 @@ namespace osu.Game.Rulesets.Objects.Drawables
OnFree(); OnFree();
HitObject = null;
ParentHitObject = null; ParentHitObject = null;
Result = null;
lifetimeEntry = null; lifetimeEntry = null;
clearExistingStateTransforms(); clearExistingStateTransforms();
hasHitObjectApplied = false; hasEntryApplied = false;
} }
protected sealed override void FreeAfterUse() protected sealed override void FreeAfterUse()
@ -385,7 +398,9 @@ namespace osu.Game.Rulesets.Objects.Drawables
private void onDefaultsApplied(HitObject hitObject) private void onDefaultsApplied(HitObject hitObject)
{ {
Apply(hitObject, lifetimeEntry); Debug.Assert(lifetimeEntry != null);
Apply(lifetimeEntry);
DefaultsApplied?.Invoke(this); DefaultsApplied?.Invoke(this);
} }
@ -783,6 +798,13 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// <param name="judgement">The <see cref="Judgement"/> that provides the scoring information.</param> /// <param name="judgement">The <see cref="Judgement"/> that provides the scoring information.</param>
protected virtual JudgementResult CreateResult(Judgement judgement) => new JudgementResult(HitObject, judgement); protected virtual JudgementResult CreateResult(Judgement judgement) => new JudgementResult(HitObject, judgement);
private void ensureEntryHasResult()
{
Debug.Assert(lifetimeEntry != null);
lifetimeEntry.Result ??= CreateResult(HitObject.CreateJudgement())
?? throw new InvalidOperationException($"{GetType().ReadableName()} must provide a {nameof(JudgementResult)} through {nameof(CreateResult)}.");
}
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {
base.Dispose(isDisposing); base.Dispose(isDisposing);

View File

@ -0,0 +1,19 @@
// 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.
using osu.Game.Rulesets.Objects.Drawables;
namespace osu.Game.Rulesets.Objects
{
/// <summary>
/// Created for a <see cref="DrawableHitObject"/> when only <see cref="HitObject"/> is given
/// to make sure a <see cref="DrawableHitObject"/> is always associated with a <see cref="HitObjectLifetimeEntry"/>.
/// </summary>
internal class SyntheticHitObjectEntry : HitObjectLifetimeEntry
{
public SyntheticHitObjectEntry(HitObject hitObject)
: base(hitObject)
{
}
}
}

View File

@ -362,7 +362,7 @@ namespace osu.Game.Rulesets.UI
lifetimeEntryMap[hitObject] = entry = CreateLifetimeEntry(hitObject); lifetimeEntryMap[hitObject] = entry = CreateLifetimeEntry(hitObject);
dho.ParentHitObject = parent; dho.ParentHitObject = parent;
dho.Apply(hitObject, entry); dho.Apply(entry);
}); });
} }

View File

@ -116,6 +116,8 @@ namespace osu.Game.Screens.Edit
protected override Texture GetBackground() => throw new NotImplementedException(); protected override Texture GetBackground() => throw new NotImplementedException();
protected override Track GetBeatmapTrack() => throw new NotImplementedException(); protected override Track GetBeatmapTrack() => throw new NotImplementedException();
public override Stream GetStream(string storagePath) => throw new NotImplementedException();
} }
} }
} }

View File

@ -7,6 +7,7 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays; using osu.Game.Overlays;
@ -60,7 +61,10 @@ namespace osu.Game.Screens.Edit.Verify
private EditorClock clock { get; set; } private EditorClock clock { get; set; }
[Resolved] [Resolved]
protected EditorBeatmap Beatmap { get; private set; } private IBindable<WorkingBeatmap> workingBeatmap { get; set; }
[Resolved]
private EditorBeatmap beatmap { get; set; }
[Resolved] [Resolved]
private Bindable<Issue> selectedIssue { get; set; } private Bindable<Issue> selectedIssue { get; set; }
@ -72,7 +76,7 @@ namespace osu.Game.Screens.Edit.Verify
private void load(OverlayColourProvider colours) private void load(OverlayColourProvider colours)
{ {
generalVerifier = new BeatmapVerifier(); generalVerifier = new BeatmapVerifier();
rulesetVerifier = Beatmap.BeatmapInfo.Ruleset?.CreateInstance()?.CreateBeatmapVerifier(); rulesetVerifier = beatmap.BeatmapInfo.Ruleset?.CreateInstance()?.CreateBeatmapVerifier();
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
@ -118,10 +122,10 @@ namespace osu.Game.Screens.Edit.Verify
private void refresh() private void refresh()
{ {
var issues = generalVerifier.Run(Beatmap); var issues = generalVerifier.Run(beatmap, workingBeatmap.Value);
if (rulesetVerifier != null) if (rulesetVerifier != null)
issues = issues.Concat(rulesetVerifier.Run(Beatmap)); issues = issues.Concat(rulesetVerifier.Run(beatmap, workingBeatmap.Value));
table.Issues = issues table.Issues = issues
.OrderBy(issue => issue.Template.Type) .OrderBy(issue => issue.Template.Type)

View File

@ -19,7 +19,7 @@ namespace osu.Game.Screens.Play
/// </summary> /// </summary>
public class GameplayClock : IFrameBasedClock public class GameplayClock : IFrameBasedClock
{ {
private readonly IFrameBasedClock underlyingClock; internal readonly IFrameBasedClock UnderlyingClock;
public readonly BindableBool IsPaused = new BindableBool(); public readonly BindableBool IsPaused = new BindableBool();
@ -30,12 +30,12 @@ namespace osu.Game.Screens.Play
public GameplayClock(IFrameBasedClock underlyingClock) public GameplayClock(IFrameBasedClock underlyingClock)
{ {
this.underlyingClock = underlyingClock; UnderlyingClock = underlyingClock;
} }
public double CurrentTime => underlyingClock.CurrentTime; public double CurrentTime => UnderlyingClock.CurrentTime;
public double Rate => underlyingClock.Rate; public double Rate => UnderlyingClock.Rate;
/// <summary> /// <summary>
/// The rate of gameplay when playback is at 100%. /// The rate of gameplay when playback is at 100%.
@ -59,19 +59,19 @@ namespace osu.Game.Screens.Play
} }
} }
public bool IsRunning => underlyingClock.IsRunning; public bool IsRunning => UnderlyingClock.IsRunning;
public void ProcessFrame() public void ProcessFrame()
{ {
// intentionally not updating the underlying clock (handled externally). // intentionally not updating the underlying clock (handled externally).
} }
public double ElapsedFrameTime => underlyingClock.ElapsedFrameTime; public double ElapsedFrameTime => UnderlyingClock.ElapsedFrameTime;
public double FramesPerSecond => underlyingClock.FramesPerSecond; public double FramesPerSecond => UnderlyingClock.FramesPerSecond;
public FrameTimeInfo TimeInfo => underlyingClock.TimeInfo; public FrameTimeInfo TimeInfo => UnderlyingClock.TimeInfo;
public IClock Source => underlyingClock; public IClock Source => UnderlyingClock;
} }
} }

View File

@ -1,300 +1,148 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Threading.Tasks;
using osu.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Timing; using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
/// <summary> /// <summary>
/// Encapsulates gameplay timing logic and provides a <see cref="Play.GameplayClock"/> for children. /// Encapsulates gameplay timing logic and provides a <see cref="GameplayClock"/> via DI for gameplay components to use.
/// </summary> /// </summary>
public class GameplayClockContainer : Container public abstract class GameplayClockContainer : Container
{ {
private readonly WorkingBeatmap beatmap; /// <summary>
/// The final clock which is exposed to gameplay components.
[NotNull] /// </summary>
private ITrack track; public GameplayClock GameplayClock { get; private set; }
/// <summary>
/// Whether gameplay is paused.
/// </summary>
public readonly BindableBool IsPaused = new BindableBool(); public readonly BindableBool IsPaused = new BindableBool();
/// <summary> /// <summary>
/// The decoupled clock used for gameplay. Should be used for seeks and clock control. /// The adjustable source clock used for gameplay. Should be used for seeks and clock control.
/// </summary> /// </summary>
private readonly DecoupleableInterpolatingFramedClock adjustableClock; protected readonly DecoupleableInterpolatingFramedClock AdjustableSource;
private readonly double gameplayStartTime;
private readonly bool startAtGameplayStart;
private readonly double firstHitObjectTime;
public readonly BindableNumber<double> UserPlaybackRate = new BindableDouble(1)
{
Default = 1,
MinValue = 0.5,
MaxValue = 2,
Precision = 0.1,
};
/// <summary> /// <summary>
/// The final clock which is exposed to underlying components. /// The source clock.
/// </summary> /// </summary>
public GameplayClock GameplayClock => localGameplayClock; protected IClock SourceClock { get; private set; }
[Cached(typeof(GameplayClock))]
private readonly LocalGameplayClock localGameplayClock;
private Bindable<double> userAudioOffset;
private readonly FramedOffsetClock userOffsetClock;
private readonly FramedOffsetClock platformOffsetClock;
/// <summary> /// <summary>
/// Creates a new <see cref="GameplayClockContainer"/>. /// Creates a new <see cref="GameplayClockContainer"/>.
/// </summary> /// </summary>
/// <param name="beatmap">The beatmap being played.</param> /// <param name="sourceClock">The source <see cref="IClock"/> used for timing.</param>
/// <param name="gameplayStartTime">The suggested time to start gameplay at.</param> protected GameplayClockContainer(IClock sourceClock)
/// <param name="startAtGameplayStart">
/// Whether <paramref name="gameplayStartTime"/> should be used regardless of when storyboard events and hitobjects are supposed to start.
/// </param>
public GameplayClockContainer(WorkingBeatmap beatmap, double gameplayStartTime, bool startAtGameplayStart = false)
{ {
this.beatmap = beatmap; SourceClock = sourceClock;
this.gameplayStartTime = gameplayStartTime;
this.startAtGameplayStart = startAtGameplayStart;
track = beatmap.Track;
firstHitObjectTime = beatmap.Beatmap.HitObjects.First().StartTime;
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
adjustableClock = new DecoupleableInterpolatingFramedClock { IsCoupled = false }; AdjustableSource = new DecoupleableInterpolatingFramedClock { IsCoupled = false };
IsPaused.BindValueChanged(OnIsPausedChanged);
}
// Lazer's audio timings in general doesn't match stable. This is the result of user testing, albeit limited. protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
// This only seems to be required on windows. We need to eventually figure out why, with a bit of luck. {
platformOffsetClock = new HardwareCorrectionOffsetClock(adjustableClock) { Offset = RuntimeInfo.OS == RuntimeInfo.Platform.Windows ? 15 : 0 }; var dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
// the final usable gameplay clock with user-set offsets applied.
userOffsetClock = new HardwareCorrectionOffsetClock(platformOffsetClock);
// the clock to be exposed via DI to children.
localGameplayClock = new LocalGameplayClock(userOffsetClock);
dependencies.CacheAs(GameplayClock = CreateGameplayClock(AdjustableSource));
GameplayClock.IsPaused.BindTo(IsPaused); GameplayClock.IsPaused.BindTo(IsPaused);
IsPaused.BindValueChanged(onPauseChanged); return dependencies;
} }
private void onPauseChanged(ValueChangedEvent<bool> isPaused)
{
if (isPaused.NewValue)
this.TransformBindableTo(pauseFreqAdjust, 0, 200, Easing.Out).OnComplete(_ => adjustableClock.Stop());
else
this.TransformBindableTo(pauseFreqAdjust, 1, 200, Easing.In);
}
private double totalOffset => userOffsetClock.Offset + platformOffsetClock.Offset;
/// <summary> /// <summary>
/// Duration before gameplay start time required before skip button displays. /// Starts gameplay.
/// </summary> /// </summary>
public const double MINIMUM_SKIP_TIME = 1000; public virtual void Start()
private readonly BindableDouble pauseFreqAdjust = new BindableDouble(1);
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{ {
userAudioOffset = config.GetBindable<double>(OsuSetting.AudioOffset); // Ensure that the source clock is set.
userAudioOffset.BindValueChanged(offset => userOffsetClock.Offset = offset.NewValue, true); ChangeSource(SourceClock);
// sane default provided by ruleset. if (!AdjustableSource.IsRunning)
double startTime = gameplayStartTime;
if (!startAtGameplayStart)
{
startTime = Math.Min(0, startTime);
// if a storyboard is present, it may dictate the appropriate start time by having events in negative time space.
// this is commonly used to display an intro before the audio track start.
double? firstStoryboardEvent = beatmap.Storyboard.EarliestEventTime;
if (firstStoryboardEvent != null)
startTime = Math.Min(startTime, firstStoryboardEvent.Value);
// some beatmaps specify a current lead-in time which should be used instead of the ruleset-provided value when available.
// this is not available as an option in the live editor but can still be applied via .osu editing.
if (beatmap.BeatmapInfo.AudioLeadIn > 0)
startTime = Math.Min(startTime, firstHitObjectTime - beatmap.BeatmapInfo.AudioLeadIn);
}
Seek(startTime);
adjustableClock.ProcessFrame();
}
public void Restart()
{
Task.Run(() =>
{
track.Seek(0);
track.Stop();
Schedule(() =>
{
adjustableClock.ChangeSource(track);
updateRate();
if (!IsPaused.Value)
Start();
});
});
}
public void Start()
{
if (!adjustableClock.IsRunning)
{ {
// Seeking the decoupled clock to its current time ensures that its source clock will be seeked to the same time // Seeking the decoupled clock to its current time ensures that its source clock will be seeked to the same time
// This accounts for the audio clock source potentially taking time to enter a completely stopped state // This accounts for the clock source potentially taking time to enter a completely stopped state
Seek(GameplayClock.CurrentTime); Seek(GameplayClock.CurrentTime);
adjustableClock.Start(); AdjustableSource.Start();
} }
IsPaused.Value = false; IsPaused.Value = false;
} }
/// <summary>
/// Skip forward to the next valid skip point.
/// </summary>
public void Skip()
{
if (GameplayClock.CurrentTime > gameplayStartTime - MINIMUM_SKIP_TIME)
return;
double skipTarget = gameplayStartTime - MINIMUM_SKIP_TIME;
if (GameplayClock.CurrentTime < 0 && skipTarget > 6000)
// double skip exception for storyboards with very long intros
skipTarget = 0;
Seek(skipTarget);
}
/// <summary> /// <summary>
/// Seek to a specific time in gameplay. /// Seek to a specific time in gameplay.
/// <remarks>
/// Adjusts for any offsets which have been applied (so the seek may not be the expected point in time on the underlying audio track).
/// </remarks>
/// </summary> /// </summary>
/// <param name="time">The destination time to seek to.</param> /// <param name="time">The destination time to seek to.</param>
public void Seek(double time) public virtual void Seek(double time)
{ {
// remove the offset component here because most of the time we want the seek to be aligned to gameplay, not the audio track. AdjustableSource.Seek(time);
// we may want to consider reversing the application of offsets in the future as it may feel more correct.
adjustableClock.Seek(time - totalOffset);
// manually process frame to ensure GameplayClock is correctly updated after a seek. // Manually process to make sure the gameplay clock is correctly updated after a seek.
userOffsetClock.ProcessFrame(); GameplayClock.UnderlyingClock.ProcessFrame();
}
public void Stop()
{
IsPaused.Value = true;
} }
/// <summary> /// <summary>
/// Changes the backing clock to avoid using the originally provided track. /// Stops gameplay.
/// </summary> /// </summary>
public void StopUsingBeatmapClock() public virtual void Stop() => IsPaused.Value = true;
{
removeSourceClockAdjustments();
track = new TrackVirtual(track.Length); /// <summary>
adjustableClock.ChangeSource(track); /// Resets this <see cref="GameplayClockContainer"/> and the source to an initial state ready for gameplay.
/// </summary>
public virtual void Reset()
{
Seek(0);
// Manually stop the source in order to not affect the IsPaused state.
AdjustableSource.Stop();
if (!IsPaused.Value)
Start();
} }
/// <summary>
/// Changes the source clock.
/// </summary>
/// <param name="sourceClock">The new source.</param>
protected void ChangeSource(IClock sourceClock) => AdjustableSource.ChangeSource(SourceClock = sourceClock);
protected override void Update() protected override void Update()
{ {
if (!IsPaused.Value) if (!IsPaused.Value)
{ GameplayClock.UnderlyingClock.ProcessFrame();
userOffsetClock.ProcessFrame();
}
base.Update(); base.Update();
} }
private bool speedAdjustmentsApplied; /// <summary>
/// Invoked when the value of <see cref="IsPaused"/> is changed to start or stop the <see cref="AdjustableSource"/> clock.
private void updateRate() /// </summary>
/// <param name="isPaused">Whether the clock should now be paused.</param>
protected virtual void OnIsPausedChanged(ValueChangedEvent<bool> isPaused)
{ {
if (speedAdjustmentsApplied) if (isPaused.NewValue)
return; AdjustableSource.Stop();
else
track.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust); AdjustableSource.Start();
track.AddAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
localGameplayClock.MutableNonGameplayAdjustments.Add(pauseFreqAdjust);
localGameplayClock.MutableNonGameplayAdjustments.Add(UserPlaybackRate);
speedAdjustmentsApplied = true;
} }
protected override void Dispose(bool isDisposing) /// <summary>
{ /// Creates the final <see cref="GameplayClock"/> which is exposed via DI to be used by gameplay components.
base.Dispose(isDisposing); /// </summary>
removeSourceClockAdjustments(); /// <remarks>
} /// Any intermediate clocks such as platform offsets should be applied here.
/// </remarks>
private void removeSourceClockAdjustments() /// <param name="source">The <see cref="IFrameBasedClock"/> providing the source time.</param>
{ /// <returns>The final <see cref="GameplayClock"/>.</returns>
if (!speedAdjustmentsApplied) return; protected abstract GameplayClock CreateGameplayClock(IFrameBasedClock source);
track.RemoveAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
track.RemoveAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
localGameplayClock.MutableNonGameplayAdjustments.Remove(pauseFreqAdjust);
localGameplayClock.MutableNonGameplayAdjustments.Remove(UserPlaybackRate);
speedAdjustmentsApplied = false;
}
private class LocalGameplayClock : GameplayClock
{
public readonly List<Bindable<double>> MutableNonGameplayAdjustments = new List<Bindable<double>>();
public override IEnumerable<Bindable<double>> NonGameplayAdjustments => MutableNonGameplayAdjustments;
public LocalGameplayClock(FramedOffsetClock underlyingClock)
: base(underlyingClock)
{
}
}
private class HardwareCorrectionOffsetClock : FramedOffsetClock
{
// we always want to apply the same real-time offset, so it should be adjusted by the difference in playback rate (from realtime) to achieve this.
// base implementation already adds offset at 1.0 rate, so we only add the difference from that here.
public override double CurrentTime => base.CurrentTime + Offset * (Rate - 1);
public HardwareCorrectionOffsetClock(IClock source, bool processSource = true)
: base(source, processSource)
{
}
}
} }
} }

View File

@ -0,0 +1,233 @@
// 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.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
namespace osu.Game.Screens.Play
{
/// <summary>
/// A <see cref="GameplayClockContainer"/> which uses a <see cref="WorkingBeatmap"/> as a source.
/// <para>
/// This is the most complete <see cref="GameplayClockContainer"/> which takes into account all user and platform offsets,
/// and provides implementations for user actions such as skipping or adjusting playback rates that may occur during gameplay.
/// </para>
/// </summary>
/// <remarks>
/// This is intended to be used as a single controller for gameplay, or as a reference source for other <see cref="GameplayClockContainer"/>s.
/// </remarks>
public class MasterGameplayClockContainer : GameplayClockContainer
{
/// <summary>
/// Duration before gameplay start time required before skip button displays.
/// </summary>
public const double MINIMUM_SKIP_TIME = 1000;
protected Track Track => (Track)SourceClock;
public readonly BindableNumber<double> UserPlaybackRate = new BindableDouble(1)
{
Default = 1,
MinValue = 0.5,
MaxValue = 2,
Precision = 0.1,
};
private double totalOffset => userOffsetClock.Offset + platformOffsetClock.Offset;
private readonly BindableDouble pauseFreqAdjust = new BindableDouble(1);
private readonly WorkingBeatmap beatmap;
private readonly double gameplayStartTime;
private readonly bool startAtGameplayStart;
private readonly double firstHitObjectTime;
private FramedOffsetClock userOffsetClock;
private FramedOffsetClock platformOffsetClock;
private MasterGameplayClock masterGameplayClock;
private Bindable<double> userAudioOffset;
private double startOffset;
public MasterGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStartTime, bool startAtGameplayStart = false)
: base(beatmap.Track)
{
this.beatmap = beatmap;
this.gameplayStartTime = gameplayStartTime;
this.startAtGameplayStart = startAtGameplayStart;
firstHitObjectTime = beatmap.Beatmap.HitObjects.First().StartTime;
}
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
{
userAudioOffset = config.GetBindable<double>(OsuSetting.AudioOffset);
userAudioOffset.BindValueChanged(offset => userOffsetClock.Offset = offset.NewValue, true);
// sane default provided by ruleset.
startOffset = gameplayStartTime;
if (!startAtGameplayStart)
{
startOffset = Math.Min(0, startOffset);
// if a storyboard is present, it may dictate the appropriate start time by having events in negative time space.
// this is commonly used to display an intro before the audio track start.
double? firstStoryboardEvent = beatmap.Storyboard.EarliestEventTime;
if (firstStoryboardEvent != null)
startOffset = Math.Min(startOffset, firstStoryboardEvent.Value);
// some beatmaps specify a current lead-in time which should be used instead of the ruleset-provided value when available.
// this is not available as an option in the live editor but can still be applied via .osu editing.
if (beatmap.BeatmapInfo.AudioLeadIn > 0)
startOffset = Math.Min(startOffset, firstHitObjectTime - beatmap.BeatmapInfo.AudioLeadIn);
}
Seek(startOffset);
}
protected override void OnIsPausedChanged(ValueChangedEvent<bool> isPaused)
{
// The source is stopped by a frequency fade first.
if (isPaused.NewValue)
this.TransformBindableTo(pauseFreqAdjust, 0, 200, Easing.Out).OnComplete(_ => AdjustableSource.Stop());
else
this.TransformBindableTo(pauseFreqAdjust, 1, 200, Easing.In);
}
public override void Start()
{
addSourceClockAdjustments();
base.Start();
}
/// <summary>
/// Seek to a specific time in gameplay.
/// </summary>
/// <remarks>
/// Adjusts for any offsets which have been applied (so the seek may not be the expected point in time on the underlying audio track).
/// </remarks>
/// <param name="time">The destination time to seek to.</param>
public override void Seek(double time)
{
// remove the offset component here because most of the time we want the seek to be aligned to gameplay, not the audio track.
// we may want to consider reversing the application of offsets in the future as it may feel more correct.
base.Seek(time - totalOffset);
}
/// <summary>
/// Skip forward to the next valid skip point.
/// </summary>
public void Skip()
{
if (GameplayClock.CurrentTime > gameplayStartTime - MINIMUM_SKIP_TIME)
return;
double skipTarget = gameplayStartTime - MINIMUM_SKIP_TIME;
if (GameplayClock.CurrentTime < 0 && skipTarget > 6000)
// double skip exception for storyboards with very long intros
skipTarget = 0;
Seek(skipTarget);
}
public override void Reset()
{
base.Reset();
Seek(startOffset);
}
protected override GameplayClock CreateGameplayClock(IFrameBasedClock source)
{
// Lazer's audio timings in general doesn't match stable. This is the result of user testing, albeit limited.
// This only seems to be required on windows. We need to eventually figure out why, with a bit of luck.
platformOffsetClock = new HardwareCorrectionOffsetClock(source) { Offset = RuntimeInfo.OS == RuntimeInfo.Platform.Windows ? 15 : 0 };
// the final usable gameplay clock with user-set offsets applied.
userOffsetClock = new HardwareCorrectionOffsetClock(platformOffsetClock);
return masterGameplayClock = new MasterGameplayClock(userOffsetClock);
}
/// <summary>
/// Changes the backing clock to avoid using the originally provided track.
/// </summary>
public void StopUsingBeatmapClock()
{
removeSourceClockAdjustments();
ChangeSource(new TrackVirtual(beatmap.Track.Length));
addSourceClockAdjustments();
}
private bool speedAdjustmentsApplied;
private void addSourceClockAdjustments()
{
if (speedAdjustmentsApplied)
return;
Track.AddAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
Track.AddAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
masterGameplayClock.MutableNonGameplayAdjustments.Add(pauseFreqAdjust);
masterGameplayClock.MutableNonGameplayAdjustments.Add(UserPlaybackRate);
speedAdjustmentsApplied = true;
}
private void removeSourceClockAdjustments()
{
if (!speedAdjustmentsApplied)
return;
Track.RemoveAdjustment(AdjustableProperty.Frequency, pauseFreqAdjust);
Track.RemoveAdjustment(AdjustableProperty.Tempo, UserPlaybackRate);
masterGameplayClock.MutableNonGameplayAdjustments.Remove(pauseFreqAdjust);
masterGameplayClock.MutableNonGameplayAdjustments.Remove(UserPlaybackRate);
speedAdjustmentsApplied = false;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
removeSourceClockAdjustments();
}
private class HardwareCorrectionOffsetClock : FramedOffsetClock
{
// we always want to apply the same real-time offset, so it should be adjusted by the difference in playback rate (from realtime) to achieve this.
// base implementation already adds offset at 1.0 rate, so we only add the difference from that here.
public override double CurrentTime => base.CurrentTime + Offset * (Rate - 1);
public HardwareCorrectionOffsetClock(IClock source, bool processSource = true)
: base(source, processSource)
{
}
}
private class MasterGameplayClock : GameplayClock
{
public readonly List<Bindable<double>> MutableNonGameplayAdjustments = new List<Bindable<double>>();
public override IEnumerable<Bindable<double>> NonGameplayAdjustments => MutableNonGameplayAdjustments;
public MasterGameplayClock(FramedOffsetClock underlyingClock)
: base(underlyingClock)
{
}
}
}
}

View File

@ -295,7 +295,7 @@ namespace osu.Game.Screens.Play
IsBreakTime.BindValueChanged(onBreakTimeChanged, true); IsBreakTime.BindValueChanged(onBreakTimeChanged, true);
} }
protected virtual GameplayClockContainer CreateGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStart) => new GameplayClockContainer(beatmap, gameplayStart); protected virtual GameplayClockContainer CreateGameplayClockContainer(WorkingBeatmap beatmap, double gameplayStart) => new MasterGameplayClockContainer(beatmap, gameplayStart);
private Drawable createUnderlayComponents() => private Drawable createUnderlayComponents() =>
DimmableStoryboard = new DimmableStoryboard(Beatmap.Value.Storyboard) { RelativeSizeAxes = Axes.Both }; DimmableStoryboard = new DimmableStoryboard(Beatmap.Value.Storyboard) { RelativeSizeAxes = Axes.Both };
@ -342,7 +342,6 @@ namespace osu.Game.Screens.Play
Action = () => PerformExit(true), Action = () => PerformExit(true),
IsPaused = { BindTarget = GameplayClockContainer.IsPaused } IsPaused = { BindTarget = GameplayClockContainer.IsPaused }
}, },
PlayerSettingsOverlay = { PlaybackSettings = { UserPlaybackRate = { BindTarget = GameplayClockContainer.UserPlaybackRate } } },
KeyCounter = KeyCounter =
{ {
AlwaysVisible = { BindTarget = DrawableRuleset.HasReplayLoaded }, AlwaysVisible = { BindTarget = DrawableRuleset.HasReplayLoaded },
@ -386,6 +385,9 @@ namespace osu.Game.Screens.Play
} }
}; };
if (GameplayClockContainer is MasterGameplayClockContainer master)
HUDOverlay.PlayerSettingsOverlay.PlaybackSettings.UserPlaybackRate.BindTarget = master.UserPlaybackRate;
if (!Configuration.AllowSkippingIntro) if (!Configuration.AllowSkippingIntro)
skipOverlay.Expire(); skipOverlay.Expire();
@ -533,7 +535,8 @@ namespace osu.Game.Screens.Play
// user requested skip // user requested skip
// disable sample playback to stop currently playing samples and perform skip // disable sample playback to stop currently playing samples and perform skip
samplePlaybackDisabled.Value = true; samplePlaybackDisabled.Value = true;
GameplayClockContainer.Skip();
(GameplayClockContainer as MasterGameplayClockContainer)?.Skip();
// return samplePlaybackDisabled.Value to what is defined by the beatmap's current state // return samplePlaybackDisabled.Value to what is defined by the beatmap's current state
updateSampleDisabledState(); updateSampleDisabledState();
@ -808,7 +811,7 @@ namespace osu.Game.Screens.Play
if (GameplayClockContainer.GameplayClock.IsRunning) if (GameplayClockContainer.GameplayClock.IsRunning)
throw new InvalidOperationException($"{nameof(StartGameplay)} should not be called when the gameplay clock is already running"); throw new InvalidOperationException($"{nameof(StartGameplay)} should not be called when the gameplay clock is already running");
GameplayClockContainer.Restart(); GameplayClockContainer.Reset();
} }
public override void OnSuspending(IScreen next) public override void OnSuspending(IScreen next)
@ -832,7 +835,7 @@ namespace osu.Game.Screens.Play
// GameplayClockContainer performs seeks / start / stop operations on the beatmap's track. // GameplayClockContainer performs seeks / start / stop operations on the beatmap's track.
// as we are no longer the current screen, we cannot guarantee the track is still usable. // as we are no longer the current screen, we cannot guarantee the track is still usable.
GameplayClockContainer?.StopUsingBeatmapClock(); (GameplayClockContainer as MasterGameplayClockContainer)?.StopUsingBeatmapClock();
musicController.ResetTrackAdjustments(); musicController.ResetTrackAdjustments();

View File

@ -90,7 +90,7 @@ namespace osu.Game.Screens.Play
private const double fade_time = 300; private const double fade_time = 300;
private double fadeOutBeginTime => startTime - GameplayClockContainer.MINIMUM_SKIP_TIME; private double fadeOutBeginTime => startTime - MasterGameplayClockContainer.MINIMUM_SKIP_TIME;
protected override void LoadComplete() protected override void LoadComplete()
{ {

View File

@ -61,7 +61,7 @@ namespace osu.Game.Screens.Play
if (firstFrameTime == null || firstFrameTime <= gameplayStart + 5000) if (firstFrameTime == null || firstFrameTime <= gameplayStart + 5000)
return base.CreateGameplayClockContainer(beatmap, gameplayStart); return base.CreateGameplayClockContainer(beatmap, gameplayStart);
return new GameplayClockContainer(beatmap, firstFrameTime.Value, true); return new MasterGameplayClockContainer(beatmap, firstFrameTime.Value, true);
} }
public override bool OnExiting(IScreen next) public override bool OnExiting(IScreen next)

View File

@ -16,7 +16,7 @@ namespace osu.Game.Skinning
{ {
public double Length => !DrawableSamples.Any() ? 0 : DrawableSamples.Max(sample => sample.Length); public double Length => !DrawableSamples.Any() ? 0 : DrawableSamples.Max(sample => sample.Length);
protected bool RequestedPlaying { get; private set; } public bool RequestedPlaying { get; private set; }
public PausableSkinnableSound() public PausableSkinnableSound()
{ {

View File

@ -61,28 +61,32 @@ namespace osu.Game.Storyboards.Drawables
{ {
base.Update(); base.Update();
// Check if we've yet to pass the sample start time.
if (Time.Current < sampleInfo.StartTime) if (Time.Current < sampleInfo.StartTime)
{ {
// We've rewound before the start time of the sample
Stop(); Stop();
// In the case that the user fast-forwards to a point far beyond the start time of the sample, // Playback has stopped, but if the user fast-forwards to a point after the start time of the sample then
// we want to be able to fall into the if-conditional below (therefore we must not have a life time end) // we must not have a lifetime end in order to continue receiving updates and start the sample below.
LifetimeStart = sampleInfo.StartTime; LifetimeStart = sampleInfo.StartTime;
LifetimeEnd = double.MaxValue; LifetimeEnd = double.MaxValue;
return;
} }
else if (Time.Current - Time.Elapsed <= sampleInfo.StartTime)
// Ensure that we've elapsed from a point before the sample's start time before playing.
if (Time.Current - Time.Elapsed <= sampleInfo.StartTime)
{ {
// We've passed the start time of the sample. We only play the sample if we're within an allowable range // We've passed the start time of the sample. We only play the sample if we're within an allowable range
// from the sample's start, to reduce layering if we've been fast-forwarded far into the future // from the sample's start, to reduce layering if we've been fast-forwarded far into the future
if (!RequestedPlaying && Time.Current - sampleInfo.StartTime < allowable_late_start) if (!RequestedPlaying && Time.Current - sampleInfo.StartTime < allowable_late_start)
Play(); Play();
}
// In the case that the user rewinds to a point far behind the start time of the sample, // Playback has started, but if the user rewinds to a point before the start time of the sample then
// we want to be able to fall into the if-conditional above (therefore we must not have a life time start) // we must not have a lifetime start in order to continue receiving updates and stop the sample above.
LifetimeStart = double.MinValue; LifetimeStart = double.MinValue;
LifetimeEnd = sampleInfo.StartTime; LifetimeEnd = sampleInfo.StartTime;
} }
} }
} }
}

View File

@ -215,6 +215,8 @@ namespace osu.Game.Tests.Beatmaps
protected override Track GetBeatmapTrack() => throw new NotImplementedException(); protected override Track GetBeatmapTrack() => throw new NotImplementedException();
public override Stream GetStream(string storagePath) => throw new NotImplementedException();
protected override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap, Ruleset ruleset) protected override IBeatmapConverter CreateBeatmapConverter(IBeatmap beatmap, Ruleset ruleset)
{ {
var converter = base.CreateBeatmapConverter(beatmap, ruleset); var converter = base.CreateBeatmapConverter(beatmap, ruleset);

View File

@ -1,6 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.IO;
using osu.Framework.Audio; using osu.Framework.Audio;
using osu.Framework.Audio.Track; using osu.Framework.Audio.Track;
using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Textures;
@ -35,6 +36,8 @@ namespace osu.Game.Tests.Beatmaps
protected override Storyboard GetStoryboard() => storyboard ?? base.GetStoryboard(); protected override Storyboard GetStoryboard() => storyboard ?? base.GetStoryboard();
public override Stream GetStream(string storagePath) => null;
protected override Texture GetBackground() => null; protected override Texture GetBackground() => null;
protected override Track GetBeatmapTrack() => null; protected override Track GetBeatmapTrack() => null;

View File

@ -29,7 +29,7 @@
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="5.0.0" />
<PackageReference Include="Microsoft.NETCore.Targets" Version="3.1.0" /> <PackageReference Include="Microsoft.NETCore.Targets" Version="3.1.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="ppy.osu.Framework" Version="2021.419.0" /> <PackageReference Include="ppy.osu.Framework" Version="2021.422.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.412.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2021.412.0" />
<PackageReference Include="Sentry" Version="3.2.0" /> <PackageReference Include="Sentry" Version="3.2.0" />
<PackageReference Include="SharpCompress" Version="0.28.1" /> <PackageReference Include="SharpCompress" Version="0.28.1" />

View File

@ -70,7 +70,7 @@
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
</ItemGroup> </ItemGroup>
<ItemGroup Label="Package References"> <ItemGroup Label="Package References">
<PackageReference Include="ppy.osu.Framework.iOS" Version="2021.419.0" /> <PackageReference Include="ppy.osu.Framework.iOS" Version="2021.422.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2021.412.0" /> <PackageReference Include="ppy.osu.Game.Resources" Version="2021.412.0" />
</ItemGroup> </ItemGroup>
<!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) --> <!-- See https://github.com/dotnet/runtime/issues/35988 (can be removed after Xamarin uses net5.0 / net6.0) -->
@ -93,7 +93,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.6" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" /> <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.6" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ppy.osu.Framework" Version="2021.419.0" /> <PackageReference Include="ppy.osu.Framework" Version="2021.422.0" />
<PackageReference Include="SharpCompress" Version="0.28.1" /> <PackageReference Include="SharpCompress" Version="0.28.1" />
<PackageReference Include="NUnit" Version="3.12.0" /> <PackageReference Include="NUnit" Version="3.12.0" />
<PackageReference Include="SharpRaven" Version="2.4.0" /> <PackageReference Include="SharpRaven" Version="2.4.0" />