mirror of
https://github.com/ppy/osu.git
synced 2025-01-14 02:22:56 +08:00
Ensure all read and write operations on APIRoom
are done on the update thread
This commit is contained in:
parent
42ad726154
commit
a0ff86f5e8
@ -444,18 +444,28 @@ namespace osu.Game.Online.Multiplayer
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
async Task IMultiplayerClient.SettingsChanged(MultiplayerRoomSettings newSettings)
|
||||
Task IMultiplayerClient.SettingsChanged(MultiplayerRoomSettings newSettings)
|
||||
{
|
||||
Debug.Assert(APIRoom != null);
|
||||
Debug.Assert(Room != null);
|
||||
|
||||
// ensure the new selected item is populated immediately.
|
||||
var playlistItem = APIRoom.Playlist.SingleOrDefault(p => p.ID == newSettings.PlaylistItemId);
|
||||
Scheduler.Add(() =>
|
||||
{
|
||||
// ensure the new selected item is populated immediately.
|
||||
var playlistItem = APIRoom.Playlist.SingleOrDefault(p => p.ID == newSettings.PlaylistItemId);
|
||||
|
||||
if (playlistItem != null)
|
||||
await PopulateBeatmap(playlistItem).ConfigureAwait(false);
|
||||
if (playlistItem != null)
|
||||
{
|
||||
GetAPIBeatmap(playlistItem.BeatmapID).ContinueWith(b =>
|
||||
{
|
||||
Scheduler.Add(() => playlistItem.Beatmap.Value = b.Result);
|
||||
}, TaskContinuationOptions.OnlyOnRanToCompletion);
|
||||
}
|
||||
|
||||
Scheduler.Add(() => updateLocalRoomSettings(newSettings));
|
||||
updateLocalRoomSettings(newSettings);
|
||||
});
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
Task IMultiplayerClient.UserStateChanged(int userId, MultiplayerUserState state)
|
||||
@ -727,19 +737,11 @@ namespace osu.Game.Online.Multiplayer
|
||||
playlistItem.AllowedMods.AddRange(item.AllowedMods.Select(m => m.ToMod(rulesetInstance)));
|
||||
|
||||
if (populateBeatmapImmediately)
|
||||
await PopulateBeatmap(playlistItem).ConfigureAwait(false);
|
||||
playlistItem.Beatmap.Value = await GetAPIBeatmap(item.BeatmapID).ConfigureAwait(false);
|
||||
|
||||
return playlistItem;
|
||||
}
|
||||
|
||||
public async Task PopulateBeatmap(PlaylistItem item)
|
||||
{
|
||||
if (item.Beatmap.Value != null)
|
||||
return;
|
||||
|
||||
item.Beatmap.Value = await GetAPIBeatmap(item.BeatmapID).ConfigureAwait(false);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves a <see cref="APIBeatmap"/> from an online source.
|
||||
/// </summary>
|
||||
|
@ -69,6 +69,9 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
[Resolved]
|
||||
private UserLookupCache userLookupCache { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private BeatmapLookupCache beatmapLookupCache { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private MultiplayerClient multiplayerClient { get; set; }
|
||||
|
||||
@ -148,10 +151,11 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
{
|
||||
try
|
||||
{
|
||||
var user = await userLookupCache.GetUserAsync(Item.OwnerID).ConfigureAwait(false);
|
||||
Schedule(() => ownerAvatar.User = user);
|
||||
var foundUser = await userLookupCache.GetUserAsync(Item.OwnerID).ConfigureAwait(false);
|
||||
Schedule(() => ownerAvatar.User = foundUser);
|
||||
|
||||
await multiplayerClient.PopulateBeatmap(Item).ConfigureAwait(false);
|
||||
var foundBeatmap = await beatmapLookupCache.GetBeatmapAsync(Item.BeatmapID).ConfigureAwait(false);
|
||||
Schedule(() => Item.Beatmap.Value = foundBeatmap);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user