1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-04 01:22:54 +08:00

Don't create nested hitobjects unless absolutely required

This commit is contained in:
smoogipoo 2018-05-17 12:29:33 +09:00
parent 7765a1aa3a
commit c67f372560

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>. // Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Newtonsoft.Json; using Newtonsoft.Json;
using osu.Framework.Extensions.IEnumerableExtensions; using osu.Framework.Extensions.IEnumerableExtensions;
@ -56,10 +57,10 @@ namespace osu.Game.Rulesets.Objects
/// </summary> /// </summary>
public HitWindows HitWindows { get; set; } public HitWindows HitWindows { get; set; }
private readonly SortedList<HitObject> nestedHitObjects = new SortedList<HitObject>((h1, h2) => h1.StartTime.CompareTo(h2.StartTime)); private readonly Lazy<SortedList<HitObject>> nestedHitObjects = new Lazy<SortedList<HitObject>>(() => new SortedList<HitObject>((h1, h2) => h1.StartTime.CompareTo(h2.StartTime)));
[JsonIgnore] [JsonIgnore]
public IReadOnlyList<HitObject> NestedHitObjects => nestedHitObjects; public IReadOnlyList<HitObject> NestedHitObjects => nestedHitObjects.Value;
/// <summary> /// <summary>
/// Applies default values to this HitObject. /// Applies default values to this HitObject.
@ -70,13 +71,19 @@ namespace osu.Game.Rulesets.Objects
{ {
ApplyDefaultsToSelf(controlPointInfo, difficulty); ApplyDefaultsToSelf(controlPointInfo, difficulty);
nestedHitObjects.Clear(); if (nestedHitObjects.IsValueCreated)
nestedHitObjects.Value.Clear();
CreateNestedHitObjects(); CreateNestedHitObjects();
nestedHitObjects.ForEach(h =>
if (nestedHitObjects.IsValueCreated)
{ {
h.HitWindows = HitWindows; nestedHitObjects.Value.ForEach(h =>
h.ApplyDefaults(controlPointInfo, difficulty); {
}); h.HitWindows = HitWindows;
h.ApplyDefaults(controlPointInfo, difficulty);
});
}
} }
protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected virtual void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
@ -96,7 +103,7 @@ namespace osu.Game.Rulesets.Objects
{ {
} }
protected void AddNested(HitObject hitObject) => nestedHitObjects.Add(hitObject); protected void AddNested(HitObject hitObject) => nestedHitObjects.Value.Add(hitObject);
/// <summary> /// <summary>
/// Creates the <see cref="HitWindows"/> for this <see cref="HitObject"/>. /// Creates the <see cref="HitWindows"/> for this <see cref="HitObject"/>.