From 10287eb66dfe31fb02a864e3343ce7373d2914bf Mon Sep 17 00:00:00 2001 From: smoogipoo Date: Fri, 15 Nov 2019 17:58:47 +0900 Subject: [PATCH] Add debounce logic in several places --- .../Multi/Lounge/Components/RoomsContainer.cs | 17 ++++++++++++++++- osu.Game/Screens/Multi/RoomManager.cs | 11 ++++++++++- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/osu.Game/Screens/Multi/Lounge/Components/RoomsContainer.cs b/osu.Game/Screens/Multi/Lounge/Components/RoomsContainer.cs index 77f4632bf1..3dde9452e4 100644 --- a/osu.Game/Screens/Multi/Lounge/Components/RoomsContainer.cs +++ b/osu.Game/Screens/Multi/Lounge/Components/RoomsContainer.cs @@ -9,6 +9,7 @@ using osu.Framework.Bindables; using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Threading; using osu.Game.Graphics.UserInterface; using osu.Game.Online.Multiplayer; using osuTK; @@ -62,7 +63,10 @@ namespace osu.Game.Screens.Multi.Lounge.Components protected override void LoadComplete() { - filter?.BindValueChanged(f => Filter(f.NewValue), true); + filter?.BindValueChanged(f => scheduleFilter()); + + if (filter != null) + Filter(filter.Value); } public void Filter(FilterCriteria criteria) @@ -89,6 +93,17 @@ namespace osu.Game.Screens.Multi.Lounge.Components }); } + private ScheduledDelegate scheduledFilter; + + private void scheduleFilter() + { + if (filter == null) + return; + + scheduledFilter?.Cancel(); + scheduledFilter = Scheduler.AddDelayed(() => Filter(filter.Value), 200); + } + private void addRooms(IEnumerable rooms) { foreach (var r in rooms) diff --git a/osu.Game/Screens/Multi/RoomManager.cs b/osu.Game/Screens/Multi/RoomManager.cs index cdaba85b9e..d6d3ec37ef 100644 --- a/osu.Game/Screens/Multi/RoomManager.cs +++ b/osu.Game/Screens/Multi/RoomManager.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Logging; +using osu.Framework.Threading; using osu.Game.Beatmaps; using osu.Game.Online; using osu.Game.Online.API; @@ -44,7 +45,7 @@ namespace osu.Game.Screens.Multi currentFilter.BindValueChanged(_ => { if (IsLoaded) - PollImmediately(); + schedulePoll(); }); } @@ -157,6 +158,14 @@ namespace osu.Game.Screens.Multi return tcs.Task; } + private ScheduledDelegate scheduledPoll; + + private void schedulePoll() + { + scheduledPoll?.Cancel(); + scheduledPoll = Scheduler.AddDelayed(PollImmediately, 200); + } + /// /// Updates a local with a remote copy. ///