1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-01 13:42:55 +08:00
osu-lazer/osu.Game/Screens/Edit/EditorBeatmapProcessor.cs
Bartłomiej Dach c93b87583a
Force new combo on objects succeeding a break
No issue thread for this again. Reported internally on discord:
https://discord.com/channels/90072389919997952/1259818301517725707/1320420768814727229

Placing this logic in the beatmap processor, as a post-processing step,
means that the new combo force won't be visible until a placement has
been committed. That can be seen as subpar, but I tried putting this
logic in the placement and it sucked anyway:

- While the combo number was correct, the colour looked off, because it
  would use the same combo colour as the already-placed objects after
  said break, which would only cycle to the next, correct one on
  placement

- Not all scenarios can be handled in the placement. Refer to one of the
  test cases added in the preceding commit, wherein two objects are
  placed far apart from each other, and an automated break is inserted
  between them - the placement has no practical way of knowing whether
  it's going to have a break inserted automatically before it or not.
2025-01-07 14:06:23 +01:00

132 lines
4.7 KiB
C#

// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Timing;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Screens.Edit
{
public class EditorBeatmapProcessor : IBeatmapProcessor
{
public EditorBeatmap Beatmap { get; }
IBeatmap IBeatmapProcessor.Beatmap => Beatmap;
private readonly IBeatmapProcessor? rulesetBeatmapProcessor;
/// <summary>
/// Kept for the purposes of reducing redundant regeneration of automatic breaks.
/// </summary>
private HashSet<(double, double)> objectDurationCache = new HashSet<(double, double)>();
public EditorBeatmapProcessor(EditorBeatmap beatmap, Ruleset ruleset)
{
Beatmap = beatmap;
rulesetBeatmapProcessor = ruleset.CreateBeatmapProcessor(beatmap);
}
public void PreProcess()
{
rulesetBeatmapProcessor?.PreProcess();
}
public void PostProcess()
{
rulesetBeatmapProcessor?.PostProcess();
autoGenerateBreaks();
ensureNewComboAfterBreaks();
}
private void autoGenerateBreaks()
{
var objectDuration = Beatmap.HitObjects.Select(ho => (ho.StartTime - ((ho as IHasTimePreempt)?.TimePreempt ?? 0), ho.GetEndTime())).ToHashSet();
if (objectDuration.SetEquals(objectDurationCache))
return;
objectDurationCache = objectDuration;
Beatmap.Breaks.RemoveAll(b => b is not ManualBreakPeriod);
foreach (var manualBreak in Beatmap.Breaks.ToList())
{
if (manualBreak.EndTime <= Beatmap.HitObjects.FirstOrDefault()?.StartTime
|| manualBreak.StartTime >= Beatmap.GetLastObjectTime()
|| Beatmap.HitObjects.Any(ho => ho.StartTime <= manualBreak.EndTime && ho.GetEndTime() >= manualBreak.StartTime))
{
Beatmap.Breaks.Remove(manualBreak);
}
}
double currentMaxEndTime = double.MinValue;
for (int i = 1; i < Beatmap.HitObjects.Count; ++i)
{
var previousObject = Beatmap.HitObjects[i - 1];
var nextObject = Beatmap.HitObjects[i];
// Keep track of the maximum end time encountered thus far.
// This handles cases like osu!mania's hold notes, which could have concurrent other objects after their start time.
// Note that we're relying on the implicit assumption that objects are sorted by start time,
// which is why similar tracking is not done for start time.
currentMaxEndTime = Math.Max(currentMaxEndTime, previousObject.GetEndTime());
if (nextObject.StartTime - currentMaxEndTime < BreakPeriod.MIN_GAP_DURATION)
continue;
double breakStartTime = currentMaxEndTime + BreakPeriod.GAP_BEFORE_BREAK;
double breakEndTime = nextObject.StartTime;
if (nextObject is IHasTimePreempt hasTimePreempt)
breakEndTime -= hasTimePreempt.TimePreempt;
else
breakEndTime -= Math.Max(BreakPeriod.GAP_AFTER_BREAK, Beatmap.ControlPointInfo.TimingPointAt(nextObject.StartTime).BeatLength * 2);
if (breakEndTime - breakStartTime < BreakPeriod.MIN_BREAK_DURATION)
continue;
var breakPeriod = new BreakPeriod(breakStartTime, breakEndTime);
if (Beatmap.Breaks.Any(b => b.Intersects(breakPeriod)))
continue;
Beatmap.Breaks.Add(breakPeriod);
}
}
private void ensureNewComboAfterBreaks()
{
var breakEnds = Beatmap.Breaks.Select(b => b.EndTime).OrderBy(t => t).ToList();
if (breakEnds.Count == 0)
return;
int currentBreak = 0;
for (int i = 0; i < Beatmap.HitObjects.Count; ++i)
{
var hitObject = Beatmap.HitObjects[i];
if (hitObject is not IHasComboInformation hasCombo)
continue;
if (currentBreak < breakEnds.Count && hitObject.StartTime >= breakEnds[currentBreak])
{
hasCombo.NewCombo = true;
currentBreak += 1;
}
hasCombo.UpdateComboInformation(i > 0 ? Beatmap.HitObjects[i - 1] as IHasComboInformation : null);
}
}
}
}