mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 22:22:54 +08:00
Make NestedHitObjects lazily-constructed
This commit is contained in:
parent
df84b23847
commit
2a9fb2c2c6
@ -81,7 +81,7 @@ namespace osu.Game.Rulesets.Taiko.Objects.Drawables
|
|||||||
if (timeOffset < 0)
|
if (timeOffset < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
int countHit = NestedHitObjects?.Count(o => o.IsHit) ?? 0;
|
int countHit = NestedHitObjects.Count(o => o.IsHit);
|
||||||
if (countHit >= HitObject.RequiredGoodHits)
|
if (countHit >= HitObject.RequiredGoodHits)
|
||||||
{
|
{
|
||||||
AddJudgement(new TaikoJudgement { Result = countHit >= HitObject.RequiredGreatHits ? HitResult.Great : HitResult.Good });
|
AddJudgement(new TaikoJudgement { Result = countHit >= HitObject.RequiredGreatHits ? HitResult.Great : HitResult.Good });
|
||||||
|
@ -35,8 +35,9 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
|
|
||||||
protected virtual IEnumerable<SampleInfo> GetSamples() => HitObject.Samples;
|
protected virtual IEnumerable<SampleInfo> GetSamples() => HitObject.Samples;
|
||||||
|
|
||||||
private List<DrawableHitObject> nestedHitObjects;
|
private readonly Lazy<List<DrawableHitObject>> nestedHitObjects = new Lazy<List<DrawableHitObject>>();
|
||||||
public IReadOnlyList<DrawableHitObject> NestedHitObjects => nestedHitObjects;
|
public bool HasNestedHitObjects => nestedHitObjects.IsValueCreated;
|
||||||
|
public IReadOnlyList<DrawableHitObject> NestedHitObjects => nestedHitObjects.Value;
|
||||||
|
|
||||||
public event Action<DrawableHitObject, Judgement> OnJudgement;
|
public event Action<DrawableHitObject, Judgement> OnJudgement;
|
||||||
public event Action<DrawableHitObject, Judgement> OnJudgementRemoved;
|
public event Action<DrawableHitObject, Judgement> OnJudgementRemoved;
|
||||||
@ -52,12 +53,12 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether this <see cref="DrawableHitObject"/> and all of its nested <see cref="DrawableHitObject"/>s have been hit.
|
/// Whether this <see cref="DrawableHitObject"/> and all of its nested <see cref="DrawableHitObject"/>s have been hit.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool IsHit => Judgements.Any(j => j.Final && j.IsHit) && (NestedHitObjects?.All(n => n.IsHit) ?? true);
|
public bool IsHit => Judgements.Any(j => j.Final && j.IsHit) && (!HasNestedHitObjects || NestedHitObjects.All(n => n.IsHit));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether this <see cref="DrawableHitObject"/> and all of its nested <see cref="DrawableHitObject"/>s have been judged.
|
/// Whether this <see cref="DrawableHitObject"/> and all of its nested <see cref="DrawableHitObject"/>s have been judged.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public bool AllJudged => (!ProvidesJudgement || judgementFinalized) && (NestedHitObjects?.All(h => h.AllJudged) ?? true);
|
public bool AllJudged => (!ProvidesJudgement || judgementFinalized) && (!HasNestedHitObjects || NestedHitObjects.All(h => h.AllJudged));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether this <see cref="DrawableHitObject"/> can be judged.
|
/// Whether this <see cref="DrawableHitObject"/> can be judged.
|
||||||
@ -160,14 +161,11 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
|
|
||||||
protected virtual void AddNested(DrawableHitObject h)
|
protected virtual void AddNested(DrawableHitObject h)
|
||||||
{
|
{
|
||||||
if (nestedHitObjects == null)
|
|
||||||
nestedHitObjects = new List<DrawableHitObject>();
|
|
||||||
|
|
||||||
h.OnJudgement += (d, j) => OnJudgement?.Invoke(d, j);
|
h.OnJudgement += (d, j) => OnJudgement?.Invoke(d, j);
|
||||||
h.OnJudgementRemoved += (d, j) => OnJudgementRemoved?.Invoke(d, j);
|
h.OnJudgementRemoved += (d, j) => OnJudgementRemoved?.Invoke(d, j);
|
||||||
h.ApplyCustomUpdateState += (d, j) => ApplyCustomUpdateState?.Invoke(d, j);
|
h.ApplyCustomUpdateState += (d, j) => ApplyCustomUpdateState?.Invoke(d, j);
|
||||||
|
|
||||||
nestedHitObjects.Add(h);
|
nestedHitObjects.Value.Add(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -211,7 +209,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
if (AllJudged)
|
if (AllJudged)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (NestedHitObjects != null)
|
if (HasNestedHitObjects)
|
||||||
foreach (var d in NestedHitObjects)
|
foreach (var d in NestedHitObjects)
|
||||||
judgementOccurred |= d.UpdateJudgement(userTriggered);
|
judgementOccurred |= d.UpdateJudgement(userTriggered);
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
|||||||
var controlPoint = controlPointAt(obj.HitObject.StartTime);
|
var controlPoint = controlPointAt(obj.HitObject.StartTime);
|
||||||
obj.LifetimeStart = obj.HitObject.StartTime - timeRange / controlPoint.Multiplier;
|
obj.LifetimeStart = obj.HitObject.StartTime - timeRange / controlPoint.Multiplier;
|
||||||
|
|
||||||
if (obj.NestedHitObjects != null)
|
if (obj.HasNestedHitObjects)
|
||||||
{
|
{
|
||||||
ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length);
|
ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length);
|
||||||
ComputePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length);
|
ComputePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length);
|
||||||
|
@ -46,7 +46,7 @@ namespace osu.Game.Rulesets.UI.Scrolling.Visualisers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (obj.NestedHitObjects != null)
|
if (obj.HasNestedHitObjects)
|
||||||
{
|
{
|
||||||
ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length);
|
ComputeInitialStates(obj.NestedHitObjects, direction, timeRange, length);
|
||||||
ComputePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length);
|
ComputePositions(obj.NestedHitObjects, direction, obj.HitObject.StartTime, timeRange, length);
|
||||||
|
Loading…
Reference in New Issue
Block a user