Implement room parting

This commit is contained in:
smoogipoo 2020-12-19 02:02:04 +09:00
parent 7d1fe7955e
commit 0fb8615f95
2 changed files with 22 additions and 2 deletions

View File

@ -107,7 +107,7 @@ namespace osu.Game.Screens.Multi.Components
api.Queue(currentJoinRoomRequest);
}
public void PartRoom()
public virtual void PartRoom()
{
currentJoinRoomRequest?.Cancel();
@ -157,6 +157,8 @@ namespace osu.Game.Screens.Multi.Components
RoomsUpdated?.Invoke();
}
protected void RemoveRoom(Room room) => rooms.Remove(room);
protected void ClearRooms()
{
rooms.Clear();

View File

@ -23,6 +23,8 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
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();
@ -39,6 +41,22 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
public override void JoinRoom(Room room, Action<Room> onSuccess = null, Action<string> onError = null)
=> base.JoinRoom(room, r => joinMultiplayerRoom(r, onSuccess), onError);
public override void PartRoom()
{
if (JoinedRoom == null)
return;
var joinedRoom = JoinedRoom;
base.PartRoom();
multiplayerClient.LeaveRoom().Wait();
// 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.
RemoveRoom(joinedRoom);
// This is delayed one frame because upon exiting the match subscreen, multiplayer updates the polling rate and messes with polling.
Schedule(() => listingPollingComponent.PollImmediately());
}
private void joinMultiplayerRoom(Room room, Action<Room> onSuccess = null)
{
Debug.Assert(room.RoomID.Value != null);
@ -64,7 +82,7 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer
protected override RoomPollingComponent[] CreatePollingComponents() => new RoomPollingComponent[]
{
new RealtimeListingPollingComponent
listingPollingComponent = new RealtimeListingPollingComponent
{
TimeBetweenPolls = { BindTarget = TimeBetweenListingPolls },
AllowPolling = { BindTarget = allowPolling }