Skip to content

Commit

Permalink
Avoid doing expensive colour fetch operation every update
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Jun 19, 2023
1 parent aa96fef commit 0900ceb
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions osu.Game.Rulesets.Osu/Mods/OsuModSynesthesia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Screens.Edit;
using osuTK.Graphics;

namespace osu.Game.Rulesets.Osu.Mods
{
Expand All @@ -26,14 +27,20 @@ public void ApplyToBeatmap(IBeatmap beatmap)
currentBeatmap = beatmap;
}

public void ApplyToDrawableHitObject(DrawableHitObject drawable)
public void ApplyToDrawableHitObject(DrawableHitObject d)
{
if (currentBeatmap == null) return;

drawable.OnUpdate += _ =>
drawable.AccentColour.Value = BindableBeatDivisor.GetColourFor(
currentBeatmap.ControlPointInfo.GetClosestBeatDivisor(drawable.HitObject.StartTime),
colours);
Color4? timingBasedColour = null;

d.HitObjectApplied += _ => timingBasedColour = BindableBeatDivisor.GetColourFor(currentBeatmap.ControlPointInfo.GetClosestBeatDivisor(d.HitObject.StartTime), 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;
};
}
}
}

0 comments on commit 0900ceb

Please sign in to comment.