1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 20:07:29 +08:00

Clear rooms and poll only when connected to multiplayer server

This commit is contained in:
smoogipoo 2020-12-19 01:01:09 +09:00
parent cf2340cafb
commit a6520d3d44
2 changed files with 69 additions and 1 deletions

View File

@ -157,6 +157,12 @@ namespace osu.Game.Screens.Multi.Components
RoomsUpdated?.Invoke();
}
protected void ClearRooms()
{
rooms.Clear();
InitialRoomsReceived.Value = false;
}
/// <summary>
/// Updates a local <see cref="Room"/> with a remote copy.
/// </summary>

View File

@ -5,6 +5,7 @@ using System;
using System.Diagnostics;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Logging;
using osu.Game.Online.Multiplayer;
using osu.Game.Online.RealtimeMultiplayer;
@ -17,6 +18,22 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
[Resolved]
private StatefulMultiplayerClient multiplayerClient { get; set; }
public readonly Bindable<double> TimeBetweenListingPolls = new Bindable<double>();
public readonly Bindable<double> TimeBetweenSelectionPolls = new Bindable<double>();
private readonly IBindable<bool> isConnected = new Bindable<bool>();
protected override void LoadComplete()
{
base.LoadComplete();
isConnected.BindTo(multiplayerClient.IsConnected);
isConnected.BindValueChanged(connected => Schedule(() =>
{
if (!connected.NewValue)
ClearRooms();
}));
}
public override void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
=> base.CreateRoom(room, r => joinMultiplayerRoom(r, onSuccess), onError);
@ -39,7 +56,52 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
protected override RoomPollingComponent[] CreatePollingComponents() => new RoomPollingComponent[]
{
new ListingPollingComponent()
new RealtimeListingPollingComponent
{
TimeBetweenPolls = { BindTarget = TimeBetweenListingPolls },
AllowPolling = { BindTarget = isConnected }
},
new RealtimeSelectionPollingComponent
{
TimeBetweenPolls = { BindTarget = TimeBetweenSelectionPolls },
AllowPolling = { BindTarget = isConnected }
}
};
private class RealtimeListingPollingComponent : ListingPollingComponent
{
public readonly IBindable<bool> AllowPolling = new Bindable<bool>();
protected override void LoadComplete()
{
base.LoadComplete();
AllowPolling.BindValueChanged(_ =>
{
if (IsLoaded)
PollImmediately();
});
}
protected override Task Poll() => !AllowPolling.Value ? Task.CompletedTask : base.Poll();
}
private class RealtimeSelectionPollingComponent : SelectionPollingComponent
{
public readonly IBindable<bool> AllowPolling = new Bindable<bool>();
protected override void LoadComplete()
{
base.LoadComplete();
AllowPolling.BindValueChanged(_ =>
{
if (IsLoaded)
PollImmediately();
});
}
protected override Task Poll() => !AllowPolling.Value ? Task.CompletedTask : base.Poll();
}
}
}