Merge pull request #27206 from EVAST9919/selection-enumerators

Reduce allocations during beatmap selection
This commit is contained in:
Dean Herbert 2024-02-18 10:02:35 +08:00 committed by GitHub
commit 715236765a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 36 additions and 20 deletions

View File

@ -232,7 +232,13 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Preprocessing
IList<HitObject> nestedObjects = slider.NestedHitObjects;
SliderTick? lastRealTick = slider.NestedHitObjects.OfType<SliderTick>().LastOrDefault();
SliderTick? lastRealTick = null;
foreach (var hitobject in slider.NestedHitObjects)
{
if (hitobject is SliderTick tick)
lastRealTick = tick;
}
if (lastRealTick?.StartTime > trackingEndTime)
{

View File

@ -2,7 +2,6 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Linq;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
@ -149,8 +148,11 @@ namespace osu.Game.Rulesets.Osu.Objects
{
StackHeightBindable.BindValueChanged(height =>
{
foreach (var nested in NestedHitObjects.OfType<OsuHitObject>())
nested.StackHeight = height.NewValue;
foreach (var nested in NestedHitObjects)
{
if (nested is OsuHitObject osuHitObject)
osuHitObject.StackHeight = height.NewValue;
}
});
}

View File

@ -252,18 +252,25 @@ namespace osu.Game.Rulesets.Osu.Objects
protected void UpdateNestedSamples()
{
var firstSample = Samples.FirstOrDefault(s => s.Name == HitSampleInfo.HIT_NORMAL)
?? Samples.FirstOrDefault(); // TODO: remove this when guaranteed sort is present for samples (https://github.com/ppy/osu/issues/1933)
var sampleList = new List<HitSampleInfo>();
// TODO: remove this when guaranteed sort is present for samples (https://github.com/ppy/osu/issues/1933)
HitSampleInfo tickSample = (Samples.FirstOrDefault(s => s.Name == HitSampleInfo.HIT_NORMAL) ?? Samples.FirstOrDefault())?.With("slidertick");
if (firstSample != null)
sampleList.Add(firstSample.With("slidertick"));
foreach (var nested in NestedHitObjects)
{
switch (nested)
{
case SliderTick tick:
tick.SamplesBindable.Clear();
foreach (var tick in NestedHitObjects.OfType<SliderTick>())
tick.Samples = sampleList;
if (tickSample != null)
tick.SamplesBindable.Add(tickSample);
break;
foreach (var repeat in NestedHitObjects.OfType<SliderRepeat>())
repeat.Samples = this.GetNodeSamples(repeat.RepeatIndex + 1);
case SliderRepeat repeat:
repeat.Samples = this.GetNodeSamples(repeat.RepeatIndex + 1);
break;
}
}
if (HeadCircle != null)
HeadCircle.Samples = this.GetNodeSamples(0);

View File

@ -61,16 +61,17 @@ namespace osu.Game.Rulesets.Objects
case NotifyCollectionChangedAction.Add:
Debug.Assert(args.NewItems != null);
foreach (var c in args.NewItems.Cast<PathControlPoint>())
c.Changed += invalidate;
foreach (object? newItem in args.NewItems)
((PathControlPoint)newItem).Changed += invalidate;
break;
case NotifyCollectionChangedAction.Reset:
case NotifyCollectionChangedAction.Remove:
Debug.Assert(args.OldItems != null);
foreach (var c in args.OldItems.Cast<PathControlPoint>())
c.Changed -= invalidate;
foreach (object? oldItem in args.OldItems)
((PathControlPoint)oldItem).Changed -= invalidate;
break;
}
@ -269,10 +270,10 @@ namespace osu.Game.Rulesets.Objects
{
List<Vector2> subPath = calculateSubPath(segmentVertices, segmentType);
// Skip the first vertex if it is the same as the last vertex from the previous segment
int skipFirst = calculatedPath.Count > 0 && subPath.Count > 0 && calculatedPath.Last() == subPath[0] ? 1 : 0;
bool skipFirst = calculatedPath.Count > 0 && subPath.Count > 0 && calculatedPath.Last() == subPath[0];
foreach (Vector2 t in subPath.Skip(skipFirst))
calculatedPath.Add(t);
for (int j = skipFirst ? 1 : 0; j < subPath.Count; j++)
calculatedPath.Add(subPath[j]);
}
if (i > 0)