From 0fb8615f95b29dbff7ba1c839c3591a1b72aa5b1 Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Sat, 19 Dec 2020 02:02:04 +0900 Subject: [PATCH] Implement room parting --- .../Screens/Multi/Components/RoomManager.cs | 4 +++- .../RealtimeRoomManager.cs | 20 ++++++++++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Multi/Components/RoomManager.cs b/osu.Game/Screens/Multi/Components/RoomManager.cs index 6e27515849..21bff70b8b 100644 --- a/osu.Game/Screens/Multi/Components/RoomManager.cs +++ b/osu.Game/Screens/Multi/Components/RoomManager.cs @@ -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(); diff --git a/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeRoomManager.cs b/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeRoomManager.cs index 69addde2a6..4f73ee3865 100644 --- a/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeRoomManager.cs +++ b/osu.Game/Screens/Multi/RealtimeMultiplayer/RealtimeRoomManager.cs @@ -23,6 +23,8 @@ namespace osu.Game.Screens.Multi.RealtimeMultiplayer private readonly IBindable isConnected = new Bindable(); private readonly Bindable allowPolling = new Bindable(); + 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 onSuccess = null, Action 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 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 }