1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-05 15:03:16 +08:00

Fix queue list not considering expired items

This commit is contained in:
Dan Balasescu 2021-12-01 20:53:29 +09:00
parent e2f289eeff
commit ad35f3434b
2 changed files with 28 additions and 17 deletions

View File

@ -15,13 +15,13 @@ using osu.Game.Tests.Beatmaps;
namespace osu.Game.Tests.Visual.Multiplayer namespace osu.Game.Tests.Visual.Multiplayer
{ {
public class TestSceneMultiplayerQueueList : OsuTestScene public class TestSceneMultiplayerQueueList : MultiplayerTestScene
{ {
private MultiplayerQueueList list; private MultiplayerQueueList list;
private int currentItemId; private int currentItemId;
[SetUp] [SetUp]
public void Setup() => Schedule(() => public new void Setup() => Schedule(() =>
{ {
Child = list = new MultiplayerQueueList Child = list = new MultiplayerQueueList
{ {
@ -34,8 +34,10 @@ namespace osu.Game.Tests.Visual.Multiplayer
}); });
[SetUpSteps] [SetUpSteps]
public void SetUpSteps() public override void SetUpSteps()
{ {
base.SetUpSteps();
// Not inside a step since this is used to affect steps added by the current test. // Not inside a step since this is used to affect steps added by the current test.
currentItemId = 0; currentItemId = 0;
} }

View File

@ -4,6 +4,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -35,6 +36,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist
{ {
public readonly IBindable<QueueMode> QueueMode = new Bindable<QueueMode>(); public readonly IBindable<QueueMode> QueueMode = new Bindable<QueueMode>();
[Resolved(typeof(Room), nameof(Room.Playlist))]
private BindableList<PlaylistItem> roomPlaylist { get; set; }
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
@ -53,20 +57,25 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist
.OrderBy(item => item.Model.ID); .OrderBy(item => item.Model.ID);
case Game.Online.Multiplayer.QueueMode.AllPlayersRoundRobin: case Game.Online.Multiplayer.QueueMode.AllPlayersRoundRobin:
RearrangeableListItem<PlaylistItem>[] allItems = AliveInternalChildren RearrangeableListItem<PlaylistItem>[] items = AliveInternalChildren
.Where(d => d.IsPresent) .Where(d => d.IsPresent)
.OfType<RearrangeableListItem<PlaylistItem>>() .OfType<RearrangeableListItem<PlaylistItem>>()
.OrderBy(item => item.Model.ID) .OrderBy(item => item.Model.ID)
.ToArray(); .ToArray();
int totalCount = allItems.Length; int totalCount = items.Length;
if (totalCount == 0) if (totalCount == 0)
return Enumerable.Empty<Drawable>(); return Enumerable.Empty<Drawable>();
Dictionary<int, int> perUserCounts = allItems // Count of "expired" items per user.
.Select(item => item.Model.OwnerID) Dictionary<int, int> perUserCounts = roomPlaylist
.Distinct() .Where(item => item.Expired)
.ToDictionary(u => u, _ => 0); .GroupBy(item => item.OwnerID)
.ToDictionary(group => group.Key, group => group.Count());
// Fill the count dictionary with zeroes for all users with no currently expired items.
foreach (var item in items)
perUserCounts.TryAdd(item.Model.OwnerID, 0);
List<Drawable> result = new List<Drawable>(); List<Drawable> result = new List<Drawable>();
@ -76,16 +85,16 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match.Playlist
// Todo: This could probably be more efficient, likely at the cost of increased complexity. // Todo: This could probably be more efficient, likely at the cost of increased complexity.
while (totalCount-- > 0) while (totalCount-- > 0)
{ {
var candidateItem = allItems var candidateItem = items
.Where(item => item != null) .Where(item => item != null)
.OrderBy(item => perUserCounts[item.Model.OwnerID]) .OrderBy(item => perUserCounts[item.Model.OwnerID])
.First(); .First();
int itemIndex = Array.IndexOf(allItems, candidateItem); int itemIndex = Array.IndexOf(items, candidateItem);
result.Add(allItems[itemIndex]); result.Add(items[itemIndex]);
perUserCounts[candidateItem.Model.OwnerID]++; perUserCounts[candidateItem.Model.OwnerID]++;
allItems[itemIndex] = null; items[itemIndex] = null;
} }
return result; return result;