mirror of
https://github.com/ppy/osu.git
synced 2025-01-30 01:32:55 +08:00
Merge pull request #14474 from smoogipoo/fix-multi-crash
Fix crash when entering multiplayer gameplay
This commit is contained in:
commit
08f757a584
@ -9,6 +9,8 @@ namespace osu.Game.Tests.Resources
|
|||||||
{
|
{
|
||||||
public static class TestResources
|
public static class TestResources
|
||||||
{
|
{
|
||||||
|
public const double QUICK_BEATMAP_LENGTH = 10000;
|
||||||
|
|
||||||
public static DllResourceStore GetStore() => new DllResourceStore(typeof(TestResources).Assembly);
|
public static DllResourceStore GetStore() => new DllResourceStore(typeof(TestResources).Assembly);
|
||||||
|
|
||||||
public static Stream OpenResource(string name) => GetStore().GetStream($"Resources/{name}");
|
public static Stream OpenResource(string name) => GetStore().GetStream($"Resources/{name}");
|
||||||
|
@ -39,7 +39,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
{
|
{
|
||||||
base.SetUpSteps();
|
base.SetUpSteps();
|
||||||
|
|
||||||
AddStep("load chat display", () => Child = chatDisplay = new GameplayChatDisplay
|
AddStep("load chat display", () => Child = chatDisplay = new GameplayChatDisplay(SelectedRoom.Value)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
|
@ -28,6 +28,8 @@ using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
|||||||
using osu.Game.Screens.OnlinePlay.Match;
|
using osu.Game.Screens.OnlinePlay.Match;
|
||||||
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
using osu.Game.Screens.OnlinePlay.Multiplayer;
|
||||||
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
using osu.Game.Screens.OnlinePlay.Multiplayer.Match;
|
||||||
|
using osu.Game.Screens.Play;
|
||||||
|
using osu.Game.Screens.Ranking;
|
||||||
using osu.Game.Tests.Resources;
|
using osu.Game.Tests.Resources;
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using osuTK.Input;
|
using osuTK.Input;
|
||||||
@ -430,6 +432,40 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestGameplayFlow()
|
||||||
|
{
|
||||||
|
createRoom(() => new Room
|
||||||
|
{
|
||||||
|
Name = { Value = "Test Room" },
|
||||||
|
Playlist =
|
||||||
|
{
|
||||||
|
new PlaylistItem
|
||||||
|
{
|
||||||
|
Beatmap = { Value = beatmaps.GetWorkingBeatmap(importedSet.Beatmaps.First(b => b.RulesetID == 0)).BeatmapInfo },
|
||||||
|
Ruleset = { Value = new OsuRuleset().RulesetInfo },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
AddRepeatStep("click spectate button", () =>
|
||||||
|
{
|
||||||
|
InputManager.MoveMouseTo(this.ChildrenOfType<MultiplayerReadyButton>().Single());
|
||||||
|
InputManager.Click(MouseButton.Left);
|
||||||
|
}, 2);
|
||||||
|
|
||||||
|
AddUntilStep("wait for player", () => Stack.CurrentScreen is Player);
|
||||||
|
|
||||||
|
// Gameplay runs in real-time, so we need to incrementally check if gameplay has finished in order to not time out.
|
||||||
|
for (double i = 1000; i < TestResources.QUICK_BEATMAP_LENGTH; i += 1000)
|
||||||
|
{
|
||||||
|
var time = i;
|
||||||
|
AddUntilStep($"wait for time > {i}", () => this.ChildrenOfType<GameplayClockContainer>().SingleOrDefault()?.GameplayClock.CurrentTime > time);
|
||||||
|
}
|
||||||
|
|
||||||
|
AddUntilStep("wait for results", () => Stack.CurrentScreen is ResultsScreen);
|
||||||
|
}
|
||||||
|
|
||||||
private void createRoom(Func<Room> room)
|
private void createRoom(Func<Room> room)
|
||||||
{
|
{
|
||||||
AddUntilStep("wait for lounge", () => multiplayerScreen.ChildrenOfType<LoungeSubScreen>().SingleOrDefault()?.IsLoaded == true);
|
AddUntilStep("wait for lounge", () => multiplayerScreen.ChildrenOfType<LoungeSubScreen>().SingleOrDefault()?.IsLoaded == true);
|
||||||
|
@ -25,7 +25,7 @@ namespace osu.Game.Tests.Visual.Multiplayer
|
|||||||
|
|
||||||
AddStep("initialise gameplay", () =>
|
AddStep("initialise gameplay", () =>
|
||||||
{
|
{
|
||||||
Stack.Push(player = new MultiplayerPlayer(Client.CurrentMatchPlayingItem.Value, Client.Room?.Users.ToArray()));
|
Stack.Push(player = new MultiplayerPlayer(Client.APIRoom, Client.CurrentMatchPlayingItem.Value, Client.Room?.Users.ToArray()));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,20 +10,18 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
|||||||
{
|
{
|
||||||
public class MatchChatDisplay : StandAloneChatDisplay
|
public class MatchChatDisplay : StandAloneChatDisplay
|
||||||
{
|
{
|
||||||
[Resolved(typeof(Room), nameof(Room.RoomID))]
|
private readonly IBindable<int> channelId = new Bindable<int>();
|
||||||
private Bindable<long?> roomId { get; set; }
|
|
||||||
|
|
||||||
[Resolved(typeof(Room), nameof(Room.ChannelId))]
|
|
||||||
private Bindable<int> channelId { get; set; }
|
|
||||||
|
|
||||||
[Resolved(CanBeNull = true)]
|
[Resolved(CanBeNull = true)]
|
||||||
private ChannelManager channelManager { get; set; }
|
private ChannelManager channelManager { get; set; }
|
||||||
|
|
||||||
|
private readonly Room room;
|
||||||
private readonly bool leaveChannelOnDispose;
|
private readonly bool leaveChannelOnDispose;
|
||||||
|
|
||||||
public MatchChatDisplay(bool leaveChannelOnDispose = true)
|
public MatchChatDisplay(Room room, bool leaveChannelOnDispose = true)
|
||||||
: base(true)
|
: base(true)
|
||||||
{
|
{
|
||||||
|
this.room = room;
|
||||||
this.leaveChannelOnDispose = leaveChannelOnDispose;
|
this.leaveChannelOnDispose = leaveChannelOnDispose;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -31,15 +29,17 @@ namespace osu.Game.Screens.OnlinePlay.Match.Components
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
|
// Required for the time being since this component is created prior to the room being joined.
|
||||||
|
channelId.BindTo(room.ChannelId);
|
||||||
channelId.BindValueChanged(_ => updateChannel(), true);
|
channelId.BindValueChanged(_ => updateChannel(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateChannel()
|
private void updateChannel()
|
||||||
{
|
{
|
||||||
if (roomId.Value == null || channelId.Value == 0)
|
if (room.RoomID.Value == null || channelId.Value == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Channel.Value = channelManager?.JoinChannel(new Channel { Id = channelId.Value, Type = ChannelType.Multiplayer, Name = $"#lazermp_{roomId.Value}" });
|
Channel.Value = channelManager?.JoinChannel(new Channel { Id = channelId.Value, Type = ChannelType.Multiplayer, Name = $"#lazermp_{room.RoomID.Value}" });
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
@ -7,6 +7,7 @@ using osu.Framework.Graphics;
|
|||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Input.Bindings;
|
using osu.Game.Input.Bindings;
|
||||||
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Screens.OnlinePlay.Match.Components;
|
using osu.Game.Screens.OnlinePlay.Match.Components;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
|
|
||||||
@ -29,8 +30,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
|
|
||||||
public override bool PropagateNonPositionalInputSubTree => true;
|
public override bool PropagateNonPositionalInputSubTree => true;
|
||||||
|
|
||||||
public GameplayChatDisplay()
|
public GameplayChatDisplay(Room room)
|
||||||
: base(leaveChannelOnDispose: false)
|
: base(room, leaveChannelOnDispose: false)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
|
|
||||||
|
@ -173,7 +173,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
new Drawable[] { new OverlinedHeader("Chat") { Margin = new MarginPadding { Vertical = 5 }, }, },
|
new Drawable[] { new OverlinedHeader("Chat") { Margin = new MarginPadding { Vertical = 5 }, }, },
|
||||||
new Drawable[] { new MatchChatDisplay { RelativeSizeAxes = Axes.Both } }
|
new Drawable[] { new MatchChatDisplay(Room) { RelativeSizeAxes = Axes.Both } }
|
||||||
},
|
},
|
||||||
RowDimensions = new[]
|
RowDimensions = new[]
|
||||||
{
|
{
|
||||||
@ -395,7 +395,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
return new MultiSpectatorScreen(users.Take(PlayerGrid.MAX_PLAYERS).ToArray());
|
return new MultiSpectatorScreen(users.Take(PlayerGrid.MAX_PLAYERS).ToArray());
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return new PlayerLoader(() => new MultiplayerPlayer(SelectedItem.Value, users));
|
return new PlayerLoader(() => new MultiplayerPlayer(Room, SelectedItem.Value, users));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,10 +45,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Construct a multiplayer player.
|
/// Construct a multiplayer player.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
/// <param name="room">The room.</param>
|
||||||
/// <param name="playlistItem">The playlist item to be played.</param>
|
/// <param name="playlistItem">The playlist item to be played.</param>
|
||||||
/// <param name="users">The users which are participating in this game.</param>
|
/// <param name="users">The users which are participating in this game.</param>
|
||||||
public MultiplayerPlayer(PlaylistItem playlistItem, MultiplayerRoomUser[] users)
|
public MultiplayerPlayer(Room room, PlaylistItem playlistItem, MultiplayerRoomUser[] users)
|
||||||
: base(playlistItem, new PlayerConfiguration
|
: base(room, playlistItem, new PlayerConfiguration
|
||||||
{
|
{
|
||||||
AllowPause = false,
|
AllowPause = false,
|
||||||
AllowRestart = false,
|
AllowRestart = false,
|
||||||
@ -92,7 +93,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
LoadComponentAsync(new GameplayChatDisplay
|
LoadComponentAsync(new GameplayChatDisplay(Room)
|
||||||
{
|
{
|
||||||
Expanded = { BindTarget = HUDOverlay.ShowHud },
|
Expanded = { BindTarget = HUDOverlay.ShowHud },
|
||||||
}, chat => leaderboardFlow.Insert(2, chat));
|
}, chat => leaderboardFlow.Insert(2, chat));
|
||||||
@ -186,10 +187,11 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
|||||||
|
|
||||||
protected override ResultsScreen CreateResults(ScoreInfo score)
|
protected override ResultsScreen CreateResults(ScoreInfo score)
|
||||||
{
|
{
|
||||||
Debug.Assert(RoomId.Value != null);
|
Debug.Assert(Room.RoomID.Value != null);
|
||||||
|
|
||||||
return leaderboard.TeamScores.Count == 2
|
return leaderboard.TeamScores.Count == 2
|
||||||
? new MultiplayerTeamResultsScreen(score, RoomId.Value.Value, PlaylistItem, leaderboard.TeamScores)
|
? new MultiplayerTeamResultsScreen(score, Room.RoomID.Value.Value, PlaylistItem, leaderboard.TeamScores)
|
||||||
: new MultiplayerResultsScreen(score, RoomId.Value.Value, PlaylistItem);
|
: new MultiplayerResultsScreen(score, Room.RoomID.Value.Value, PlaylistItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
|
@ -20,8 +20,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
{
|
{
|
||||||
public Action Exited;
|
public Action Exited;
|
||||||
|
|
||||||
public PlaylistsPlayer(PlaylistItem playlistItem, PlayerConfiguration configuration = null)
|
public PlaylistsPlayer(Room room, PlaylistItem playlistItem, PlayerConfiguration configuration = null)
|
||||||
: base(playlistItem, configuration)
|
: base(room, playlistItem, configuration)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,8 +51,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
|
|
||||||
protected override ResultsScreen CreateResults(ScoreInfo score)
|
protected override ResultsScreen CreateResults(ScoreInfo score)
|
||||||
{
|
{
|
||||||
Debug.Assert(RoomId.Value != null);
|
Debug.Assert(Room.RoomID.Value != null);
|
||||||
return new PlaylistsResultsScreen(score, RoomId.Value.Value, PlaylistItem, true);
|
return new PlaylistsResultsScreen(score, Room.RoomID.Value.Value, PlaylistItem, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task PrepareScoreForResultsAsync(Score score)
|
protected override async Task PrepareScoreForResultsAsync(Score score)
|
||||||
|
@ -158,7 +158,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
},
|
},
|
||||||
new Drawable[] { leaderboard = new MatchLeaderboard { RelativeSizeAxes = Axes.Both }, },
|
new Drawable[] { leaderboard = new MatchLeaderboard { RelativeSizeAxes = Axes.Both }, },
|
||||||
new Drawable[] { new OverlinedHeader("Chat"), },
|
new Drawable[] { new OverlinedHeader("Chat"), },
|
||||||
new Drawable[] { new MatchChatDisplay { RelativeSizeAxes = Axes.Both } }
|
new Drawable[] { new MatchChatDisplay(Room) { RelativeSizeAxes = Axes.Both } }
|
||||||
},
|
},
|
||||||
RowDimensions = new[]
|
RowDimensions = new[]
|
||||||
{
|
{
|
||||||
@ -199,7 +199,7 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
|||||||
Logger.Log($"Polling adjusted (selection: {selectionPollingComponent.TimeBetweenPolls.Value})");
|
Logger.Log($"Polling adjusted (selection: {selectionPollingComponent.TimeBetweenPolls.Value})");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Screen CreateGameplayScreen() => new PlayerLoader(() => new PlaylistsPlayer(SelectedItem.Value)
|
protected override Screen CreateGameplayScreen() => new PlayerLoader(() => new PlaylistsPlayer(Room, SelectedItem.Value)
|
||||||
{
|
{
|
||||||
Exited = () => leaderboard.RefreshScores()
|
Exited = () => leaderboard.RefreshScores()
|
||||||
});
|
});
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using osu.Framework.Allocation;
|
using System.Diagnostics;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Game.Online.API;
|
using osu.Game.Online.API;
|
||||||
using osu.Game.Online.Rooms;
|
using osu.Game.Online.Rooms;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
@ -14,25 +13,28 @@ namespace osu.Game.Screens.Play
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class RoomSubmittingPlayer : SubmittingPlayer
|
public abstract class RoomSubmittingPlayer : SubmittingPlayer
|
||||||
{
|
{
|
||||||
[Resolved(typeof(Room), nameof(Room.RoomID))]
|
|
||||||
protected Bindable<long?> RoomId { get; private set; }
|
|
||||||
|
|
||||||
protected readonly PlaylistItem PlaylistItem;
|
protected readonly PlaylistItem PlaylistItem;
|
||||||
|
protected readonly Room Room;
|
||||||
|
|
||||||
protected RoomSubmittingPlayer(PlaylistItem playlistItem, PlayerConfiguration configuration = null)
|
protected RoomSubmittingPlayer(Room room, PlaylistItem playlistItem, PlayerConfiguration configuration = null)
|
||||||
: base(configuration)
|
: base(configuration)
|
||||||
{
|
{
|
||||||
|
Room = room;
|
||||||
PlaylistItem = playlistItem;
|
PlaylistItem = playlistItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override APIRequest<APIScoreToken> CreateTokenRequest()
|
protected override APIRequest<APIScoreToken> CreateTokenRequest()
|
||||||
{
|
{
|
||||||
if (!(RoomId.Value is long roomId))
|
if (!(Room.RoomID.Value is long roomId))
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return new CreateRoomScoreRequest(roomId, PlaylistItem.ID, Game.VersionHash);
|
return new CreateRoomScoreRequest(roomId, PlaylistItem.ID, Game.VersionHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override APIRequest<MultiplayerScore> CreateSubmissionRequest(Score score, long token) => new SubmitRoomScoreRequest(token, RoomId.Value ?? 0, PlaylistItem.ID, score.ScoreInfo);
|
protected override APIRequest<MultiplayerScore> CreateSubmissionRequest(Score score, long token)
|
||||||
|
{
|
||||||
|
Debug.Assert(Room.RoomID.Value != null);
|
||||||
|
return new SubmitRoomScoreRequest(token, Room.RoomID.Value.Value, PlaylistItem.ID, score.ScoreInfo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user