Merge pull request #16442 from peppy/fix-multiplayer-chat-polling

Fix chat poll rate being too low in multiplayer lobby and gameplay
This commit is contained in:
Dan Balasescu 2022-01-14 13:52:37 +09:00 committed by GitHub
commit 70f56cd0c9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 11 deletions

View File

@ -90,13 +90,16 @@ private void updatePollRate(ValueChangedEvent<bool> valueChangedEvent)
{
// 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.
int millisecondsBetweenPolls = HighPollRate.Value ? 1000 : 60000;
if (HighPollRate.Value)
TimeBetweenPolls.Value = 1000;
else if (!isIdle.Value)
TimeBetweenPolls.Value = 60000;
else
TimeBetweenPolls.Value = 600000;
if (isIdle.Value)
millisecondsBetweenPolls *= 10;
if (TimeBetweenPolls.Value != millisecondsBetweenPolls)
{
TimeBetweenPolls.Value = millisecondsBetweenPolls;
Logger.Log($"Chat is now polling every {TimeBetweenPolls.Value} ms");
}
}
/// <summary>

View File

@ -25,7 +25,7 @@ public class StandAloneChatDisplay : CompositeDrawable
protected readonly ChatTextBox TextBox;
protected ChannelManager ChannelManager;
private ChannelManager channelManager;
private StandAloneDrawableChannel drawableChannel;
@ -80,7 +80,7 @@ public StandAloneChatDisplay(bool postingTextBox = false)
[BackgroundDependencyLoader(true)]
private void load(ChannelManager manager)
{
ChannelManager ??= manager;
channelManager ??= manager;
}
protected virtual StandAloneDrawableChannel CreateDrawableChannel(Channel channel) =>
@ -94,9 +94,9 @@ private void postMessage(TextBox sender, bool newText)
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;
}

View File

@ -820,7 +820,17 @@ protected override void LoadComplete()
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());