mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 18:52:55 +08:00
Reduce allocations during beatmap selection
This commit is contained in:
parent
2adc8b15e7
commit
22f5a66c02
@ -232,7 +232,13 @@ namespace osu.Game.Rulesets.Osu.Difficulty.Preprocessing
|
|||||||
|
|
||||||
IList<HitObject> nestedObjects = slider.NestedHitObjects;
|
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)
|
if (lastRealTick?.StartTime > trackingEndTime)
|
||||||
{
|
{
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Linq;
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Beatmaps.ControlPoints;
|
using osu.Game.Beatmaps.ControlPoints;
|
||||||
@ -149,8 +148,11 @@ namespace osu.Game.Rulesets.Osu.Objects
|
|||||||
{
|
{
|
||||||
StackHeightBindable.BindValueChanged(height =>
|
StackHeightBindable.BindValueChanged(height =>
|
||||||
{
|
{
|
||||||
foreach (var nested in NestedHitObjects.OfType<OsuHitObject>())
|
foreach (var nested in NestedHitObjects)
|
||||||
nested.StackHeight = height.NewValue;
|
{
|
||||||
|
if (nested is OsuHitObject osuHitObject)
|
||||||
|
osuHitObject.StackHeight = height.NewValue;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,18 +252,42 @@ namespace osu.Game.Rulesets.Osu.Objects
|
|||||||
|
|
||||||
protected void UpdateNestedSamples()
|
protected void UpdateNestedSamples()
|
||||||
{
|
{
|
||||||
var firstSample = Samples.FirstOrDefault(s => s.Name == HitSampleInfo.HIT_NORMAL)
|
HitSampleInfo firstSample = null;
|
||||||
?? Samples.FirstOrDefault(); // TODO: remove this when guaranteed sort is present for samples (https://github.com/ppy/osu/issues/1933)
|
|
||||||
|
for (int i = 0; i < Samples.Count; i++)
|
||||||
|
{
|
||||||
|
// TODO: remove this when guaranteed sort is present for samples (https://github.com/ppy/osu/issues/1933)
|
||||||
|
if (i == 0)
|
||||||
|
{
|
||||||
|
firstSample = Samples[i];
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Samples[i].Name != HitSampleInfo.HIT_NORMAL)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
firstSample = Samples[i];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
var sampleList = new List<HitSampleInfo>();
|
var sampleList = new List<HitSampleInfo>();
|
||||||
|
|
||||||
if (firstSample != null)
|
if (firstSample != null)
|
||||||
sampleList.Add(firstSample.With("slidertick"));
|
sampleList.Add(firstSample.With("slidertick"));
|
||||||
|
|
||||||
foreach (var tick in NestedHitObjects.OfType<SliderTick>())
|
foreach (var nested in NestedHitObjects)
|
||||||
tick.Samples = sampleList;
|
{
|
||||||
|
switch (nested)
|
||||||
|
{
|
||||||
|
case SliderTick tick:
|
||||||
|
tick.Samples = sampleList;
|
||||||
|
break;
|
||||||
|
|
||||||
foreach (var repeat in NestedHitObjects.OfType<SliderRepeat>())
|
case SliderRepeat repeat:
|
||||||
repeat.Samples = this.GetNodeSamples(repeat.RepeatIndex + 1);
|
repeat.Samples = this.GetNodeSamples(repeat.RepeatIndex + 1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (HeadCircle != null)
|
if (HeadCircle != null)
|
||||||
HeadCircle.Samples = this.GetNodeSamples(0);
|
HeadCircle.Samples = this.GetNodeSamples(0);
|
||||||
|
@ -61,16 +61,17 @@ namespace osu.Game.Rulesets.Objects
|
|||||||
case NotifyCollectionChangedAction.Add:
|
case NotifyCollectionChangedAction.Add:
|
||||||
Debug.Assert(args.NewItems != null);
|
Debug.Assert(args.NewItems != null);
|
||||||
|
|
||||||
foreach (var c in args.NewItems.Cast<PathControlPoint>())
|
foreach (object? newItem in args.NewItems)
|
||||||
c.Changed += invalidate;
|
((PathControlPoint)newItem).Changed += invalidate;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NotifyCollectionChangedAction.Reset:
|
case NotifyCollectionChangedAction.Reset:
|
||||||
case NotifyCollectionChangedAction.Remove:
|
case NotifyCollectionChangedAction.Remove:
|
||||||
Debug.Assert(args.OldItems != null);
|
Debug.Assert(args.OldItems != null);
|
||||||
|
|
||||||
foreach (var c in args.OldItems.Cast<PathControlPoint>())
|
foreach (object? oldItem in args.OldItems)
|
||||||
c.Changed -= invalidate;
|
((PathControlPoint)oldItem).Changed -= invalidate;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -269,10 +270,10 @@ namespace osu.Game.Rulesets.Objects
|
|||||||
{
|
{
|
||||||
List<Vector2> subPath = calculateSubPath(segmentVertices, segmentType);
|
List<Vector2> subPath = calculateSubPath(segmentVertices, segmentType);
|
||||||
// Skip the first vertex if it is the same as the last vertex from the previous segment
|
// 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))
|
for (int j = skipFirst ? 1 : 0; j < subPath.Count; j++)
|
||||||
calculatedPath.Add(t);
|
calculatedPath.Add(subPath[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
|
@ -510,12 +510,27 @@ namespace osu.Game.Screens.Select
|
|||||||
if (beatmapInfo?.Hidden != false)
|
if (beatmapInfo?.Hidden != false)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
foreach (CarouselBeatmapSet set in beatmapSets)
|
foreach (var carouselItem in root.Items)
|
||||||
{
|
{
|
||||||
|
if (carouselItem is not CarouselBeatmapSet set)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (!bypassFilters && set.Filtered.Value)
|
if (!bypassFilters && set.Filtered.Value)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
var item = set.Beatmaps.FirstOrDefault(p => p.BeatmapInfo.Equals(beatmapInfo));
|
CarouselBeatmap? item = null;
|
||||||
|
|
||||||
|
foreach (var setCarouselItem in set.Items)
|
||||||
|
{
|
||||||
|
if (setCarouselItem is not CarouselBeatmap setCarouselBeatmap)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (!setCarouselBeatmap.BeatmapInfo.Equals(beatmapInfo))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
item = setCarouselBeatmap;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (item == null)
|
if (item == null)
|
||||||
// The beatmap that needs to be selected doesn't exist in this set
|
// The beatmap that needs to be selected doesn't exist in this set
|
||||||
|
Loading…
Reference in New Issue
Block a user