1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 02:07:34 +08:00

watchedUsers -> watchedUsersRefCounts

This commit is contained in:
Salman Ahmed 2022-08-25 09:50:52 +03:00
parent e378c5b866
commit 6840e906e7

View File

@ -67,7 +67,7 @@ namespace osu.Game.Online.Spectator
/// <summary> /// <summary>
/// A dictionary containing all users currently being watched, with the number of watching components for each user. /// A dictionary containing all users currently being watched, with the number of watching components for each user.
/// </summary> /// </summary>
private readonly Dictionary<int, int> watchedUsers = new Dictionary<int, int>(); private readonly Dictionary<int, int> watchedUsersRefCounts = new Dictionary<int, int>();
private readonly BindableDictionary<int, SpectatorState> watchedUserStates = new BindableDictionary<int, SpectatorState>(); private readonly BindableDictionary<int, SpectatorState> watchedUserStates = new BindableDictionary<int, SpectatorState>();
@ -95,8 +95,8 @@ namespace osu.Game.Online.Spectator
if (connected.NewValue) if (connected.NewValue)
{ {
// get all the users that were previously being watched // get all the users that were previously being watched
var users = new Dictionary<int, int>(watchedUsers); var users = new Dictionary<int, int>(watchedUsersRefCounts);
watchedUsers.Clear(); watchedUsersRefCounts.Clear();
// resubscribe to watched users. // resubscribe to watched users.
foreach ((int user, int watchers) in users) foreach ((int user, int watchers) in users)
@ -125,7 +125,7 @@ namespace osu.Game.Online.Spectator
if (!playingUsers.Contains(userId)) if (!playingUsers.Contains(userId))
playingUsers.Add(userId); playingUsers.Add(userId);
if (watchedUsers.ContainsKey(userId)) if (watchedUsersRefCounts.ContainsKey(userId))
watchedUserStates[userId] = state; watchedUserStates[userId] = state;
OnUserBeganPlaying?.Invoke(userId, state); OnUserBeganPlaying?.Invoke(userId, state);
@ -140,7 +140,7 @@ namespace osu.Game.Online.Spectator
{ {
playingUsers.Remove(userId); playingUsers.Remove(userId);
if (watchedUsers.ContainsKey(userId)) if (watchedUsersRefCounts.ContainsKey(userId))
watchedUserStates[userId] = state; watchedUserStates[userId] = state;
OnUserFinishedPlaying?.Invoke(userId, state); OnUserFinishedPlaying?.Invoke(userId, state);
@ -236,13 +236,13 @@ namespace osu.Game.Online.Spectator
{ {
Debug.Assert(ThreadSafety.IsUpdateThread); Debug.Assert(ThreadSafety.IsUpdateThread);
if (watchedUsers.ContainsKey(userId)) if (watchedUsersRefCounts.ContainsKey(userId))
{ {
watchedUsers[userId]++; watchedUsersRefCounts[userId]++;
return; return;
} }
watchedUsers.Add(userId, 1); watchedUsersRefCounts.Add(userId, 1);
WatchUserInternal(userId); WatchUserInternal(userId);
} }
@ -252,13 +252,13 @@ namespace osu.Game.Online.Spectator
// Todo: This should not be a thing, but requires framework changes. // Todo: This should not be a thing, but requires framework changes.
Schedule(() => Schedule(() =>
{ {
if (watchedUsers.TryGetValue(userId, out int watchers) && watchers > 1) if (watchedUsersRefCounts.TryGetValue(userId, out int watchers) && watchers > 1)
{ {
watchedUsers[userId]--; watchedUsersRefCounts[userId]--;
return; return;
} }
watchedUsers.Remove(userId); watchedUsersRefCounts.Remove(userId);
watchedUserStates.Remove(userId); watchedUserStates.Remove(userId);
StopWatchingUserInternal(userId); StopWatchingUserInternal(userId);
}); });