1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 16:32:54 +08:00

Fix SpectatorScreen potentially missing user playing callbacks

This commit is contained in:
smoogipoo 2021-04-16 18:22:22 +09:00
parent 46d2181d42
commit 274e33184b

View File

@ -62,26 +62,42 @@ namespace osu.Game.Screens.Spectate
{
base.LoadComplete();
spectatorClient.OnUserBeganPlaying += userBeganPlaying;
spectatorClient.OnUserFinishedPlaying += userFinishedPlaying;
spectatorClient.OnNewFrames += userSentFrames;
foreach (var id in userIds)
populateAllUsers().ContinueWith(_ => Schedule(() =>
{
userLookupCache.GetUserAsync(id).ContinueWith(u => Schedule(() =>
spectatorClient.BindUserBeganPlaying(userBeganPlaying, true);
spectatorClient.OnUserFinishedPlaying += userFinishedPlaying;
spectatorClient.OnNewFrames += userSentFrames;
managerUpdated = beatmaps.ItemUpdated.GetBoundCopy();
managerUpdated.BindValueChanged(beatmapUpdated);
lock (stateLock)
{
if (u.Result == null)
foreach (var (id, _) in userMap)
spectatorClient.WatchUser(id);
}
}));
}
private Task populateAllUsers()
{
var userLookupTasks = new Task[userIds.Length];
for (int i = 0; i < userIds.Length; i++)
{
var userId = userIds[i];
userLookupTasks[i] = userLookupCache.GetUserAsync(userId).ContinueWith(task =>
{
if (!task.IsCompletedSuccessfully)
return;
lock (stateLock)
userMap[id] = u.Result;
spectatorClient.WatchUser(id);
}), TaskContinuationOptions.OnlyOnRanToCompletion);
userMap[userId] = task.Result;
});
}
managerUpdated = beatmaps.ItemUpdated.GetBoundCopy();
managerUpdated.BindValueChanged(beatmapUpdated);
return Task.WhenAll(userLookupTasks);
}
private void beatmapUpdated(ValueChangedEvent<WeakReference<BeatmapSetInfo>> e)