Skip to content

Commit

Permalink
Adjust code structure slightly
Browse files Browse the repository at this point in the history
  • Loading branch information
peppy committed Mar 20, 2024
1 parent 7ca45c7 commit fd509c8
Showing 1 changed file with 6 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ protected override void LoadBeatmap(EditorBeatmap beatmap)

controlPointGroups.UnbindAll();
controlPointGroups.BindTo(beatmap.ControlPointInfo.Groups);
controlPointGroups.BindCollectionChanged((_, _) =>
{
invalidateGroups();
}, true);
controlPointGroups.BindCollectionChanged((_, _) => groupCache.Invalidate(), true);
}

protected override void Update()
Expand All @@ -51,19 +48,20 @@ protected override void Update()
if (visibleRange != newRange)
{
visibleRange = newRange;
invalidateGroups();
groupCache.Invalidate();
}

if (!groupCache.IsValid)
{
recreateDrawableGroups();
groupCache.Validate();
}
}

private void invalidateGroups() => groupCache.Invalidate();

private void recreateDrawableGroups()
{
// Remove groups outside the visible range
foreach (var drawableGroup in this)
foreach (TimelineControlPointGroup drawableGroup in this)
{
if (!shouldBeVisible(drawableGroup.Group))
drawableGroup.Expire();
Expand Down Expand Up @@ -93,8 +91,6 @@ private void recreateDrawableGroups()

Add(new TimelineControlPointGroup(group));
}

groupCache.Validate();
}

private bool shouldBeVisible(ControlPointGroup group) => group.Time >= visibleRange.min && group.Time <= visibleRange.max;
Expand Down

0 comments on commit fd509c8

Please sign in to comment.