mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 12:57:36 +08:00
Update MultiplayerClient
to use BeatmapLookupCache
This commit is contained in:
parent
87883f1fe4
commit
f58c5cd9c0
@ -702,15 +702,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
private async Task<PlaylistItem> createPlaylistItem(MultiplayerPlaylistItem item)
|
||||
{
|
||||
var set = await GetOnlineBeatmapSet(item.BeatmapID).ConfigureAwait(false);
|
||||
|
||||
// The incoming response is deserialised without circular reference handling currently.
|
||||
// Because we require using metadata from this instance, populate the nested beatmaps' sets manually here.
|
||||
foreach (var b in set.Beatmaps)
|
||||
b.BeatmapSet = set;
|
||||
|
||||
var beatmap = set.Beatmaps.Single(b => b.OnlineID == item.BeatmapID);
|
||||
beatmap.Checksum = item.BeatmapChecksum;
|
||||
var apiBeatmap = await GetOnlineBeatmapSet(item.BeatmapID).ConfigureAwait(false);
|
||||
|
||||
var ruleset = Rulesets.GetRuleset(item.RulesetID);
|
||||
var rulesetInstance = ruleset.CreateInstance();
|
||||
@ -719,7 +711,7 @@ namespace osu.Game.Online.Multiplayer
|
||||
{
|
||||
ID = item.ID,
|
||||
OwnerID = item.OwnerID,
|
||||
Beatmap = { Value = beatmap },
|
||||
Beatmap = { Value = apiBeatmap },
|
||||
Ruleset = { Value = ruleset },
|
||||
Expired = item.Expired
|
||||
};
|
||||
@ -731,12 +723,12 @@ namespace osu.Game.Online.Multiplayer
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a <see cref="APIBeatmapSet"/> from an online source.
|
||||
/// Retrieves a <see cref="APIBeatmap"/> from an online source.
|
||||
/// </summary>
|
||||
/// <param name="beatmapId">The beatmap set ID.</param>
|
||||
/// <param name="beatmapId">The beatmap ID.</param>
|
||||
/// <param name="cancellationToken">A token to cancel the request.</param>
|
||||
/// <returns>The <see cref="APIBeatmapSet"/> retrieval task.</returns>
|
||||
protected abstract Task<APIBeatmapSet> GetOnlineBeatmapSet(int beatmapId, CancellationToken cancellationToken = default);
|
||||
/// <returns>The <see cref="APIBeatmap"/> retrieval task.</returns>
|
||||
protected abstract Task<APIBeatmap> GetOnlineBeatmapSet(int beatmapId, CancellationToken cancellationToken = default);
|
||||
|
||||
/// <summary>
|
||||
/// For the provided user ID, update whether the user is included in <see cref="CurrentMatchPlayingUserIds"/>.
|
||||
|
@ -9,8 +9,8 @@ using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.SignalR.Client;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
||||
@ -29,6 +29,9 @@ namespace osu.Game.Online.Multiplayer
|
||||
|
||||
private HubConnection? connection => connector?.CurrentConnection;
|
||||
|
||||
[Resolved]
|
||||
private BeatmapLookupCache beatmapLookupCache { get; set; } = null!;
|
||||
|
||||
public OnlineMultiplayerClient(EndpointConfiguration endpoints)
|
||||
{
|
||||
endpoint = endpoints.MultiplayerEndpointUrl;
|
||||
@ -159,27 +162,9 @@ namespace osu.Game.Online.Multiplayer
|
||||
return connection.InvokeAsync(nameof(IMultiplayerServer.AddPlaylistItem), item);
|
||||
}
|
||||
|
||||
protected override Task<APIBeatmapSet> GetOnlineBeatmapSet(int beatmapId, CancellationToken cancellationToken = default)
|
||||
protected override Task<APIBeatmap> GetOnlineBeatmapSet(int beatmapId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<APIBeatmapSet>();
|
||||
var req = new GetBeatmapSetRequest(beatmapId, BeatmapSetLookupType.BeatmapId);
|
||||
|
||||
req.Success += res =>
|
||||
{
|
||||
if (cancellationToken.IsCancellationRequested)
|
||||
{
|
||||
tcs.SetCanceled();
|
||||
return;
|
||||
}
|
||||
|
||||
tcs.SetResult(res);
|
||||
};
|
||||
|
||||
req.Failure += e => tcs.SetException(e);
|
||||
|
||||
API.Queue(req);
|
||||
|
||||
return tcs.Task;
|
||||
return beatmapLookupCache.GetBeatmapAsync(beatmapId, cancellationToken);
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
|
@ -336,7 +336,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
|
||||
public override Task AddPlaylistItem(MultiplayerPlaylistItem item) => AddUserPlaylistItem(api.LocalUser.Value.OnlineID, item);
|
||||
|
||||
protected override Task<APIBeatmapSet> GetOnlineBeatmapSet(int beatmapId, CancellationToken cancellationToken = default)
|
||||
protected override Task<APIBeatmap> GetOnlineBeatmapSet(int beatmapId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
IBeatmapSetInfo? set = roomManager.ServerSideRooms.SelectMany(r => r.Playlist)
|
||||
.FirstOrDefault(p => p.BeatmapID == beatmapId)?.Beatmap.Value.BeatmapSet
|
||||
@ -345,13 +345,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
||||
if (set == null)
|
||||
throw new InvalidOperationException("Beatmap not found.");
|
||||
|
||||
var apiSet = new APIBeatmapSet
|
||||
return Task.FromResult(new APIBeatmap
|
||||
{
|
||||
OnlineID = set.OnlineID,
|
||||
Beatmaps = set.Beatmaps.Select(b => new APIBeatmap { OnlineID = b.OnlineID }).ToArray(),
|
||||
};
|
||||
|
||||
return Task.FromResult(apiSet);
|
||||
BeatmapSet = new APIBeatmapSet
|
||||
{
|
||||
OnlineID = set.OnlineID,
|
||||
},
|
||||
OnlineID = set.Beatmaps.First().OnlineID
|
||||
});
|
||||
}
|
||||
|
||||
private async Task changeMatchType(MatchType type)
|
||||
|
Loading…
Reference in New Issue
Block a user