1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 14:53:21 +08:00

Reduce calculator allocations in counter

This commit is contained in:
Dan Balasescu 2022-03-14 14:44:04 +09:00
parent 4a3e3aba65
commit 926827207a

View File

@ -55,6 +55,7 @@ namespace osu.Game.Screens.Play.HUD
private readonly CancellationTokenSource loadCancellationSource = new CancellationTokenSource();
private JudgementResult lastJudgement;
private PerformanceCalculator performanceCalculator;
public PerformancePointsCounter()
{
@ -70,6 +71,8 @@ namespace osu.Game.Screens.Play.HUD
if (gameplayState != null)
{
performanceCalculator = gameplayState.Ruleset.CreatePerformanceCalculator();
clonedMods = gameplayState.Mods.Select(m => m.DeepClone()).ToArray();
var gameplayWorkingBeatmap = new GameplayWorkingBeatmap(gameplayState.Beatmap);
@ -130,9 +133,7 @@ namespace osu.Game.Screens.Play.HUD
var scoreInfo = gameplayState.Score.ScoreInfo.DeepClone();
scoreInfo.Mods = clonedMods;
var calculator = gameplayState.Ruleset.CreatePerformanceCalculator();
Current.Value = (int)Math.Round(calculator?.Calculate(scoreInfo, attrib).Total ?? 0, MidpointRounding.AwayFromZero);
Current.Value = (int)Math.Round(performanceCalculator?.Calculate(scoreInfo, attrib).Total ?? 0, MidpointRounding.AwayFromZero);
IsValid = true;
}