Limit countdown updates to once per second

This commit is contained in:
Dan Balasescu 2022-03-23 10:50:05 +09:00
parent 6b712be97d
commit d4ad4ac9db

View File

@ -6,6 +6,7 @@ using System.Linq;
using JetBrains.Annotations; using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Localisation; using osu.Framework.Localisation;
using osu.Framework.Threading;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds; using osu.Game.Graphics.Backgrounds;
using osu.Game.Online.Multiplayer; using osu.Game.Online.Multiplayer;
@ -33,21 +34,20 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer.Match
onRoomUpdated(); onRoomUpdated();
} }
protected override void Update() private ScheduledDelegate countdownUpdateDelegate;
{
base.Update();
if (room?.Countdown != null)
{
// Update the countdown timer.
onRoomUpdated();
}
}
private void onRoomUpdated() private void onRoomUpdated()
{ {
updateButtonText(); updateButtonText();
updateButtonColour(); updateButtonColour();
if (room?.Countdown != null)
countdownUpdateDelegate ??= Scheduler.AddDelayed(updateButtonText, 1000, true);
else
{
countdownUpdateDelegate?.Cancel();
countdownUpdateDelegate = null;
}
} }
private void updateButtonText() private void updateButtonText()