mirror of
https://github.com/ppy/osu.git
synced 2025-01-12 22:33:05 +08:00
Reduce allocations in DrawableSpinner
This commit is contained in:
parent
28917446ab
commit
1fb19e7129
@ -279,10 +279,9 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
if (HandleUserInput)
|
if (HandleUserInput)
|
||||||
{
|
{
|
||||||
bool isValidSpinningTime = Time.Current >= HitObject.StartTime && Time.Current <= HitObject.EndTime;
|
bool isValidSpinningTime = Time.Current >= HitObject.StartTime && Time.Current <= HitObject.EndTime;
|
||||||
bool correctButtonPressed = (OsuActionInputManager?.PressedActions.Any(x => x == OsuAction.LeftButton || x == OsuAction.RightButton) ?? false);
|
|
||||||
|
|
||||||
RotationTracker.Tracking = !Result.HasResult
|
RotationTracker.Tracking = !Result.HasResult
|
||||||
&& correctButtonPressed
|
&& correctButtonPressed()
|
||||||
&& isValidSpinningTime;
|
&& isValidSpinningTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -292,11 +291,34 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
|||||||
// Ticks can theoretically be judged at any point in the spinner's duration.
|
// Ticks can theoretically be judged at any point in the spinner's duration.
|
||||||
// A tick must be alive to correctly play back samples,
|
// A tick must be alive to correctly play back samples,
|
||||||
// but for performance reasons, we only want to keep the next tick alive.
|
// but for performance reasons, we only want to keep the next tick alive.
|
||||||
var next = NestedHitObjects.FirstOrDefault(h => !h.Judged);
|
DrawableHitObject nextTick = null;
|
||||||
|
|
||||||
|
foreach (var nested in NestedHitObjects)
|
||||||
|
{
|
||||||
|
if (!nested.Judged)
|
||||||
|
{
|
||||||
|
nextTick = nested;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// See default `LifetimeStart` as set in `DrawableSpinnerTick`.
|
// See default `LifetimeStart` as set in `DrawableSpinnerTick`.
|
||||||
if (next?.LifetimeStart == double.MaxValue)
|
if (nextTick?.LifetimeStart == double.MaxValue)
|
||||||
next.LifetimeStart = HitObject.StartTime;
|
nextTick.LifetimeStart = HitObject.StartTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool correctButtonPressed()
|
||||||
|
{
|
||||||
|
if (OsuActionInputManager == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
foreach (var action in OsuActionInputManager.PressedActions)
|
||||||
|
{
|
||||||
|
if (action == OsuAction.LeftButton || action == OsuAction.RightButton)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void UpdateAfterChildren()
|
protected override void UpdateAfterChildren()
|
||||||
|
@ -11,10 +11,12 @@ using System.Linq;
|
|||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Extensions.ListExtensions;
|
||||||
using osu.Framework.Extensions.ObjectExtensions;
|
using osu.Framework.Extensions.ObjectExtensions;
|
||||||
using osu.Framework.Extensions.TypeExtensions;
|
using osu.Framework.Extensions.TypeExtensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
|
using osu.Framework.Lists;
|
||||||
using osu.Framework.Threading;
|
using osu.Framework.Threading;
|
||||||
using osu.Framework.Utils;
|
using osu.Framework.Utils;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
@ -65,7 +67,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
|
|||||||
public virtual IEnumerable<HitSampleInfo> GetSamples() => HitObject.Samples;
|
public virtual IEnumerable<HitSampleInfo> GetSamples() => HitObject.Samples;
|
||||||
|
|
||||||
private readonly List<DrawableHitObject> nestedHitObjects = new List<DrawableHitObject>();
|
private readonly List<DrawableHitObject> nestedHitObjects = new List<DrawableHitObject>();
|
||||||
public IReadOnlyList<DrawableHitObject> NestedHitObjects => nestedHitObjects;
|
public SlimReadOnlyListWrapper<DrawableHitObject> NestedHitObjects => nestedHitObjects.AsSlimReadOnly();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Whether this object should handle any user input events.
|
/// Whether this object should handle any user input events.
|
||||||
|
Loading…
Reference in New Issue
Block a user