Send multiplayer user IDs via ctor for better thread safety

This commit is contained in:
Dean Herbert 2020-12-24 10:38:53 +09:00
parent 60be1bedc9
commit d6dadd12fa
2 changed files with 18 additions and 5 deletions

View File

@ -2,6 +2,7 @@
// See the LICENCE file in the repository root for full licence text.
using System.Collections.Specialized;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
@ -188,7 +189,14 @@ public override bool OnBackButton()
private void onPlaylistChanged(object sender, NotifyCollectionChangedEventArgs e) => SelectedItem.Value = Playlist.FirstOrDefault();
private void onLoadRequested() => multiplayer?.Push(new PlayerLoader(() => new RealtimePlayer(SelectedItem.Value)));
private void onLoadRequested()
{
Debug.Assert(client.Room != null);
int[] userIds = client.Room.Users.Where(u => u.State >= MultiplayerUserState.WaitingForLoad).Select(u => u.UserID).ToArray();
multiplayer?.Push(new PlayerLoader(() => new RealtimePlayer(SelectedItem.Value, userIds)));
}
protected override void Dispose(bool isDisposing)
{

View File

@ -3,7 +3,6 @@
using System;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
@ -37,9 +36,17 @@ public class RealtimePlayer : TimeshiftPlayer
[CanBeNull]
private MultiplayerGameplayLeaderboard leaderboard;
public RealtimePlayer(PlaylistItem playlistItem)
private readonly int[] userIds;
/// <summary>
/// Construct a multiplayer player.
/// </summary>
/// <param name="playlistItem">The playlist item to be played.</param>
/// <param name="userIds">The users which are participating in this game.</param>
public RealtimePlayer(PlaylistItem playlistItem, int[] userIds)
: base(playlistItem, false)
{
this.userIds = userIds;
}
[BackgroundDependencyLoader]
@ -65,8 +72,6 @@ private void load()
Debug.Assert(client.Room != null);
int[] userIds = client.Room.Users.Where(u => u.State >= MultiplayerUserState.WaitingForLoad).Select(u => u.UserID).ToArray();
// todo: this should be implemented via a custom HUD implementation, and correctly masked to the main content area.
LoadComponentAsync(leaderboard = new MultiplayerGameplayLeaderboard(ScoreProcessor, userIds), HUDOverlay.Add);
}