Avoid doing expensive colour fetch operation every update

This commit is contained in:
Dean Herbert 2023-06-19 20:09:53 +09:00
parent aa96fefae2
commit 0900cebc0d
1 changed files with 12 additions and 5 deletions

View File

@ -7,6 +7,7 @@
using osu.Game.Rulesets.Objects; using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Screens.Edit; using osu.Game.Screens.Edit;
using osuTK.Graphics;
namespace osu.Game.Rulesets.Osu.Mods namespace osu.Game.Rulesets.Osu.Mods
{ {
@ -26,14 +27,20 @@ public void ApplyToBeatmap(IBeatmap beatmap)
currentBeatmap = beatmap; currentBeatmap = beatmap;
} }
public void ApplyToDrawableHitObject(DrawableHitObject drawable) public void ApplyToDrawableHitObject(DrawableHitObject d)
{ {
if (currentBeatmap == null) return; if (currentBeatmap == null) return;
drawable.OnUpdate += _ => Color4? timingBasedColour = null;
drawable.AccentColour.Value = BindableBeatDivisor.GetColourFor(
currentBeatmap.ControlPointInfo.GetClosestBeatDivisor(drawable.HitObject.StartTime), d.HitObjectApplied += _ => timingBasedColour = BindableBeatDivisor.GetColourFor(currentBeatmap.ControlPointInfo.GetClosestBeatDivisor(d.HitObject.StartTime), colours);
colours);
// Need to set this every update to ensure it doesn't get overwritten by DrawableHitObject.OnApply() -> UpdateComboColour().
d.OnUpdate += _ =>
{
if (timingBasedColour != null)
d.AccentColour.Value = timingBasedColour.Value;
};
} }
} }
} }