1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-19 20:02:57 +08:00

Merge branch 'multiplayer-beatmap-tracker' into ready-button-clean-up

This commit is contained in:
Salman Ahmed 2021-01-18 10:00:31 +03:00
commit 38588ab96b
7 changed files with 37 additions and 26 deletions

View File

@ -47,6 +47,8 @@ namespace osu.Game.Tests.Online
[SetUp] [SetUp]
public void SetUp() => Schedule(() => public void SetUp() => Schedule(() =>
{ {
beatmaps.AllowImport = new TaskCompletionSource<bool>();
testBeatmapFile = getTestBeatmapOsz(); testBeatmapFile = getTestBeatmapOsz();
testBeatmapInfo = new TestBeatmap(Ruleset.Value).BeatmapInfo; testBeatmapInfo = new TestBeatmap(Ruleset.Value).BeatmapInfo;
@ -75,15 +77,15 @@ namespace osu.Game.Tests.Online
addAvailabilityCheckStep("state not downloaded", BeatmapAvailability.NotDownloaded); addAvailabilityCheckStep("state not downloaded", BeatmapAvailability.NotDownloaded);
AddStep("start downloading", () => beatmaps.Download(testBeatmapSet)); AddStep("start downloading", () => beatmaps.Download(testBeatmapSet));
addAvailabilityCheckStep("state downloading 0%", () => BeatmapAvailability.Downloading(0.0)); addAvailabilityCheckStep("state downloading 0%", () => BeatmapAvailability.Downloading(0.0f));
AddStep("set progress 40%", () => ((TestDownloadRequest)beatmaps.GetExistingDownload(testBeatmapSet)).SetProgress(0.4)); AddStep("set progress 40%", () => ((TestDownloadRequest)beatmaps.GetExistingDownload(testBeatmapSet)).SetProgress(0.4f));
addAvailabilityCheckStep("state downloading 40%", () => BeatmapAvailability.Downloading(0.4)); addAvailabilityCheckStep("state downloading 40%", () => BeatmapAvailability.Downloading(0.4f));
AddStep("finish download", () => ((TestDownloadRequest)beatmaps.GetExistingDownload(testBeatmapSet)).TriggerSuccess(testBeatmapFile)); AddStep("finish download", () => ((TestDownloadRequest)beatmaps.GetExistingDownload(testBeatmapSet)).TriggerSuccess(testBeatmapFile));
addAvailabilityCheckStep("state importing", BeatmapAvailability.Importing); addAvailabilityCheckStep("state importing", BeatmapAvailability.Importing);
AddStep("allow importing", () => beatmaps.AllowImport.Set()); AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
AddUntilStep("wait for import", () => beatmaps.IsAvailableLocally(testBeatmapSet)); AddUntilStep("wait for import", () => beatmaps.IsAvailableLocally(testBeatmapSet));
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable); addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
} }
@ -91,7 +93,7 @@ namespace osu.Game.Tests.Online
[Test] [Test]
public void TestTrackerRespectsSoftDeleting() public void TestTrackerRespectsSoftDeleting()
{ {
AddStep("allow importing", () => beatmaps.AllowImport.Set()); AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
AddStep("import beatmap", () => beatmaps.Import(testBeatmapSet).Wait()); AddStep("import beatmap", () => beatmaps.Import(testBeatmapSet).Wait());
addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable); addAvailabilityCheckStep("state locally available", BeatmapAvailability.LocallyAvailable);
@ -105,7 +107,7 @@ namespace osu.Game.Tests.Online
[Test] [Test]
public void TestTrackerRespectsChecksum() public void TestTrackerRespectsChecksum()
{ {
AddStep("allow importing", () => beatmaps.AllowImport.Set()); AddStep("allow importing", () => beatmaps.AllowImport.SetResult(true));
BeatmapInfo wrongBeatmap = null; BeatmapInfo wrongBeatmap = null;
@ -144,7 +146,7 @@ namespace osu.Game.Tests.Online
private class TestBeatmapManager : BeatmapManager private class TestBeatmapManager : BeatmapManager
{ {
public readonly ManualResetEventSlim AllowImport = new ManualResetEventSlim(); public TaskCompletionSource<bool> AllowImport = new TaskCompletionSource<bool>();
protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize) protected override ArchiveDownloadRequest<BeatmapSetInfo> CreateDownloadRequest(BeatmapSetInfo set, bool minimiseDownloadSize)
=> new TestDownloadRequest(set); => new TestDownloadRequest(set);
@ -156,16 +158,15 @@ namespace osu.Game.Tests.Online
public override async Task<BeatmapSetInfo> Import(BeatmapSetInfo item, ArchiveReader archive = null, CancellationToken cancellationToken = default) public override async Task<BeatmapSetInfo> Import(BeatmapSetInfo item, ArchiveReader archive = null, CancellationToken cancellationToken = default)
{ {
while (!AllowImport.IsSet) await AllowImport.Task;
await Task.Delay(10, cancellationToken);
return await base.Import(item, archive, cancellationToken); return await base.Import(item, archive, cancellationToken);
} }
} }
private class TestDownloadRequest : ArchiveDownloadRequest<BeatmapSetInfo> private class TestDownloadRequest : ArchiveDownloadRequest<BeatmapSetInfo>
{ {
public new void SetProgress(double progress) => base.SetProgress(progress); public new void SetProgress(float progress) => base.SetProgress(progress);
public new void TriggerSuccess(string filename) => base.TriggerSuccess(filename);
public TestDownloadRequest(BeatmapSetInfo model) public TestDownloadRequest(BeatmapSetInfo model)
: base(model) : base(model)

View File

@ -29,7 +29,7 @@ namespace osu.Game.Online.API
private void request_Progress(long current, long total) => API.Schedule(() => Progressed?.Invoke(current, total)); private void request_Progress(long current, long total) => API.Schedule(() => Progressed?.Invoke(current, total));
internal void TriggerSuccess(string filename) protected void TriggerSuccess(string filename)
{ {
if (this.filename != null) if (this.filename != null)
throw new InvalidOperationException("Attempted to trigger success more than once"); throw new InvalidOperationException("Attempted to trigger success more than once");

View File

@ -12,16 +12,16 @@ namespace osu.Game.Online.API
public double Progress { get; private set; } public double Progress { get; private set; }
public event Action<double> DownloadProgressed; public event Action<float> DownloadProgressed;
protected ArchiveDownloadRequest(TModel model) protected ArchiveDownloadRequest(TModel model)
{ {
Model = model; Model = model;
Progressed += (current, total) => SetProgress((double)current / total); Progressed += (current, total) => SetProgress((float)current / total);
} }
protected void SetProgress(double progress) protected void SetProgress(float progress)
{ {
Progress = progress; Progress = progress;
DownloadProgressed?.Invoke(progress); DownloadProgressed?.Invoke(progress);

View File

@ -80,7 +80,7 @@ namespace osu.Game.Online
/// By default, this calls <see cref="IModelDownloader{TModel}.IsAvailableLocally"/>, /// By default, this calls <see cref="IModelDownloader{TModel}.IsAvailableLocally"/>,
/// but can be overriden to add additional checks for verifying the model in database. /// but can be overriden to add additional checks for verifying the model in database.
/// </summary> /// </summary>
protected virtual bool IsModelAvailableLocally() => Manager.IsAvailableLocally(Model.Value); protected virtual bool IsModelAvailableLocally() => Manager?.IsAvailableLocally(Model.Value) == true;
private void downloadBegan(ValueChangedEvent<WeakReference<ArchiveDownloadRequest<TModel>>> weakRequest) private void downloadBegan(ValueChangedEvent<WeakReference<ArchiveDownloadRequest<TModel>>> weakRequest)
{ {
@ -144,7 +144,7 @@ namespace osu.Game.Online
private void onRequestSuccess(string _) => Schedule(() => State.Value = DownloadState.Importing); private void onRequestSuccess(string _) => Schedule(() => State.Value = DownloadState.Importing);
private void onRequestProgress(double progress) => Schedule(() => Progress.Value = progress); private void onRequestProgress(float progress) => Schedule(() => Progress.Value = progress);
private void onRequestFailure(Exception e) => Schedule(() => attachDownload(null)); private void onRequestFailure(Exception e) => Schedule(() => attachDownload(null));

View File

@ -19,17 +19,17 @@ namespace osu.Game.Online.Rooms
/// <summary> /// <summary>
/// The beatmap's downloading progress, null when not in <see cref="DownloadState.Downloading"/> state. /// The beatmap's downloading progress, null when not in <see cref="DownloadState.Downloading"/> state.
/// </summary> /// </summary>
public readonly double? DownloadProgress; public readonly float? DownloadProgress;
[JsonConstructor] [JsonConstructor]
private BeatmapAvailability(DownloadState state, double? downloadProgress = null) private BeatmapAvailability(DownloadState state, float? downloadProgress = null)
{ {
State = state; State = state;
DownloadProgress = downloadProgress; DownloadProgress = downloadProgress;
} }
public static BeatmapAvailability NotDownloaded() => new BeatmapAvailability(DownloadState.NotDownloaded); public static BeatmapAvailability NotDownloaded() => new BeatmapAvailability(DownloadState.NotDownloaded);
public static BeatmapAvailability Downloading(double progress) => new BeatmapAvailability(DownloadState.Downloading, progress); public static BeatmapAvailability Downloading(float progress) => new BeatmapAvailability(DownloadState.Downloading, progress);
public static BeatmapAvailability Importing() => new BeatmapAvailability(DownloadState.Importing); public static BeatmapAvailability Importing() => new BeatmapAvailability(DownloadState.Importing);
public static BeatmapAvailability LocallyAvailable() => new BeatmapAvailability(DownloadState.LocallyAvailable); public static BeatmapAvailability LocallyAvailable() => new BeatmapAvailability(DownloadState.LocallyAvailable);

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Linq; using System.Linq;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Logging;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
namespace osu.Game.Online.Rooms namespace osu.Game.Online.Rooms
@ -34,6 +35,15 @@ namespace osu.Game.Online.Rooms
} }
protected override bool VerifyDatabasedModel(BeatmapSetInfo databasedSet) protected override bool VerifyDatabasedModel(BeatmapSetInfo databasedSet)
{
var verified = verifyDatabasedModel(databasedSet);
if (!verified)
Logger.Log("The imported beatmapset does not match the online version.", LoggingTarget.Runtime, LogLevel.Important);
return verified;
}
private bool verifyDatabasedModel(BeatmapSetInfo databasedSet)
{ {
int? beatmapId = SelectedItem.Value.Beatmap.Value.OnlineBeatmapID; int? beatmapId = SelectedItem.Value.Beatmap.Value.OnlineBeatmapID;
string checksum = SelectedItem.Value.Beatmap.Value.MD5Hash; string checksum = SelectedItem.Value.Beatmap.Value.MD5Hash;
@ -70,7 +80,7 @@ namespace osu.Game.Online.Rooms
break; break;
case DownloadState.Downloading: case DownloadState.Downloading:
availability.Value = BeatmapAvailability.Downloading(Progress.Value); availability.Value = BeatmapAvailability.Downloading((float)Progress.Value);
break; break;
case DownloadState.Importing: case DownloadState.Importing:

View File

@ -23,9 +23,9 @@ namespace osu.Game.Overlays.Notifications
public string CompletionText { get; set; } = "Task has completed!"; public string CompletionText { get; set; } = "Task has completed!";
private double progress; private float progress;
public double Progress public float Progress
{ {
get => progress; get => progress;
set set
@ -185,9 +185,9 @@ namespace osu.Game.Overlays.Notifications
private Color4 colourActive; private Color4 colourActive;
private Color4 colourInactive; private Color4 colourInactive;
private double progress; private float progress;
public double Progress public float Progress
{ {
get => progress; get => progress;
set set
@ -195,7 +195,7 @@ namespace osu.Game.Overlays.Notifications
if (progress == value) return; if (progress == value) return;
progress = value; progress = value;
box.ResizeTo(new Vector2((float)progress, 1), 100, Easing.OutQuad); box.ResizeTo(new Vector2(progress, 1), 100, Easing.OutQuad);
} }
} }