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

Make real time room manager not poll while inside a room

This commit is contained in:
smoogipoo 2020-12-19 01:57:30 +09:00
parent 2fc5561b7e
commit 9b0ca8fc3b
2 changed files with 22 additions and 14 deletions

View File

@ -27,6 +27,8 @@ namespace osu.Game.Screens.Multi.Components
public IBindableList<Room> Rooms => rooms; public IBindableList<Room> Rooms => rooms;
protected Room JoinedRoom { get; private set; }
[Resolved] [Resolved]
private RulesetStore rulesets { get; set; } private RulesetStore rulesets { get; set; }
@ -36,8 +38,6 @@ namespace osu.Game.Screens.Multi.Components
[Resolved] [Resolved]
private IAPIProvider api { get; set; } private IAPIProvider api { get; set; }
private Room joinedRoom;
protected RoomManager() protected RoomManager()
{ {
RelativeSizeAxes = Axes.Both; RelativeSizeAxes = Axes.Both;
@ -64,7 +64,7 @@ namespace osu.Game.Screens.Multi.Components
req.Success += result => req.Success += result =>
{ {
joinedRoom = room; JoinedRoom = room;
update(room, result); update(room, result);
addRoom(room); addRoom(room);
@ -93,7 +93,7 @@ namespace osu.Game.Screens.Multi.Components
currentJoinRoomRequest.Success += () => currentJoinRoomRequest.Success += () =>
{ {
joinedRoom = room; JoinedRoom = room;
onSuccess?.Invoke(room); onSuccess?.Invoke(room);
}; };
@ -111,11 +111,11 @@ namespace osu.Game.Screens.Multi.Components
{ {
currentJoinRoomRequest?.Cancel(); currentJoinRoomRequest?.Cancel();
if (joinedRoom == null) if (JoinedRoom == null)
return; return;
api.Queue(new PartRoomRequest(joinedRoom)); api.Queue(new PartRoomRequest(JoinedRoom));
joinedRoom = null; JoinedRoom = null;
} }
private readonly HashSet<int> ignoredRooms = new HashSet<int>(); private readonly HashSet<int> ignoredRooms = new HashSet<int>();

View File

@ -21,17 +21,16 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
public readonly Bindable<double> TimeBetweenListingPolls = new Bindable<double>(); public readonly Bindable<double> TimeBetweenListingPolls = new Bindable<double>();
public readonly Bindable<double> TimeBetweenSelectionPolls = new Bindable<double>(); public readonly Bindable<double> TimeBetweenSelectionPolls = new Bindable<double>();
private readonly IBindable<bool> isConnected = new Bindable<bool>(); private readonly IBindable<bool> isConnected = new Bindable<bool>();
private readonly Bindable<bool> allowPolling = new Bindable<bool>();
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();
isConnected.BindTo(multiplayerClient.IsConnected); isConnected.BindTo(multiplayerClient.IsConnected);
isConnected.BindValueChanged(connected => Schedule(() => isConnected.BindValueChanged(_ => Schedule(updatePolling), true);
{
if (!connected.NewValue) updatePolling();
ClearRooms();
}));
} }
public override void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null) public override void CreateRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
@ -54,17 +53,26 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
}, TaskContinuationOptions.NotOnRanToCompletion); }, TaskContinuationOptions.NotOnRanToCompletion);
} }
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 == null;
}
protected override RoomPollingComponent[] CreatePollingComponents() => new RoomPollingComponent[] protected override RoomPollingComponent[] CreatePollingComponents() => new RoomPollingComponent[]
{ {
new RealtimeListingPollingComponent new RealtimeListingPollingComponent
{ {
TimeBetweenPolls = { BindTarget = TimeBetweenListingPolls }, TimeBetweenPolls = { BindTarget = TimeBetweenListingPolls },
AllowPolling = { BindTarget = isConnected } AllowPolling = { BindTarget = allowPolling }
}, },
new RealtimeSelectionPollingComponent new RealtimeSelectionPollingComponent
{ {
TimeBetweenPolls = { BindTarget = TimeBetweenSelectionPolls }, TimeBetweenPolls = { BindTarget = TimeBetweenSelectionPolls },
AllowPolling = { BindTarget = isConnected } AllowPolling = { BindTarget = allowPolling }
} }
}; };