Avoid usage of LINQ in last dash trail computation

This commit is contained in:
ekrctb 2021-07-27 19:11:08 +09:00
parent da69867fd4
commit 846f539428
2 changed files with 18 additions and 9 deletions

View File

@ -114,10 +114,9 @@ namespace osu.Game.Rulesets.Catch.UI
if (Catcher.Dashing || Catcher.HyperDashing)
{
double lastTrailTime = CatcherTrails.LastDashTrail?.LifetimeStart ?? double.NegativeInfinity;
double generationInterval = Catcher.HyperDashing ? 25 : 50;
if (Time.Current - lastTrailTime >= generationInterval)
if (Time.Current - CatcherTrails.LastDashTrailTime >= generationInterval)
CatcherTrails.DisplayDashTrail(Catcher.CurrentState, Catcher.X, Catcher.BodyScale, Catcher.HyperDashing);
}

View File

@ -1,8 +1,7 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using JetBrains.Annotations;
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Pooling;
@ -20,13 +19,11 @@ namespace osu.Game.Rulesets.Catch.UI
public class CatcherTrailDisplay : SkinReloadableDrawable
{
/// <summary>
/// The most recent dash trail added in this container.
/// The most recent time a dash trail was added to this container.
/// Only alive (not faded out) trails are considered.
/// Returns <see cref="double.NegativeInfinity"/> if no dash trail is alive.
/// </summary>
[CanBeNull]
public CatcherTrail LastDashTrail => dashTrails.Concat(hyperDashTrails)
.OrderByDescending(trail => trail.LifetimeStart)
.FirstOrDefault();
public double LastDashTrailTime => getLastDashTrailTime();
public Color4 HyperDashTrailsColour => hyperDashTrails.Colour;
@ -97,5 +94,18 @@ namespace osu.Game.Rulesets.Catch.UI
return sprite;
}
private double getLastDashTrailTime()
{
double maxTime = double.NegativeInfinity;
foreach (var trail in dashTrails)
maxTime = Math.Max(maxTime, trail.LifetimeStart);
foreach (var trail in hyperDashTrails)
maxTime = Math.Max(maxTime, trail.LifetimeStart);
return maxTime;
}
}
}