mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 15:44:04 +09:00
Move listing polling component to LoungeSubScreen
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
// 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 System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -14,6 +15,9 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
/// </summary>
|
||||
public class ListingPollingComponent : RoomPollingComponent
|
||||
{
|
||||
public IBindable<bool> HasPolledOnce => hasPolledOnce;
|
||||
private readonly Bindable<bool> hasPolledOnce = new Bindable<bool>();
|
||||
|
||||
[Resolved]
|
||||
private Bindable<FilterCriteria> currentFilter { get; set; }
|
||||
|
||||
@ -25,7 +29,9 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
{
|
||||
currentFilter.BindValueChanged(_ =>
|
||||
{
|
||||
NotifyRoomsReceived(null);
|
||||
RoomManager.ClearRooms();
|
||||
hasPolledOnce.Value = false;
|
||||
|
||||
if (IsLoaded)
|
||||
PollImmediately();
|
||||
});
|
||||
@ -45,17 +51,16 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
|
||||
pollReq.Success += result =>
|
||||
{
|
||||
for (int i = 0; i < result.Count; i++)
|
||||
foreach (var existing in RoomManager.Rooms.ToArray())
|
||||
{
|
||||
if (result[i].RoomID.Value == selectedRoom.Value?.RoomID.Value)
|
||||
{
|
||||
// The listing request always has less information than the opened room, so don't include it.
|
||||
result[i] = selectedRoom.Value;
|
||||
break;
|
||||
}
|
||||
if (result.All(r => r.RoomID.Value != existing.RoomID.Value))
|
||||
RoomManager.RemoveRoom(existing);
|
||||
}
|
||||
|
||||
NotifyRoomsReceived(result);
|
||||
foreach (var incoming in result)
|
||||
RoomManager.AddOrUpdateRoom(incoming);
|
||||
|
||||
hasPolledOnce.Value = true;
|
||||
tcs.SetResult(true);
|
||||
};
|
||||
|
||||
|
@ -8,7 +8,6 @@ using System.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
@ -17,15 +16,12 @@ using osu.Game.Rulesets;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Components
|
||||
{
|
||||
public abstract class RoomManager : CompositeDrawable, IRoomManager
|
||||
public class RoomManager : Component, IRoomManager
|
||||
{
|
||||
public event Action RoomsUpdated;
|
||||
|
||||
private readonly BindableList<Room> rooms = new BindableList<Room>();
|
||||
|
||||
public IBindable<bool> InitialRoomsReceived => initialRoomsReceived;
|
||||
private readonly Bindable<bool> initialRoomsReceived = new Bindable<bool>();
|
||||
|
||||
public IBindableList<Room> Rooms => rooms;
|
||||
|
||||
protected IBindable<Room> JoinedRoom => joinedRoom;
|
||||
@ -40,15 +36,9 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
protected RoomManager()
|
||||
public RoomManager()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
|
||||
InternalChildren = CreatePollingComponents().Select(p =>
|
||||
{
|
||||
p.RoomsReceived = onRoomsReceived;
|
||||
return p;
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
@ -118,56 +108,41 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
|
||||
private readonly HashSet<long> ignoredRooms = new HashSet<long>();
|
||||
|
||||
private void onRoomsReceived(List<Room> received)
|
||||
public void AddOrUpdateRoom(Room room)
|
||||
{
|
||||
if (received == null)
|
||||
{
|
||||
ClearRooms();
|
||||
Debug.Assert(room.RoomID.Value != null);
|
||||
|
||||
if (ignoredRooms.Contains(room.RoomID.Value.Value))
|
||||
return;
|
||||
}
|
||||
|
||||
// Remove past matches
|
||||
foreach (var r in rooms.ToList())
|
||||
room.Position.Value = -room.RoomID.Value.Value;
|
||||
|
||||
try
|
||||
{
|
||||
if (received.All(e => e.RoomID.Value != r.RoomID.Value))
|
||||
rooms.Remove(r);
|
||||
update(room, room);
|
||||
addRoom(room);
|
||||
}
|
||||
|
||||
for (int i = 0; i < received.Count; i++)
|
||||
catch (Exception ex)
|
||||
{
|
||||
var room = received[i];
|
||||
Logger.Error(ex, $"Failed to update room: {room.Name.Value}.");
|
||||
|
||||
Debug.Assert(room.RoomID.Value != null);
|
||||
|
||||
if (ignoredRooms.Contains(room.RoomID.Value.Value))
|
||||
continue;
|
||||
|
||||
room.Position.Value = i;
|
||||
|
||||
try
|
||||
{
|
||||
update(room, room);
|
||||
addRoom(room);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Error(ex, $"Failed to update room: {room.Name.Value}.");
|
||||
|
||||
ignoredRooms.Add(room.RoomID.Value.Value);
|
||||
rooms.Remove(room);
|
||||
}
|
||||
ignoredRooms.Add(room.RoomID.Value.Value);
|
||||
rooms.Remove(room);
|
||||
}
|
||||
|
||||
RoomsUpdated?.Invoke();
|
||||
initialRoomsReceived.Value = true;
|
||||
notifyRoomsUpdated();
|
||||
}
|
||||
|
||||
protected void RemoveRoom(Room room) => rooms.Remove(room);
|
||||
public void RemoveRoom(Room room)
|
||||
{
|
||||
rooms.Remove(room);
|
||||
notifyRoomsUpdated();
|
||||
}
|
||||
|
||||
protected void ClearRooms()
|
||||
public void ClearRooms()
|
||||
{
|
||||
rooms.Clear();
|
||||
initialRoomsReceived.Value = false;
|
||||
notifyRoomsUpdated();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -196,6 +171,6 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
existing.CopyFrom(room);
|
||||
}
|
||||
|
||||
protected abstract IEnumerable<RoomPollingComponent> CreatePollingComponents();
|
||||
private void notifyRoomsUpdated() => Scheduler.AddOnce(() => RoomsUpdated?.Invoke());
|
||||
}
|
||||
}
|
||||
|
@ -1,29 +1,18 @@
|
||||
// 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 System;
|
||||
using System.Collections.Generic;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Online;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Components
|
||||
{
|
||||
public abstract class RoomPollingComponent : PollingComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Invoked when any <see cref="Room"/>s have been received from the API.
|
||||
/// <para>
|
||||
/// Any <see cref="Room"/>s present locally but not returned by this event are to be removed from display.
|
||||
/// If null, the display of local rooms is reset to an initial state.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
public Action<List<Room>> RoomsReceived;
|
||||
|
||||
[Resolved]
|
||||
protected IAPIProvider API { get; private set; }
|
||||
|
||||
protected void NotifyRoomsReceived(List<Room> rooms) => RoomsReceived?.Invoke(rooms);
|
||||
[Resolved]
|
||||
protected IRoomManager RoomManager { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,6 @@
|
||||
// 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 System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
@ -48,17 +46,7 @@ namespace osu.Game.Screens.OnlinePlay.Components
|
||||
|
||||
pollReq.Success += result =>
|
||||
{
|
||||
// existing rooms need to be ordered by their position because the received of NotifyRoomsReceives expects to be able to sort them based on this order.
|
||||
var rooms = new List<Room>(roomManager.Rooms.OrderBy(r => r.Position.Value));
|
||||
|
||||
int index = rooms.FindIndex(r => r.RoomID.Value == result.RoomID.Value);
|
||||
|
||||
if (index < 0)
|
||||
return;
|
||||
|
||||
rooms[index] = result;
|
||||
|
||||
NotifyRoomsReceived(rooms);
|
||||
RoomManager.AddOrUpdateRoom(result);
|
||||
tcs.SetResult(true);
|
||||
};
|
||||
|
||||
|
@ -18,16 +18,17 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
/// </summary>
|
||||
event Action RoomsUpdated;
|
||||
|
||||
/// <summary>
|
||||
/// Whether an initial listing of rooms has been received.
|
||||
/// </summary>
|
||||
IBindable<bool> InitialRoomsReceived { get; }
|
||||
|
||||
/// <summary>
|
||||
/// All the active <see cref="Room"/>s.
|
||||
/// </summary>
|
||||
IBindableList<Room> Rooms { get; }
|
||||
|
||||
void AddOrUpdateRoom(Room room);
|
||||
|
||||
void RemoveRoom(Room room);
|
||||
|
||||
void ClearRooms();
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new <see cref="Room"/>.
|
||||
/// </summary>
|
||||
|
@ -12,14 +12,17 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Input;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Match;
|
||||
using osu.Game.Users;
|
||||
@ -41,10 +44,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
AutoSizeAxes = Axes.Both
|
||||
};
|
||||
|
||||
private readonly IBindable<bool> initialRoomsReceived = new Bindable<bool>();
|
||||
private readonly IBindable<bool> operationInProgress = new Bindable<bool>();
|
||||
|
||||
private LoadingLayer loadingLayer;
|
||||
protected ListingPollingComponent ListingPollingComponent { get; private set; }
|
||||
|
||||
[Resolved]
|
||||
private Bindable<Room> selectedRoom { get; set; }
|
||||
@ -61,9 +61,15 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
[Resolved]
|
||||
private IBindable<RulesetInfo> ruleset { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IdleTracker idleTracker { get; set; }
|
||||
|
||||
[CanBeNull]
|
||||
private IDisposable joiningRoomOperation { get; set; }
|
||||
|
||||
private readonly IBindable<bool> operationInProgress = new Bindable<bool>();
|
||||
private readonly IBindable<bool> isIdle = new BindableBool();
|
||||
private LoadingLayer loadingLayer;
|
||||
private RoomsContainer roomsContainer;
|
||||
private SearchTextBox searchTextBox;
|
||||
private Dropdown<RoomStatusFilter> statusDropdown;
|
||||
@ -77,6 +83,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
ListingPollingComponent = CreatePollingComponent(),
|
||||
new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
@ -176,8 +183,13 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
searchTextBox.Current.BindValueChanged(_ => updateFilterDebounced());
|
||||
ruleset.BindValueChanged(_ => UpdateFilter());
|
||||
|
||||
initialRoomsReceived.BindTo(RoomManager.InitialRoomsReceived);
|
||||
initialRoomsReceived.BindValueChanged(_ => updateLoadingLayer());
|
||||
ListingPollingComponent.HasPolledOnce.BindValueChanged(_ => updateLoadingLayer());
|
||||
|
||||
if (idleTracker != null)
|
||||
{
|
||||
isIdle.BindTo(idleTracker.IsIdle);
|
||||
isIdle.BindValueChanged(_ => updatePollingRate(), true);
|
||||
}
|
||||
|
||||
if (ongoingOperationTracker != null)
|
||||
{
|
||||
@ -231,7 +243,6 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
public override void OnEntering(IScreen last)
|
||||
{
|
||||
base.OnEntering(last);
|
||||
|
||||
onReturning();
|
||||
}
|
||||
|
||||
@ -266,11 +277,13 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
|
||||
private void onReturning()
|
||||
{
|
||||
updatePollingRate();
|
||||
searchTextBox.HoldFocus = true;
|
||||
}
|
||||
|
||||
private void onLeaving()
|
||||
{
|
||||
updatePollingRate();
|
||||
searchTextBox.HoldFocus = false;
|
||||
|
||||
// ensure any password prompt is dismissed.
|
||||
@ -316,6 +329,24 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
this.Push(CreateRoomSubScreen(room));
|
||||
}
|
||||
|
||||
private void updateLoadingLayer()
|
||||
{
|
||||
if (operationInProgress.Value || !ListingPollingComponent.HasPolledOnce.Value)
|
||||
loadingLayer.Show();
|
||||
else
|
||||
loadingLayer.Hide();
|
||||
}
|
||||
|
||||
private void updatePollingRate()
|
||||
{
|
||||
if (!this.IsCurrentScreen())
|
||||
ListingPollingComponent.TimeBetweenPolls.Value = 0;
|
||||
else
|
||||
ListingPollingComponent.TimeBetweenPolls.Value = isIdle.Value ? 120000 : 15000;
|
||||
|
||||
Logger.Log($"Polling adjusted (listing: {ListingPollingComponent.TimeBetweenPolls.Value})");
|
||||
}
|
||||
|
||||
protected abstract OsuButton CreateNewRoomButton();
|
||||
|
||||
/// <summary>
|
||||
@ -326,13 +357,7 @@ namespace osu.Game.Screens.OnlinePlay.Lounge
|
||||
|
||||
protected abstract RoomSubScreen CreateRoomSubScreen(Room room);
|
||||
|
||||
private void updateLoadingLayer()
|
||||
{
|
||||
if (operationInProgress.Value || !initialRoomsReceived.Value)
|
||||
loadingLayer.Show();
|
||||
else
|
||||
loadingLayer.Hide();
|
||||
}
|
||||
protected abstract ListingPollingComponent CreatePollingComponent();
|
||||
|
||||
private class LoungeSearchTextBox : SearchTextBox
|
||||
{
|
||||
|
@ -2,7 +2,6 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
@ -23,35 +22,6 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
client.ChangeState(MultiplayerUserState.Idle);
|
||||
}
|
||||
|
||||
protected override void UpdatePollingRate(bool isIdle)
|
||||
{
|
||||
var multiplayerRoomManager = (MultiplayerRoomManager)RoomManager;
|
||||
|
||||
if (!this.IsCurrentScreen())
|
||||
{
|
||||
multiplayerRoomManager.TimeBetweenListingPolls.Value = 0;
|
||||
multiplayerRoomManager.TimeBetweenSelectionPolls.Value = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (CurrentSubScreen)
|
||||
{
|
||||
case LoungeSubScreen _:
|
||||
multiplayerRoomManager.TimeBetweenListingPolls.Value = isIdle ? 120000 : 15000;
|
||||
multiplayerRoomManager.TimeBetweenSelectionPolls.Value = isIdle ? 120000 : 15000;
|
||||
break;
|
||||
|
||||
// Don't poll inside the match or anywhere else.
|
||||
default:
|
||||
multiplayerRoomManager.TimeBetweenListingPolls.Value = 0;
|
||||
multiplayerRoomManager.TimeBetweenSelectionPolls.Value = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Log($"Polling adjusted (listing: {multiplayerRoomManager.TimeBetweenListingPolls.Value}, selection: {multiplayerRoomManager.TimeBetweenSelectionPolls.Value})");
|
||||
}
|
||||
|
||||
protected override string ScreenTitle => "Multiplayer";
|
||||
|
||||
protected override RoomManager CreateRoomManager() => new MultiplayerRoomManager();
|
||||
|
@ -1,12 +1,16 @@
|
||||
// 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 System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Logging;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Multiplayer;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Lounge;
|
||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Match;
|
||||
@ -21,6 +25,12 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
[Resolved]
|
||||
private MultiplayerClient client { get; set; }
|
||||
|
||||
public override void OnResuming(IScreen last)
|
||||
{
|
||||
base.OnResuming(last);
|
||||
ListingPollingComponent.PollImmediately();
|
||||
}
|
||||
|
||||
protected override FilterCriteria CreateFilterCriteria()
|
||||
{
|
||||
var criteria = base.CreateFilterCriteria();
|
||||
@ -39,6 +49,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
|
||||
protected override RoomSubScreen CreateRoomSubScreen(Room room) => new MultiplayerMatchSubScreen(room);
|
||||
|
||||
protected override ListingPollingComponent CreatePollingComponent() => new MultiplayerListingPollingComponent();
|
||||
|
||||
protected override void OpenNewRoom(Room room)
|
||||
{
|
||||
if (client?.IsConnected.Value != true)
|
||||
@ -49,5 +61,26 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
|
||||
base.OpenNewRoom(room);
|
||||
}
|
||||
|
||||
private class MultiplayerListingPollingComponent : ListingPollingComponent
|
||||
{
|
||||
public readonly IBindable<bool> AllowPolling = new Bindable<bool>();
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
AllowPolling.BindValueChanged(allowPolling =>
|
||||
{
|
||||
if (!allowPolling.NewValue)
|
||||
return;
|
||||
|
||||
if (IsLoaded)
|
||||
PollImmediately();
|
||||
});
|
||||
}
|
||||
|
||||
protected override Task Poll() => !AllowPolling.Value ? Task.CompletedTask : base.Poll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,9 +49,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
private OngoingOperationTracker ongoingOperationTracker { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private Bindable<Room> currentRoom { get; set; }
|
||||
|
||||
private MultiplayerMatchSettingsOverlay settingsOverlay;
|
||||
private Bindable<Room> currentRoom { get; set; } // Todo: This should not exist.
|
||||
|
||||
private readonly IBindable<bool> isConnected = new Bindable<bool>();
|
||||
|
||||
@ -59,6 +57,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
private IDisposable readyClickOperation;
|
||||
|
||||
private GridContainer mainContent;
|
||||
private MultiplayerMatchSettingsOverlay settingsOverlay;
|
||||
|
||||
public MultiplayerMatchSubScreen(Room room)
|
||||
{
|
||||
@ -324,6 +323,10 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
|
||||
public override bool OnExiting(IScreen next)
|
||||
{
|
||||
// We don't know whether we're the only participant in the room, and whether the room will close after we leave it as a result.
|
||||
// To work around this, temporarily remove the room until the next listing poll retrieves it.
|
||||
RoomManager?.RemoveRoom(currentRoom.Value);
|
||||
|
||||
// the room may not be left immediately after a disconnection due to async flow,
|
||||
// so checking the IsConnected status is also required.
|
||||
if (client.Room == null || !client.IsConnected.Value)
|
||||
|
@ -2,9 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Threading.Tasks;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Extensions.ExceptionExtensions;
|
||||
@ -21,13 +19,9 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
[Resolved]
|
||||
private MultiplayerClient 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>();
|
||||
private readonly Bindable<bool> allowPolling = new Bindable<bool>();
|
||||
|
||||
private ListingPollingComponent listingPollingComponent;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
@ -64,19 +58,8 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
if (JoinedRoom.Value == null)
|
||||
return;
|
||||
|
||||
var joinedRoom = JoinedRoom.Value;
|
||||
|
||||
base.PartRoom();
|
||||
|
||||
multiplayerClient.LeaveRoom();
|
||||
|
||||
// Todo: This is not the way to do this. Basically when we're the only participant and the room closes, there's no way to know if this is actually the case.
|
||||
// This is delayed one frame because upon exiting the match subscreen, multiplayer updates the polling rate and messes with polling.
|
||||
Schedule(() =>
|
||||
{
|
||||
RemoveRoom(joinedRoom);
|
||||
listingPollingComponent.PollImmediately();
|
||||
});
|
||||
}
|
||||
|
||||
private void joinMultiplayerRoom(Room room, string password, Action<Room> onSuccess = null, Action<string> onError = null)
|
||||
@ -108,61 +91,5 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer
|
||||
// Don't poll when not connected or when a room has been joined.
|
||||
allowPolling.Value = isConnected.Value && JoinedRoom.Value == null;
|
||||
}
|
||||
|
||||
protected override IEnumerable<RoomPollingComponent> CreatePollingComponents() => new RoomPollingComponent[]
|
||||
{
|
||||
listingPollingComponent = new MultiplayerListingPollingComponent
|
||||
{
|
||||
TimeBetweenPolls = { BindTarget = TimeBetweenListingPolls },
|
||||
AllowPolling = { BindTarget = allowPolling }
|
||||
},
|
||||
new MultiplayerSelectionPollingComponent
|
||||
{
|
||||
TimeBetweenPolls = { BindTarget = TimeBetweenSelectionPolls },
|
||||
AllowPolling = { BindTarget = allowPolling }
|
||||
}
|
||||
};
|
||||
|
||||
private class MultiplayerListingPollingComponent : ListingPollingComponent
|
||||
{
|
||||
public readonly IBindable<bool> AllowPolling = new Bindable<bool>();
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
AllowPolling.BindValueChanged(allowPolling =>
|
||||
{
|
||||
if (!allowPolling.NewValue)
|
||||
return;
|
||||
|
||||
if (IsLoaded)
|
||||
PollImmediately();
|
||||
});
|
||||
}
|
||||
|
||||
protected override Task Poll() => !AllowPolling.Value ? Task.CompletedTask : base.Poll();
|
||||
}
|
||||
|
||||
private class MultiplayerSelectionPollingComponent : SelectionPollingComponent
|
||||
{
|
||||
public readonly IBindable<bool> AllowPolling = new Bindable<bool>();
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
AllowPolling.BindValueChanged(allowPolling =>
|
||||
{
|
||||
if (!allowPolling.NewValue)
|
||||
return;
|
||||
|
||||
if (IsLoaded)
|
||||
PollImmediately();
|
||||
});
|
||||
}
|
||||
|
||||
protected override Task Poll() => !AllowPolling.Value ? Task.CompletedTask : base.Poll();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ using osu.Framework.Logging;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Beatmaps.Drawables;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Input;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Overlays;
|
||||
@ -43,8 +42,6 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
private LoungeSubScreen loungeSubScreen;
|
||||
private ScreenStack screenStack;
|
||||
|
||||
private readonly IBindable<bool> isIdle = new BindableBool();
|
||||
|
||||
[Cached(Type = typeof(IRoomManager))]
|
||||
protected RoomManager RoomManager { get; private set; }
|
||||
|
||||
@ -66,9 +63,6 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
[Resolved]
|
||||
protected IAPIProvider API { get; private set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private IdleTracker idleTracker { get; set; }
|
||||
|
||||
[Resolved(CanBeNull = true)]
|
||||
private OsuLogo logo { get; set; }
|
||||
|
||||
@ -151,12 +145,6 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
|
||||
apiState.BindTo(API.State);
|
||||
apiState.BindValueChanged(onlineStateChanged, true);
|
||||
|
||||
if (idleTracker != null)
|
||||
{
|
||||
isIdle.BindTo(idleTracker.IsIdle);
|
||||
isIdle.BindValueChanged(idle => UpdatePollingRate(idle.NewValue), true);
|
||||
}
|
||||
}
|
||||
|
||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||
@ -166,8 +154,6 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
return dependencies;
|
||||
}
|
||||
|
||||
protected abstract void UpdatePollingRate(bool isIdle);
|
||||
|
||||
private void forcefullyExit()
|
||||
{
|
||||
// This is temporary since we don't currently have a way to force screens to be exited
|
||||
@ -203,8 +189,6 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
screenStack.CurrentScreen.OnResuming(last);
|
||||
|
||||
base.OnResuming(last);
|
||||
|
||||
UpdatePollingRate(isIdle.Value);
|
||||
}
|
||||
|
||||
public override void OnSuspending(IScreen next)
|
||||
@ -214,8 +198,6 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
|
||||
Debug.Assert(screenStack.CurrentScreen != null);
|
||||
screenStack.CurrentScreen.OnSuspending(next);
|
||||
|
||||
UpdatePollingRate(isIdle.Value);
|
||||
}
|
||||
|
||||
public override bool OnExiting(IScreen next)
|
||||
@ -279,15 +261,13 @@ namespace osu.Game.Screens.OnlinePlay
|
||||
|
||||
if (newScreen is IOsuScreen newOsuScreen)
|
||||
((IBindable<UserActivity>)Activity).BindTo(newOsuScreen.Activity);
|
||||
|
||||
UpdatePollingRate(isIdle.Value);
|
||||
}
|
||||
|
||||
protected IScreen CurrentSubScreen => screenStack.CurrentScreen;
|
||||
|
||||
protected abstract string ScreenTitle { get; }
|
||||
|
||||
protected abstract RoomManager CreateRoomManager();
|
||||
protected virtual RoomManager CreateRoomManager() => new RoomManager();
|
||||
|
||||
protected abstract LoungeSubScreen CreateLounge();
|
||||
|
||||
|
@ -1,53 +1,14 @@
|
||||
// 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.Logging;
|
||||
using osu.Framework.Screens;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Lounge;
|
||||
using osu.Game.Screens.OnlinePlay.Match;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
{
|
||||
public class Playlists : OnlinePlayScreen
|
||||
{
|
||||
protected override void UpdatePollingRate(bool isIdle)
|
||||
{
|
||||
var playlistsManager = (PlaylistsRoomManager)RoomManager;
|
||||
|
||||
if (!this.IsCurrentScreen())
|
||||
{
|
||||
playlistsManager.TimeBetweenListingPolls.Value = 0;
|
||||
playlistsManager.TimeBetweenSelectionPolls.Value = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
switch (CurrentSubScreen)
|
||||
{
|
||||
case LoungeSubScreen _:
|
||||
playlistsManager.TimeBetweenListingPolls.Value = isIdle ? 120000 : 15000;
|
||||
playlistsManager.TimeBetweenSelectionPolls.Value = isIdle ? 120000 : 15000;
|
||||
break;
|
||||
|
||||
case RoomSubScreen _:
|
||||
playlistsManager.TimeBetweenListingPolls.Value = 0;
|
||||
playlistsManager.TimeBetweenSelectionPolls.Value = isIdle ? 30000 : 5000;
|
||||
break;
|
||||
|
||||
default:
|
||||
playlistsManager.TimeBetweenListingPolls.Value = 0;
|
||||
playlistsManager.TimeBetweenSelectionPolls.Value = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Logger.Log($"Polling adjusted (listing: {playlistsManager.TimeBetweenListingPolls.Value}, selection: {playlistsManager.TimeBetweenSelectionPolls.Value})");
|
||||
}
|
||||
|
||||
protected override string ScreenTitle => "Playlists";
|
||||
|
||||
protected override RoomManager CreateRoomManager() => new PlaylistsRoomManager();
|
||||
|
||||
protected override LoungeSubScreen CreateLounge() => new PlaylistsLoungeSubScreen();
|
||||
}
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Rooms;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Lounge;
|
||||
using osu.Game.Screens.OnlinePlay.Lounge.Components;
|
||||
using osu.Game.Screens.OnlinePlay.Match;
|
||||
@ -66,6 +67,8 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
|
||||
protected override RoomSubScreen CreateRoomSubScreen(Room room) => new PlaylistsRoomSubScreen(room);
|
||||
|
||||
protected override ListingPollingComponent CreatePollingComponent() => new ListingPollingComponent();
|
||||
|
||||
private enum PlaylistsCategory
|
||||
{
|
||||
Any,
|
||||
|
@ -1,21 +0,0 @@
|
||||
// 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 System.Collections.Generic;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Game.Screens.OnlinePlay.Components;
|
||||
|
||||
namespace osu.Game.Screens.OnlinePlay.Playlists
|
||||
{
|
||||
public class PlaylistsRoomManager : RoomManager
|
||||
{
|
||||
public readonly Bindable<double> TimeBetweenListingPolls = new Bindable<double>();
|
||||
public readonly Bindable<double> TimeBetweenSelectionPolls = new Bindable<double>();
|
||||
|
||||
protected override IEnumerable<RoomPollingComponent> CreatePollingComponents() => new RoomPollingComponent[]
|
||||
{
|
||||
new ListingPollingComponent { TimeBetweenPolls = { BindTarget = TimeBetweenListingPolls } },
|
||||
new SelectionPollingComponent { TimeBetweenPolls = { BindTarget = TimeBetweenSelectionPolls } }
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user