Skip to content

Commit

Permalink
Merge pull request #30807 from smoogipoo/multiplayer-nrt
Browse files Browse the repository at this point in the history
Enable NRT for multiplayer and playlists
  • Loading branch information
bdach authored Nov 22, 2024
2 parents 4a129ac + 512d2c6 commit ce3d4e8
Show file tree
Hide file tree
Showing 58 changed files with 358 additions and 414 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void TestPlayingUsersUpdatedOnJoin()
AddStep("create room initially in gameplay", () =>
{
var newRoom = new Room();
newRoom.CopyFrom(SelectedRoom.Value);
newRoom.CopyFrom(SelectedRoom.Value!);

newRoom.RoomID = null;
MultiplayerClient.RoomSetupAction = room =>
Expand Down
12 changes: 5 additions & 7 deletions osu.Game.Tests/OnlinePlay/TestSceneCatchUpSyncManager.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Collections.Generic;
using NUnit.Framework;
Expand All @@ -21,12 +19,12 @@ namespace osu.Game.Tests.OnlinePlay
[HeadlessTest]
public partial class TestSceneCatchUpSyncManager : OsuTestScene
{
private GameplayClockContainer master;
private SpectatorSyncManager syncManager;
private GameplayClockContainer master = null!;
private SpectatorSyncManager syncManager = null!;

private Dictionary<SpectatorPlayerClock, int> clocksById;
private SpectatorPlayerClock player1;
private SpectatorPlayerClock player2;
private Dictionary<SpectatorPlayerClock, int> clocksById = null!;
private SpectatorPlayerClock player1 = null!;
private SpectatorPlayerClock player2 = null!;

[SetUp]
public void Setup()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Collections.Generic;
using System.Collections.Specialized;
Expand Down Expand Up @@ -31,7 +29,7 @@ public abstract partial class MultiplayerGameplayLeaderboardTestScene : OsuTestS

protected readonly BindableList<MultiplayerRoomUser> MultiplayerUsers = new BindableList<MultiplayerRoomUser>();

protected MultiplayerGameplayLeaderboard Leaderboard { get; private set; }
protected MultiplayerGameplayLeaderboard? Leaderboard { get; private set; }

protected virtual MultiplayerRoomUser CreateUser(int userId) => new MultiplayerRoomUser(userId);

Expand All @@ -40,7 +38,7 @@ public abstract partial class MultiplayerGameplayLeaderboardTestScene : OsuTestS
private readonly BindableList<int> multiplayerUserIds = new BindableList<int>();
private readonly BindableDictionary<int, SpectatorState> watchedUserStates = new BindableDictionary<int, SpectatorState>();

private OsuConfigManager config;
private OsuConfigManager config = null!;

private readonly Mock<SpectatorClient> spectatorClient = new Mock<SpectatorClient>();
private readonly Mock<MultiplayerClient> multiplayerClient = new Mock<MultiplayerClient>();
Expand Down Expand Up @@ -133,7 +131,7 @@ public virtual void SetUpSteps()
LoadComponentAsync(Leaderboard = CreateLeaderboard(), Add);
});

AddUntilStep("wait for load", () => Leaderboard.IsLoaded);
AddUntilStep("wait for load", () => Leaderboard!.IsLoaded);

AddStep("check watch requests were sent", () =>
{
Expand All @@ -146,7 +144,7 @@ public virtual void SetUpSteps()
public void TestScoreUpdates()
{
AddRepeatStep("update state", UpdateUserStatesRandomly, 100);
AddToggleStep("switch compact mode", expanded => Leaderboard.Expanded.Value = expanded);
AddToggleStep("switch compact mode", expanded => Leaderboard!.Expanded.Value = expanded);
}

[Test]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using NUnit.Framework;
using osu.Framework.Graphics;
Expand All @@ -12,7 +10,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
public partial class TestSceneCreateMultiplayerMatchButton : MultiplayerTestScene
{
private CreateMultiplayerMatchButton button;
private CreateMultiplayerMatchButton button = null!;

public override void SetUpSteps()
{
Expand All @@ -29,7 +27,7 @@ public override void SetUpSteps()
[Test]
public void TestButtonEnableStateChanges()
{
IDisposable joiningRoomOperation = null;
IDisposable joiningRoomOperation = null!;

assertButtonEnableState(true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void TestAddAndRemoveUsers()
AddAssert("4 circles displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 4);
AddAssert("46 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 46);

AddStep("remove from end", () => removeUserAt(SelectedRoom.Value.RecentParticipants.Count - 1));
AddStep("remove from end", () => removeUserAt(SelectedRoom.Value!.RecentParticipants.Count - 1));
AddAssert("4 circles displayed", () => list.ChildrenOfType<UpdateableAvatar>().Count() == 4);
AddAssert("45 hidden users", () => list.ChildrenOfType<DrawableRoomParticipantsList.HiddenUserCount>().Single().Count == 45);

Expand All @@ -138,18 +138,18 @@ public void TestAddAndRemoveUsers()

private void addUser(int id)
{
SelectedRoom.Value.RecentParticipants = SelectedRoom.Value.RecentParticipants.Append(new APIUser
SelectedRoom.Value!.RecentParticipants = SelectedRoom.Value!.RecentParticipants.Append(new APIUser
{
Id = id,
Username = $"User {id}"
}).ToArray();
SelectedRoom.Value.ParticipantCount++;
SelectedRoom.Value!.ParticipantCount++;
}

private void removeUserAt(int index)
{
SelectedRoom.Value.RecentParticipants = SelectedRoom.Value.RecentParticipants.Where(u => !u.Equals(SelectedRoom.Value.RecentParticipants[index])).ToArray();
SelectedRoom.Value.ParticipantCount--;
SelectedRoom.Value!.RecentParticipants = SelectedRoom.Value!.RecentParticipants.Where(u => !u.Equals(SelectedRoom.Value!.RecentParticipants[index])).ToArray();
SelectedRoom.Value!.ParticipantCount--;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Collections.Generic;
using System.Diagnostics;
Expand Down Expand Up @@ -39,9 +37,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
public partial class TestSceneDrawableRoomPlaylist : MultiplayerTestScene
{
private TestPlaylist playlist;

private BeatmapManager manager;
private TestPlaylist playlist = null!;
private BeatmapManager manager = null!;

[BackgroundDependencyLoader]
private void load(GameHost host, AudioManager audio)
Expand Down Expand Up @@ -199,14 +196,14 @@ public void TestKeyboardSelection()
[Test]
public void TestDownloadButtonHiddenWhenBeatmapExists()
{
Live<BeatmapSetInfo> imported = null;
Live<BeatmapSetInfo> imported = null!;

AddStep("import beatmap", () =>
{
var beatmap = new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo;

Debug.Assert(beatmap.BeatmapSet != null);
imported = manager.Import(beatmap.BeatmapSet);
imported = manager.Import(beatmap.BeatmapSet)!;
});

createPlaylistWithBeatmaps(() => imported.PerformRead(s => s.Beatmaps.Detach()));
Expand Down Expand Up @@ -378,7 +375,7 @@ private void createPlaylistWithBeatmaps(Func<IEnumerable<IBeatmapInfo>> beatmaps
}
});

private void createPlaylist(Action<TestPlaylist> setupPlaylist = null)
private void createPlaylist(Action<TestPlaylist>? setupPlaylist = null)
{
AddStep("create playlist", () =>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -26,9 +24,9 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
public partial class TestSceneFreeModSelectOverlay : MultiplayerTestScene
{
private FreeModSelectOverlay freeModSelectOverlay;
private FooterButtonFreeMods footerButtonFreeMods;
private ScreenFooter footer;
private FreeModSelectOverlay freeModSelectOverlay = null!;
private FooterButtonFreeMods footerButtonFreeMods = null!;
private ScreenFooter footer = null!;
private readonly Bindable<Dictionary<ModType, IReadOnlyList<Mod>>> availableMods = new Bindable<Dictionary<ModType, IReadOnlyList<Mod>>>();

[BackgroundDependencyLoader]
Expand All @@ -49,8 +47,7 @@ public void TestFreeModSelect()

AddToggleStep("toggle visibility", visible =>
{
if (freeModSelectOverlay != null)
freeModSelectOverlay.State.Value = visible ? Visibility.Visible : Visibility.Hidden;
freeModSelectOverlay.State.Value = visible ? Visibility.Visible : Visibility.Hidden;
});
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System.Linq;
using Moq;
using NUnit.Framework;
Expand All @@ -20,7 +18,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
public partial class TestSceneGameplayChatDisplay : OsuManualInputManagerTestScene
{
private GameplayChatDisplay chatDisplay;
private GameplayChatDisplay chatDisplay = null!;

[Cached(typeof(ILocalUserPlayInfo))]
private ILocalUserPlayInfo localUserInfo;
Expand Down
12 changes: 5 additions & 7 deletions osu.Game.Tests/Visual/Multiplayer/TestSceneHostOnlyQueueMode.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System;
using System.Linq;
using NUnit.Framework;
Expand Down Expand Up @@ -70,13 +68,13 @@ public void TestOnlyLastItemChangedAfterGameplayFinished()
{
RunGameplay();

IBeatmapInfo firstBeatmap = null;
AddStep("get first playlist item beatmap", () => firstBeatmap = MultiplayerClient.ServerAPIRoom?.Playlist[0].Beatmap);
IBeatmapInfo firstBeatmap = null!;
AddStep("get first playlist item beatmap", () => firstBeatmap = MultiplayerClient.ServerAPIRoom!.Playlist[0].Beatmap);

selectNewItem(() => OtherBeatmap);

AddUntilStep("first playlist item hasn't changed", () => MultiplayerClient.ServerAPIRoom?.Playlist[0].Beatmap == firstBeatmap);
AddUntilStep("second playlist item changed", () => MultiplayerClient.ClientAPIRoom?.Playlist[1].Beatmap != firstBeatmap);
AddUntilStep("first playlist item hasn't changed", () => MultiplayerClient.ServerAPIRoom!.Playlist[0].Beatmap == firstBeatmap);
AddUntilStep("second playlist item changed", () => MultiplayerClient.ClientAPIRoom!.Playlist[1].Beatmap != firstBeatmap);
}

[Test]
Expand All @@ -103,7 +101,7 @@ private void selectNewItem(Func<BeatmapInfo> beatmap)

AddUntilStep("wait for song select", () => CurrentSubScreen is Screens.Select.SongSelect select && select.BeatmapSetsLoaded);

BeatmapInfo otherBeatmap = null;
BeatmapInfo otherBeatmap = null!;
AddStep("select other beatmap", () => ((Screens.Select.SongSelect)CurrentSubScreen).FinaliseSelection(otherBeatmap = beatmap()));

AddUntilStep("wait for return to match", () => CurrentSubScreen is MultiplayerMatchSubScreen);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System.Linq;
using NUnit.Framework;
using osu.Framework.Graphics;
Expand All @@ -23,7 +21,7 @@ public partial class TestSceneLoungeRoomsContainer : OnlinePlayTestScene
{
protected new TestRoomManager RoomManager => (TestRoomManager)base.RoomManager;

private RoomsContainer container;
private RoomsContainer container = null!;

public override void SetUpSteps()
{
Expand Down Expand Up @@ -65,7 +63,7 @@ public void TestBasicListChanges()
AddStep("select first room", () => container.Rooms.First().TriggerClick());
AddAssert("first spotlight selected", () => checkRoomSelected(RoomManager.Rooms.First(r => r.Category == RoomCategory.Spotlight)));

AddStep("remove last room", () => RoomManager.RemoveRoom(RoomManager.Rooms.MinBy(r => r.RoomID)));
AddStep("remove last room", () => RoomManager.RemoveRoom(RoomManager.Rooms.MinBy(r => r.RoomID)!));
AddAssert("first spotlight still selected", () => checkRoomSelected(RoomManager.Rooms.First(r => r.Category == RoomCategory.Spotlight)));

AddStep("remove spotlight room", () => RoomManager.RemoveRoom(RoomManager.Rooms.Single(r => r.Category == RoomCategory.Spotlight)));
Expand Down Expand Up @@ -157,7 +155,7 @@ public void TestRulesetFiltering()
AddStep("add rooms", () => RoomManager.AddRooms(3, new CatchRuleset().RulesetInfo));

// Todo: What even is this case...?
AddStep("set empty filter criteria", () => container.Filter.Value = null);
AddStep("set empty filter criteria", () => container.Filter.Value = new FilterCriteria());
AddUntilStep("5 rooms visible", () => container.Rooms.Count(r => r.IsPresent) == 5);

AddStep("filter osu! rooms", () => container.Filter.Value = new FilterCriteria { Ruleset = new OsuRuleset().RulesetInfo });
Expand Down Expand Up @@ -195,9 +193,9 @@ public void TestPasswordProtectedRooms()
AddStep("add rooms", () => RoomManager.AddRooms(3, withPassword: true));
}

private bool checkRoomSelected(Room room) => SelectedRoom.Value == room;
private bool checkRoomSelected(Room? room) => SelectedRoom.Value == room;

private Room getRoomInFlow(int index) =>
private Room? getRoomInFlow(int index) =>
(container.ChildrenOfType<FillFlowContainer<DrawableLoungeRoom>>().First().FlowingChildren.ElementAt(index) as DrawableRoom)?.Room;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public override void SetUpSteps()

private void createNewItem()
{
SelectedRoom.Value.Playlist = SelectedRoom.Value.Playlist.Append(new PlaylistItem(new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo)
SelectedRoom.Value!.Playlist = SelectedRoom.Value.Playlist.Append(new PlaylistItem(new TestBeatmap(new OsuRuleset().RulesetInfo).BeatmapInfo)
{
ID = SelectedRoom.Value.Playlist.Count,
RulesetID = new OsuRuleset().RulesetInfo.OnlineID,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

#nullable disable

using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
Expand All @@ -18,8 +16,8 @@ namespace osu.Game.Tests.Visual.Multiplayer
{
public partial class TestSceneMultiSpectatorLeaderboard : MultiplayerTestScene
{
private Dictionary<int, ManualClock> clocks;
private MultiSpectatorLeaderboard leaderboard;
private Dictionary<int, ManualClock> clocks = null!;
private MultiSpectatorLeaderboard? leaderboard;

[SetUpSteps]
public override void SetUpSteps()
Expand Down Expand Up @@ -55,13 +53,13 @@ public override void SetUpSteps()
}, Add);
});

AddUntilStep("wait for load", () => leaderboard.IsLoaded);
AddUntilStep("wait for load", () => leaderboard!.IsLoaded);
AddUntilStep("wait for user population", () => leaderboard.ChildrenOfType<GameplayLeaderboardScore>().Count() == 2);

AddStep("add clock sources", () =>
{
foreach ((int userId, var clock) in clocks)
leaderboard.AddClock(userId, clock);
leaderboard!.AddClock(userId, clock);
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,7 +455,7 @@ private void loadSpectateScreen(bool waitForPlayerLoad = true, Action<WorkingBea

applyToBeatmap?.Invoke(Beatmap.Value);

LoadScreen(spectatorScreen = new MultiSpectatorScreen(SelectedRoom.Value, playingUsers.ToArray()));
LoadScreen(spectatorScreen = new MultiSpectatorScreen(SelectedRoom.Value!, playingUsers.ToArray()));
});

AddUntilStep("wait for screen load", () => spectatorScreen.LoadState == LoadState.Loaded && (!waitForPlayerLoad || spectatorScreen.AllPlayersLoaded));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ protected override MultiplayerGameplayLeaderboard CreateLeaderboard()
[Test]
public void TestPerUserMods()
{
AddStep("first user has no mods", () => Assert.That(((TestLeaderboard)Leaderboard).UserMods[0], Is.Empty));
AddStep("first user has no mods", () => Assert.That(((TestLeaderboard)Leaderboard!).UserMods[0], Is.Empty));
AddStep("last user has NF mod", () =>
{
Assert.That(((TestLeaderboard)Leaderboard).UserMods[TOTAL_USERS - 1], Has.One.Items);
Assert.That(((TestLeaderboard)Leaderboard!).UserMods[TOTAL_USERS - 1], Has.One.Items);
Assert.That(((TestLeaderboard)Leaderboard).UserMods[TOTAL_USERS - 1].Single(), Is.TypeOf<OsuModNoFail>());
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public override void SetUpSteps()
{
LoadComponentAsync(new MatchScoreDisplay
{
Team1Score = { BindTarget = Leaderboard.TeamScores[0] },
Team1Score = { BindTarget = Leaderboard!.TeamScores[0] },
Team2Score = { BindTarget = Leaderboard.TeamScores[1] }
}, Add);

Expand Down
Loading

0 comments on commit ce3d4e8

Please sign in to comment.