Skip to content

Commit

Permalink
Limit per-frame movement hitobject processing to stacking updates
Browse files Browse the repository at this point in the history
  • Loading branch information
bdach committed Jul 11, 2024
1 parent 38796aa commit 37a296b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
17 changes: 11 additions & 6 deletions osu.Game.Rulesets.Osu/Beatmaps/OsuBeatmapProcessor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,27 @@ public override void PostProcess()
{
base.PostProcess();

var hitObjects = Beatmap.HitObjects as List<OsuHitObject> ?? Beatmap.HitObjects.OfType<OsuHitObject>().ToList();
ApplyStacking(Beatmap);
}

internal static void ApplyStacking(IBeatmap beatmap)
{
var hitObjects = beatmap.HitObjects as List<OsuHitObject> ?? beatmap.HitObjects.OfType<OsuHitObject>().ToList();

if (hitObjects.Count > 0)
{
// Reset stacking
foreach (var h in hitObjects)
h.StackHeight = 0;

if (Beatmap.BeatmapInfo.BeatmapVersion >= 6)
applyStacking(Beatmap.BeatmapInfo, hitObjects, 0, hitObjects.Count - 1);
if (beatmap.BeatmapInfo.BeatmapVersion >= 6)
applyStacking(beatmap.BeatmapInfo, hitObjects, 0, hitObjects.Count - 1);
else
applyStackingOld(Beatmap.BeatmapInfo, hitObjects);
applyStackingOld(beatmap.BeatmapInfo, hitObjects);
}
}

private void applyStacking(BeatmapInfo beatmapInfo, List<OsuHitObject> hitObjects, int startIndex, int endIndex)
private static void applyStacking(BeatmapInfo beatmapInfo, List<OsuHitObject> hitObjects, int startIndex, int endIndex)
{
ArgumentOutOfRangeException.ThrowIfGreaterThan(startIndex, endIndex);
ArgumentOutOfRangeException.ThrowIfNegative(startIndex);
Expand Down Expand Up @@ -209,7 +214,7 @@ private void applyStacking(BeatmapInfo beatmapInfo, List<OsuHitObject> hitObject
}
}

private void applyStackingOld(BeatmapInfo beatmapInfo, List<OsuHitObject> hitObjects)
private static void applyStackingOld(BeatmapInfo beatmapInfo, List<OsuHitObject> hitObjects)
{
for (int i = 0; i < hitObjects.Count; i++)
{
Expand Down
9 changes: 5 additions & 4 deletions osu.Game.Rulesets.Osu/Edit/OsuSelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Game.Rulesets.Edit;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Game.Rulesets.Osu.Beatmaps;
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.UI;
using osu.Game.Screens.Edit.Compose.Components;
Expand Down Expand Up @@ -72,10 +73,10 @@ public override bool HandleMovement(MoveSelectionEvent<HitObject> moveEvent)
// but this will be corrected.
moveSelectionInBounds();

// update all of the objects in order to update stacking.
// in particular, this causes stacked objects to instantly unstack on drag.
foreach (var h in hitObjects)
EditorBeatmap.Update(h);
// manually update stacking.
// this intentionally bypasses the editor `UpdateState()` / beatmap processor flow for performance reasons,
// as the entire flow is too expensive to run on every movement.
Scheduler.AddOnce(OsuBeatmapProcessor.ApplyStacking, EditorBeatmap);

return true;
}
Expand Down

0 comments on commit 37a296b

Please sign in to comment.