mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 09:32:55 +08:00
Remove local state dictionary from SpectatorScreen
This commit is contained in:
parent
83716ddb08
commit
c50b526ba0
@ -284,6 +284,18 @@ namespace osu.Game.Online.Spectator
|
||||
lastSendTime = Time.Current;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Attempts to retrieve the <see cref="SpectatorState"/> for a currently-playing user.
|
||||
/// </summary>
|
||||
/// <param name="userId">The user.</param>
|
||||
/// <param name="state">The current <see cref="SpectatorState"/> for the user, if they're playing. <c>null</c> if the user is not playing.</param>
|
||||
/// <returns><c>true</c> if successful (the user is playing), <c>false</c> otherwise.</returns>
|
||||
public bool TryGetPlayingUserState(int userId, out SpectatorState state)
|
||||
{
|
||||
lock (userLock)
|
||||
return playingUserStates.TryGetValue(userId, out state);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Bind an action to <see cref="OnUserBeganPlaying"/> with the option of running the bound action once immediately.
|
||||
/// </summary>
|
||||
|
@ -44,7 +44,6 @@ namespace osu.Game.Screens.Spectate
|
||||
private readonly object stateLock = new object();
|
||||
|
||||
private readonly Dictionary<int, User> userMap = new Dictionary<int, User>();
|
||||
private readonly Dictionary<int, SpectatorState> spectatorStates = new Dictionary<int, SpectatorState>();
|
||||
private readonly Dictionary<int, GameplayState> gameplayStates = new Dictionary<int, GameplayState>();
|
||||
|
||||
private IBindable<WeakReference<BeatmapSetInfo>> managerUpdated;
|
||||
@ -107,9 +106,12 @@ namespace osu.Game.Screens.Spectate
|
||||
|
||||
lock (stateLock)
|
||||
{
|
||||
foreach (var (userId, state) in spectatorStates)
|
||||
foreach (var (userId, _) in userMap)
|
||||
{
|
||||
if (beatmapSet.Beatmaps.Any(b => b.OnlineBeatmapID == state.BeatmapID))
|
||||
if (!spectatorClient.TryGetPlayingUserState(userId, out var userState))
|
||||
continue;
|
||||
|
||||
if (beatmapSet.Beatmaps.Any(b => b.OnlineBeatmapID == userState.BeatmapID))
|
||||
updateGameplayState(userId);
|
||||
}
|
||||
}
|
||||
@ -125,7 +127,6 @@ namespace osu.Game.Screens.Spectate
|
||||
if (!userMap.ContainsKey(userId))
|
||||
return;
|
||||
|
||||
spectatorStates[userId] = state;
|
||||
Schedule(() => OnUserStateChanged(userId, state));
|
||||
|
||||
updateGameplayState(userId);
|
||||
@ -138,7 +139,10 @@ namespace osu.Game.Screens.Spectate
|
||||
{
|
||||
Debug.Assert(userMap.ContainsKey(userId));
|
||||
|
||||
var spectatorState = spectatorStates[userId];
|
||||
// The user may have stopped playing.
|
||||
if (!spectatorClient.TryGetPlayingUserState(userId, out var spectatorState))
|
||||
return;
|
||||
|
||||
var user = userMap[userId];
|
||||
|
||||
var resolvedRuleset = rulesets.AvailableRulesets.FirstOrDefault(r => r.ID == spectatorState.RulesetID)?.CreateInstance();
|
||||
|
Loading…
Reference in New Issue
Block a user