osu/osu.Game.Rulesets.Mania/Replays/ManiaAutoGenerator.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

121 lines
3.9 KiB
C#
Raw Normal View History

// 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.
2018-04-13 09:19:50 +00:00
using System.Collections.Generic;
using System.Linq;
2022-07-02 11:48:32 +00:00
using osu.Framework.Extensions.ObjectExtensions;
using osu.Game.Rulesets.Mania.Beatmaps;
using osu.Game.Rulesets.Mania.Objects;
2019-08-19 14:18:25 +00:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Replays;
2018-04-13 09:19:50 +00:00
namespace osu.Game.Rulesets.Mania.Replays
{
internal class ManiaAutoGenerator : AutoGenerator<ManiaReplayFrame>
{
public const double RELEASE_DELAY = 20;
2018-04-13 09:19:50 +00:00
public new ManiaBeatmap Beatmap => (ManiaBeatmap)base.Beatmap;
2018-04-13 09:19:50 +00:00
public ManiaAutoGenerator(ManiaBeatmap beatmap)
: base(beatmap)
{
}
2018-04-13 09:19:50 +00:00
protected override void GenerateFrames()
{
if (Beatmap.HitObjects.Count == 0)
return;
var pointGroups = generateActionPoints().GroupBy(a => a.Time).OrderBy(g => g.First().Time);
2018-04-13 09:19:50 +00:00
var actions = new List<ManiaAction>();
2019-04-01 03:16:05 +00:00
foreach (var group in pointGroups)
{
foreach (var point in group)
{
switch (point)
{
2022-06-24 12:25:23 +00:00
case HitPoint:
2024-08-13 05:03:26 +00:00
actions.Add(ManiaAction.Key1 + point.Column);
break;
2019-04-01 03:16:05 +00:00
2022-06-24 12:25:23 +00:00
case ReleasePoint:
2024-08-13 05:03:26 +00:00
actions.Remove(ManiaAction.Key1 + point.Column);
break;
}
}
2018-04-13 09:19:50 +00:00
Frames.Add(new ManiaReplayFrame(group.First().Time, actions.ToArray()));
}
}
2018-04-13 09:19:50 +00:00
private IEnumerable<IActionPoint> generateActionPoints()
2017-09-12 07:10:31 +00:00
{
for (int i = 0; i < Beatmap.HitObjects.Count; i++)
2017-09-12 07:10:31 +00:00
{
var currentObject = Beatmap.HitObjects[i];
2019-08-19 18:45:23 +00:00
var nextObjectInColumn = GetNextObject(i); // Get the next object that requires pressing the same button
double releaseTime = calculateReleaseTime(currentObject, nextObjectInColumn);
yield return new HitPoint { Time = currentObject.StartTime, Column = currentObject.Column };
yield return new ReleasePoint { Time = releaseTime, Column = currentObject.Column };
}
}
private double calculateReleaseTime(HitObject currentObject, HitObject? nextObject)
{
double endTime = currentObject.GetEndTime();
double releaseDelay = RELEASE_DELAY;
if (currentObject is HoldNote hold)
{
if (hold.Duration > 0)
// hold note releases must be timed exactly.
return endTime;
// Special case for super short hold notes
releaseDelay = 1;
}
bool canDelayKeyUpFully = nextObject == null ||
nextObject.StartTime > endTime + releaseDelay;
return endTime + (canDelayKeyUpFully ? releaseDelay : (nextObject.AsNonNull().StartTime - endTime) * 0.9);
2019-08-19 14:18:25 +00:00
}
protected override HitObject? GetNextObject(int currentIndex)
2019-08-19 14:18:25 +00:00
{
2019-08-26 08:45:12 +00:00
int desiredColumn = Beatmap.HitObjects[currentIndex].Column;
2019-08-26 08:45:12 +00:00
for (int i = currentIndex + 1; i < Beatmap.HitObjects.Count; i++)
2019-08-19 14:18:25 +00:00
{
2019-08-26 08:45:12 +00:00
if (Beatmap.HitObjects[i].Column == desiredColumn)
return Beatmap.HitObjects[i];
2017-09-12 07:10:31 +00:00
}
2019-08-19 14:18:25 +00:00
return null;
}
2018-04-13 09:19:50 +00:00
private interface IActionPoint
{
double Time { get; set; }
int Column { get; set; }
2017-09-12 07:10:31 +00:00
}
2018-04-13 09:19:50 +00:00
private struct HitPoint : IActionPoint
2017-09-12 07:10:31 +00:00
{
public double Time { get; set; }
public int Column { get; set; }
}
2018-04-13 09:19:50 +00:00
private struct ReleasePoint : IActionPoint
{
public double Time { get; set; }
public int Column { get; set; }
2017-09-12 07:10:31 +00:00
}
}
}