mirror of
https://github.com/ppy/osu.git
synced 2024-11-11 20:47:51 +08:00
Make real time room manager not poll while inside a room
This commit is contained in:
parent
2fc5561b7e
commit
9b0ca8fc3b
@ -27,6 +27,8 @@ namespace osu.Game.Screens.Multi.Components
|
||||
|
||||
public IBindableList<Room> Rooms => rooms;
|
||||
|
||||
protected Room JoinedRoom { get; private set; }
|
||||
|
||||
[Resolved]
|
||||
private RulesetStore rulesets { get; set; }
|
||||
|
||||
@ -36,8 +38,6 @@ namespace osu.Game.Screens.Multi.Components
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
private Room joinedRoom;
|
||||
|
||||
protected RoomManager()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
@ -64,7 +64,7 @@ namespace osu.Game.Screens.Multi.Components
|
||||
|
||||
req.Success += result =>
|
||||
{
|
||||
joinedRoom = room;
|
||||
JoinedRoom = room;
|
||||
|
||||
update(room, result);
|
||||
addRoom(room);
|
||||
@ -93,7 +93,7 @@ namespace osu.Game.Screens.Multi.Components
|
||||
|
||||
currentJoinRoomRequest.Success += () =>
|
||||
{
|
||||
joinedRoom = room;
|
||||
JoinedRoom = room;
|
||||
onSuccess?.Invoke(room);
|
||||
};
|
||||
|
||||
@ -111,11 +111,11 @@ namespace osu.Game.Screens.Multi.Components
|
||||
{
|
||||
currentJoinRoomRequest?.Cancel();
|
||||
|
||||
if (joinedRoom == null)
|
||||
if (JoinedRoom == null)
|
||||
return;
|
||||
|
||||
api.Queue(new PartRoomRequest(joinedRoom));
|
||||
joinedRoom = null;
|
||||
api.Queue(new PartRoomRequest(JoinedRoom));
|
||||
JoinedRoom = null;
|
||||
}
|
||||
|
||||
private readonly HashSet<int> ignoredRooms = new HashSet<int>();
|
||||
|
@ -21,17 +21,16 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
|
||||
public readonly Bindable<double> TimeBetweenListingPolls = new Bindable<double>();
|
||||
public readonly Bindable<double> TimeBetweenSelectionPolls = new Bindable<double>();
|
||||
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(connected => Schedule(() =>
|
||||
{
|
||||
if (!connected.NewValue)
|
||||
ClearRooms();
|
||||
}));
|
||||
isConnected.BindValueChanged(_ => Schedule(updatePolling), true);
|
||||
|
||||
updatePolling();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
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[]
|
||||
{
|
||||
new RealtimeListingPollingComponent
|
||||
{
|
||||
TimeBetweenPolls = { BindTarget = TimeBetweenListingPolls },
|
||||
AllowPolling = { BindTarget = isConnected }
|
||||
AllowPolling = { BindTarget = allowPolling }
|
||||
},
|
||||
new RealtimeSelectionPollingComponent
|
||||
{
|
||||
TimeBetweenPolls = { BindTarget = TimeBetweenSelectionPolls },
|
||||
AllowPolling = { BindTarget = isConnected }
|
||||
AllowPolling = { BindTarget = allowPolling }
|
||||
}
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user