1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 08:12:56 +08:00

Fix multiplayer polling when not connected

This commit is contained in:
smoogipoo 2021-08-13 17:59:18 +09:00
parent 8910781bcd
commit 7cbf4c48ed
3 changed files with 34 additions and 40 deletions

View File

@ -44,8 +44,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
AutoSizeAxes = Axes.Both
};
protected ListingPollingComponent ListingPollingComponent { get; private set; }
[Resolved]
private Bindable<Room> selectedRoom { get; set; }
@ -73,6 +71,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
private RoomsContainer roomsContainer;
private SearchTextBox searchTextBox;
private Dropdown<RoomStatusFilter> statusDropdown;
private ListingPollingComponent listingPollingComponent;
[BackgroundDependencyLoader]
private void load()
@ -83,7 +82,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
InternalChildren = new Drawable[]
{
ListingPollingComponent = CreatePollingComponent(),
listingPollingComponent = CreatePollingComponent(),
new Container
{
RelativeSizeAxes = Axes.Both,
@ -183,7 +182,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
searchTextBox.Current.BindValueChanged(_ => updateFilterDebounced());
ruleset.BindValueChanged(_ => UpdateFilter());
ListingPollingComponent.HasPolledOnce.BindValueChanged(_ => updateLoadingLayer());
listingPollingComponent.HasPolledOnce.BindValueChanged(_ => updateLoadingLayer());
if (idleTracker != null)
{
@ -331,7 +330,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
private void updateLoadingLayer()
{
if (operationInProgress.Value || !ListingPollingComponent.HasPolledOnce.Value)
if (operationInProgress.Value || !listingPollingComponent.HasPolledOnce.Value)
loadingLayer.Show();
else
loadingLayer.Hide();
@ -340,11 +339,11 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
private void updatePollingRate()
{
if (!this.IsCurrentScreen())
ListingPollingComponent.TimeBetweenPolls.Value = 0;
listingPollingComponent.TimeBetweenPolls.Value = 0;
else
ListingPollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 120000 : 15000;
listingPollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 120000 : 15000;
Logger.Log($"Polling adjusted (listing: {ListingPollingComponent.TimeBetweenPolls.Value})");
Logger.Log($"Polling adjusted (listing: {listingPollingComponent.TimeBetweenPolls.Value})");
}
protected abstract OsuButton CreateNewRoomButton();

View File

@ -25,10 +25,23 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
[Resolved]
private MultiplayerClient client { get; set; }
private MultiplayerListingPollingComponent listingPollingComponent;
private readonly IBindable<bool> isConnected = new Bindable<bool>();
private readonly Bindable<bool> allowPolling = new Bindable<bool>();
protected override void LoadComplete()
{
base.LoadComplete();
isConnected.BindTo(client.IsConnected);
isConnected.BindValueChanged(c => Scheduler.AddOnce(() => listingPollingComponent.AllowPolling = c.NewValue));
}
public override void OnResuming(IScreen last)
{
base.OnResuming(last);
ListingPollingComponent.PollImmediately();
listingPollingComponent.PollImmediately();
}
protected override FilterCriteria CreateFilterCriteria()
@ -49,7 +62,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
protected override RoomSubScreen CreateRoomSubScreen(Room room) => new MultiplayerMatchSubScreen(room);
protected override ListingPollingComponent CreatePollingComponent() => new MultiplayerListingPollingComponent();
protected override ListingPollingComponent CreatePollingComponent() => listingPollingComponent = new MultiplayerListingPollingComponent();
protected override void OpenNewRoom(Room room)
{
@ -64,23 +77,27 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
private class MultiplayerListingPollingComponent : ListingPollingComponent
{
public readonly IBindable<bool> AllowPolling = new Bindable<bool>();
private bool allowPolling;
protected override void LoadComplete()
public bool AllowPolling
{
base.LoadComplete();
AllowPolling.BindValueChanged(allowPolling =>
get => allowPolling;
set
{
if (!allowPolling.NewValue)
if (allowPolling == value)
return;
allowPolling = value;
if (!allowPolling)
return;
if (IsLoaded)
PollImmediately();
});
}
}
protected override Task Poll() => !AllowPolling.Value ? Task.CompletedTask : base.Poll();
protected override Task Poll() => !AllowPolling ? Task.CompletedTask : base.Poll();
}
}
}

View File

@ -4,7 +4,6 @@
using System;
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.ExceptionExtensions;
using osu.Framework.Logging;
using osu.Game.Online.Multiplayer;
@ -19,18 +18,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
[Resolved]
private MultiplayerClient multiplayerClient { get; set; }
private readonly IBindable<bool> isConnected = new Bindable<bool>();
private readonly Bindable<bool> allowPolling = new Bindable<bool>();
protected override void LoadComplete()
{
base.LoadComplete();
isConnected.BindTo(multiplayerClient.IsConnected);
isConnected.BindValueChanged(_ => Scheduler.AddOnce(updatePolling));
JoinedRoom.BindValueChanged(_ => Scheduler.AddOnce(updatePolling), true);
}
public override void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
=> base.CreateRoom(room, r => joinMultiplayerRoom(r, r.Password.Value, onSuccess, onError), onError);
@ -82,14 +69,5 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
}
});
}
private void updatePolling()
{
if (!isConnected.Value)
ClearRooms();
// Don't poll when not connected or when a room has been joined.
allowPolling.Value = isConnected.Value && JoinedRoom.Value == null;
}
}
}