From 2de0c34bc9fa10ed728a599ae563172348fa7bf2 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 Jan 2022 17:10:48 +0900 Subject: [PATCH 1/4] Reduce exposure of `ChannelManager` --- osu.Game/Online/Chat/StandAloneChatDisplay.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/osu.Game/Online/Chat/StandAloneChatDisplay.cs b/osu.Game/Online/Chat/StandAloneChatDisplay.cs index 81fd5ad98c..f83bf4877e 100644 --- a/osu.Game/Online/Chat/StandAloneChatDisplay.cs +++ b/osu.Game/Online/Chat/StandAloneChatDisplay.cs @@ -25,7 +25,7 @@ namespace osu.Game.Online.Chat protected readonly ChatTextBox TextBox; - protected ChannelManager ChannelManager; + private ChannelManager channelManager; private StandAloneDrawableChannel drawableChannel; @@ -80,7 +80,7 @@ namespace osu.Game.Online.Chat [BackgroundDependencyLoader(true)] private void load(ChannelManager manager) { - ChannelManager ??= manager; + channelManager ??= manager; } protected virtual StandAloneDrawableChannel CreateDrawableChannel(Channel channel) => @@ -94,9 +94,9 @@ namespace osu.Game.Online.Chat return; if (text[0] == '/') - ChannelManager?.PostCommand(text.Substring(1), Channel.Value); + channelManager?.PostCommand(text.Substring(1), Channel.Value); else - ChannelManager?.PostMessage(text, target: Channel.Value); + channelManager?.PostMessage(text, target: Channel.Value); TextBox.Text = string.Empty; } From 0bd34253e7a4614014c69f386acc5e89b38725b7 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 Jan 2022 17:31:49 +0900 Subject: [PATCH 2/4] Increase chat polling rate during multiplayer lobby / games --- osu.Game/OsuGame.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index c5a465ae96..21d84a365b 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -820,7 +820,17 @@ namespace osu.Game loadComponentSingleFile(CreateHighPerformanceSession(), Add); - chatOverlay.State.ValueChanged += state => channelManager.HighPollRate.Value = state.NewValue == Visibility.Visible; + chatOverlay.State.BindValueChanged(_ => updateChatPollRate()); + // Multiplayer modes need to increase poll rate temporarily. + API.Activity.BindValueChanged(_ => updateChatPollRate(), true); + + void updateChatPollRate() + { + channelManager.HighPollRate.Value = + chatOverlay.State.Value == Visibility.Visible + || API.Activity.Value is UserActivity.InLobby + || API.Activity.Value is UserActivity.InMultiplayerGame; + } Add(difficultyRecommender); Add(externalLinkOpener = new ExternalLinkOpener()); From 46d2f305b5967ec2098fe7305f8e65b9808c9e60 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 Jan 2022 17:31:55 +0900 Subject: [PATCH 3/4] Log chat polling rate changes --- osu.Game/Online/Chat/ChannelManager.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Online/Chat/ChannelManager.cs b/osu.Game/Online/Chat/ChannelManager.cs index 82e042ae4e..e5acda89f2 100644 --- a/osu.Game/Online/Chat/ChannelManager.cs +++ b/osu.Game/Online/Chat/ChannelManager.cs @@ -90,13 +90,14 @@ namespace osu.Game.Online.Chat { // Polling will eventually be replaced with websocket, but let's avoid doing these background operations as much as possible for now. // The only loss will be delayed PM/message highlight notifications. - if (HighPollRate.Value) TimeBetweenPolls.Value = 1000; else if (!isIdle.Value) TimeBetweenPolls.Value = 60000; else TimeBetweenPolls.Value = 600000; + + Logger.Log($"Chat is now polling every {TimeBetweenPolls.Value} ms"); } /// From 4012ef7e7b583bf5f245462fd94420266bdafc07 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 13 Jan 2022 17:33:55 +0900 Subject: [PATCH 4/4] Reduce polling rate when idle even if `HighPollRate` is requested --- osu.Game/Online/Chat/ChannelManager.cs | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/osu.Game/Online/Chat/ChannelManager.cs b/osu.Game/Online/Chat/ChannelManager.cs index e5acda89f2..77b52c34d9 100644 --- a/osu.Game/Online/Chat/ChannelManager.cs +++ b/osu.Game/Online/Chat/ChannelManager.cs @@ -90,14 +90,16 @@ namespace osu.Game.Online.Chat { // Polling will eventually be replaced with websocket, but let's avoid doing these background operations as much as possible for now. // The only loss will be delayed PM/message highlight notifications. - if (HighPollRate.Value) - TimeBetweenPolls.Value = 1000; - else if (!isIdle.Value) - TimeBetweenPolls.Value = 60000; - else - TimeBetweenPolls.Value = 600000; + int millisecondsBetweenPolls = HighPollRate.Value ? 1000 : 60000; - Logger.Log($"Chat is now polling every {TimeBetweenPolls.Value} ms"); + if (isIdle.Value) + millisecondsBetweenPolls *= 10; + + if (TimeBetweenPolls.Value != millisecondsBetweenPolls) + { + TimeBetweenPolls.Value = millisecondsBetweenPolls; + Logger.Log($"Chat is now polling every {TimeBetweenPolls.Value} ms"); + } } ///