mirror of
https://github.com/ppy/osu.git
synced 2025-03-01 04:02:57 +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)
|
private async Task<PlaylistItem> createPlaylistItem(MultiplayerPlaylistItem item)
|
||||||
{
|
{
|
||||||
var set = await GetOnlineBeatmapSet(item.BeatmapID).ConfigureAwait(false);
|
var apiBeatmap = 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 ruleset = Rulesets.GetRuleset(item.RulesetID);
|
var ruleset = Rulesets.GetRuleset(item.RulesetID);
|
||||||
var rulesetInstance = ruleset.CreateInstance();
|
var rulesetInstance = ruleset.CreateInstance();
|
||||||
@ -719,7 +711,7 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
{
|
{
|
||||||
ID = item.ID,
|
ID = item.ID,
|
||||||
OwnerID = item.OwnerID,
|
OwnerID = item.OwnerID,
|
||||||
Beatmap = { Value = beatmap },
|
Beatmap = { Value = apiBeatmap },
|
||||||
Ruleset = { Value = ruleset },
|
Ruleset = { Value = ruleset },
|
||||||
Expired = item.Expired
|
Expired = item.Expired
|
||||||
};
|
};
|
||||||
@ -731,12 +723,12 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves a <see cref="APIBeatmapSet"/> from an online source.
|
/// Retrieves a <see cref="APIBeatmap"/> from an online source.
|
||||||
/// </summary>
|
/// </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>
|
/// <param name="cancellationToken">A token to cancel the request.</param>
|
||||||
/// <returns>The <see cref="APIBeatmapSet"/> retrieval task.</returns>
|
/// <returns>The <see cref="APIBeatmap"/> retrieval task.</returns>
|
||||||
protected abstract Task<APIBeatmapSet> GetOnlineBeatmapSet(int beatmapId, CancellationToken cancellationToken = default);
|
protected abstract Task<APIBeatmap> GetOnlineBeatmapSet(int beatmapId, CancellationToken cancellationToken = default);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// For the provided user ID, update whether the user is included in <see cref="CurrentMatchPlayingUserIds"/>.
|
/// 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 Microsoft.AspNetCore.SignalR.Client;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Game.Database;
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.API.Requests;
|
|
||||||
using osu.Game.Online.API.Requests.Responses;
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
|
|
||||||
@ -29,6 +29,9 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
|
|
||||||
private HubConnection? connection => connector?.CurrentConnection;
|
private HubConnection? connection => connector?.CurrentConnection;
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private BeatmapLookupCache beatmapLookupCache { get; set; } = null!;
|
||||||
|
|
||||||
public OnlineMultiplayerClient(EndpointConfiguration endpoints)
|
public OnlineMultiplayerClient(EndpointConfiguration endpoints)
|
||||||
{
|
{
|
||||||
endpoint = endpoints.MultiplayerEndpointUrl;
|
endpoint = endpoints.MultiplayerEndpointUrl;
|
||||||
@ -159,27 +162,9 @@ namespace osu.Game.Online.Multiplayer
|
|||||||
return connection.InvokeAsync(nameof(IMultiplayerServer.AddPlaylistItem), item);
|
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>();
|
return beatmapLookupCache.GetBeatmapAsync(beatmapId, cancellationToken);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
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);
|
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)
|
IBeatmapSetInfo? set = roomManager.ServerSideRooms.SelectMany(r => r.Playlist)
|
||||||
.FirstOrDefault(p => p.BeatmapID == beatmapId)?.Beatmap.Value.BeatmapSet
|
.FirstOrDefault(p => p.BeatmapID == beatmapId)?.Beatmap.Value.BeatmapSet
|
||||||
@ -345,13 +345,14 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
if (set == null)
|
if (set == null)
|
||||||
throw new InvalidOperationException("Beatmap not found.");
|
throw new InvalidOperationException("Beatmap not found.");
|
||||||
|
|
||||||
var apiSet = new APIBeatmapSet
|
return Task.FromResult(new APIBeatmap
|
||||||
|
{
|
||||||
|
BeatmapSet = new APIBeatmapSet
|
||||||
{
|
{
|
||||||
OnlineID = set.OnlineID,
|
OnlineID = set.OnlineID,
|
||||||
Beatmaps = set.Beatmaps.Select(b => new APIBeatmap { OnlineID = b.OnlineID }).ToArray(),
|
},
|
||||||
};
|
OnlineID = set.Beatmaps.First().OnlineID
|
||||||
|
});
|
||||||
return Task.FromResult(apiSet);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task changeMatchType(MatchType type)
|
private async Task changeMatchType(MatchType type)
|
||||||
|
Loading…
Reference in New Issue
Block a user