From 81e2edc73ff95d47d272c711d1c7034829a68870 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Tue, 22 Dec 2020 14:59:11 +0900 Subject: [PATCH] Use MRE with timeout to wait on match start --- .../RealtimeMultiplayer/RealtimePlayer.cs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimePlayer.cs b/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimePlayer.cs index f4e84510bf..c6d44686b5 100644 --- a/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimePlayer.cs +++ b/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimePlayer.cs @@ -6,6 +6,8 @@ using System.Diagnostics; using System.Threading; using System.Threading.Tasks; using osu.Framework.Allocation; +using osu.Framework.Logging; +using osu.Framework.Screens; using osu.Game.Online.Multiplayer; using osu.Game.Online.RealtimeMultiplayer; using osu.Game.Scoring; @@ -26,7 +28,7 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer private StatefulMultiplayerClient client { get; set; } private readonly TaskCompletionSource resultsReady = new TaskCompletionSource(); - private bool started; + private readonly ManualResetEventSlim startedEvent = new ManualResetEventSlim(); public RealtimePlayer(PlaylistItem playlistItem) : base(playlistItem, false) @@ -43,11 +45,19 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer client.ResultsReady += onResultsReady; client.ChangeState(MultiplayerUserState.Loaded); - while (!started) - Thread.Sleep(100); + if (!startedEvent.Wait(TimeSpan.FromSeconds(30))) + { + Logger.Log("Failed to start the multiplayer match in time.", LoggingTarget.Runtime, LogLevel.Important); + + Schedule(() => + { + ValidForResume = false; + this.Exit(); + }); + } } - private void onMatchStarted() => started = true; + private void onMatchStarted() => startedEvent.Set(); private void onResultsReady() => resultsReady.SetResult(true);