mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 23:12:56 +08:00
Merge pull request #16253 from peppy/reduce-chat-overhead
Reduce overhead from chat polling when game is not active
This commit is contained in:
commit
cf864e58f7
@ -1,11 +1,13 @@
|
||||
// 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.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Platform;
|
||||
using osu.Game.Input.Bindings;
|
||||
|
||||
namespace osu.Game.Input
|
||||
@ -63,8 +65,17 @@ namespace osu.Game.Input
|
||||
|
||||
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e) => updateLastInteractionTime();
|
||||
|
||||
[Resolved]
|
||||
private GameHost host { get; set; }
|
||||
|
||||
protected override bool Handle(UIEvent e)
|
||||
{
|
||||
// Even when not active, `MouseMoveEvent`s will arrive.
|
||||
// We don't want these to trigger a non-idle state as it's quite often the user interacting
|
||||
// with other windows while osu! is in the background.
|
||||
if (!host.IsActive.Value)
|
||||
return base.Handle(e);
|
||||
|
||||
switch (e)
|
||||
{
|
||||
case KeyDownEvent _:
|
||||
|
@ -9,6 +9,7 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Database;
|
||||
using osu.Game.Input;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.API.Requests;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
@ -67,11 +68,34 @@ namespace osu.Game.Online.Chat
|
||||
|
||||
public readonly BindableBool HighPollRate = new BindableBool();
|
||||
|
||||
private readonly IBindable<bool> isIdle = new BindableBool();
|
||||
|
||||
public ChannelManager()
|
||||
{
|
||||
CurrentChannel.ValueChanged += currentChannelChanged;
|
||||
}
|
||||
|
||||
HighPollRate.BindValueChanged(enabled => TimeBetweenPolls.Value = enabled.NewValue ? 1000 : 6000, true);
|
||||
[BackgroundDependencyLoader(permitNulls: true)]
|
||||
private void load(IdleTracker idleTracker)
|
||||
{
|
||||
HighPollRate.BindValueChanged(updatePollRate);
|
||||
isIdle.BindValueChanged(updatePollRate, true);
|
||||
|
||||
if (idleTracker != null)
|
||||
isIdle.BindTo(idleTracker.IsIdle);
|
||||
}
|
||||
|
||||
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.
|
||||
|
||||
if (HighPollRate.Value)
|
||||
TimeBetweenPolls.Value = 1000;
|
||||
else if (!isIdle.Value)
|
||||
TimeBetweenPolls.Value = 60000;
|
||||
else
|
||||
TimeBetweenPolls.Value = 600000;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
Loading…
Reference in New Issue
Block a user