From d4ad4ac9db8c76be1cd9545944dca12e582d41f9 Mon Sep 17 00:00:00 2001 From: Dan Balasescu Date: Wed, 23 Mar 2022 10:50:05 +0900 Subject: [PATCH] Limit countdown updates to once per second --- .../Multiplayer/Match/ReadyButton.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/ReadyButton.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/ReadyButton.cs index 8e3a9f9349..b37d990466 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/Match/ReadyButton.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/Match/ReadyButton.cs @@ -6,6 +6,7 @@ using System.Linq; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Localisation; +using osu.Framework.Threading; using osu.Game.Graphics; using osu.Game.Graphics.Backgrounds; using osu.Game.Online.Multiplayer; @@ -33,21 +34,20 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match onRoomUpdated(); } - protected override void Update() - { - base.Update(); - - if (room?.Countdown != null) - { - // Update the countdown timer. - onRoomUpdated(); - } - } + private ScheduledDelegate countdownUpdateDelegate; private void onRoomUpdated() { updateButtonText(); updateButtonColour(); + + if (room?.Countdown != null) + countdownUpdateDelegate ??= Scheduler.AddDelayed(updateButtonText, 1000, true); + else + { + countdownUpdateDelegate?.Cancel(); + countdownUpdateDelegate = null; + } } private void updateButtonText()