Merge pull request #27379 from EVAST9919/gameplay-alloc

Further reduce allocations during gameplay
This commit is contained in:
Dean Herbert 2024-02-26 09:55:28 +08:00 committed by GitHub
commit b0c45c87c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 8 deletions

View File

@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Performance;
using osu.Game.Rulesets.Judgements;
@ -41,7 +40,22 @@ public class HitObjectLifetimeEntry : LifetimeEntry
/// <summary>
/// Whether <see cref="HitObject"/> and all of its nested objects have been judged.
/// </summary>
public bool AllJudged => Judged && NestedEntries.All(h => h.AllJudged);
public bool AllJudged
{
get
{
if (!Judged)
return false;
foreach (var entry in NestedEntries)
{
if (!entry.AllJudged)
return false;
}
return true;
}
}
private readonly IBindable<double> startTimeBindable = new BindableDouble();

View File

@ -258,14 +258,10 @@ protected override void Update()
Vector2? highestBottomScreenSpace = null;
foreach (var element in mainComponents.Components)
processDrawable(element);
processDrawables(mainComponents);
if (rulesetComponents != null)
{
foreach (var element in rulesetComponents.Components)
processDrawable(element);
}
processDrawables(rulesetComponents);
if (lowestTopScreenSpaceRight.HasValue)
topRightElements.Y = MathHelper.Clamp(ToLocalSpace(new Vector2(0, lowestTopScreenSpaceRight.Value)).Y, 0, DrawHeight - topRightElements.DrawHeight);
@ -282,6 +278,14 @@ protected override void Update()
else
bottomRightElements.Y = 0;
void processDrawables(SkinComponentsContainer components)
{
// Avoid using foreach due to missing GetEnumerator implementation.
// See https://github.com/ppy/osu-framework/blob/e10051e6643731e393b09de40a3a3d209a545031/osu.Framework/Bindables/IBindableList.cs#L41-L44.
for (int i = 0; i < components.Components.Count; i++)
processDrawable(components.Components[i]);
}
void processDrawable(ISerialisableDrawable element)
{
// Cast can be removed when IDrawable interface includes Anchor / RelativeSizeAxes.