Simplify/sanitize construction of ManiaReplayFrame

This commit is contained in:
smoogipoo 2017-11-29 15:47:10 +09:00
parent 1136db1556
commit 6fd550dc91
2 changed files with 7 additions and 7 deletions

View File

@ -30,7 +30,7 @@ public ManiaAutoGenerator(Beatmap<ManiaHitObject> beatmap, int availableColumns)
public override Replay Generate()
{
// Todo: Realistically this shouldn't be needed, but the first frame is skipped with the way replays are currently handled
Replay.Frames.Add(new ManiaReplayFrame(-100000, null, null, ReplayButtonState.None));
Replay.Frames.Add(new ManiaReplayFrame(-100000, 0));
double[] holdEndTimes = new double[availableColumns];
for (int i = 0; i < availableColumns; i++)
@ -60,7 +60,7 @@ public override Replay Generate()
activeColumns |= 1 << obj.Column;
}
Replay.Frames.Add(new ManiaReplayFrame(groupTime, activeColumns, null, ReplayButtonState.None));
Replay.Frames.Add(new ManiaReplayFrame(groupTime, activeColumns));
// Add the release frames. We can't do this with the loop above because we need activeColumns to be fully populated
foreach (var obj in objGroup.GroupBy(h => (h as IHasEndTime)?.EndTime ?? h.StartTime + release_delay).OrderBy(h => h.Key))
@ -74,14 +74,14 @@ public override Replay Generate()
activeColumnsAtEnd |= 1 << i;
}
Replay.Frames.Add(new ManiaReplayFrame(groupEndTime, activeColumnsAtEnd, 0, ReplayButtonState.None));
Replay.Frames.Add(new ManiaReplayFrame(groupEndTime, activeColumnsAtEnd));
}
}
Replay.Frames = Replay.Frames
// Pick the maximum activeColumns for all frames at the same time
.GroupBy(f => f.Time)
.Select(g => new ManiaReplayFrame(g.First().Time, maxMouseX(g), 0, ReplayButtonState.None))
.Select(g => new ManiaReplayFrame(g.First().Time, maxMouseX(g)))
.Cast<ReplayFrame>()
// The addition of release frames above maybe result in unordered frames, but we need them ordered
.OrderBy(f => f.Time)
@ -95,7 +95,7 @@ public override Replay Generate()
/// </summary>
/// <param name="group">The <see cref="ReplayFrame"/> grouping to search.</param>
/// <returns>The maximum <see cref="ReplayFrame.MouseX"/> by count of bits.</returns>
private float maxMouseX(IGrouping<double, ReplayFrame> group)
private int maxMouseX(IGrouping<double, ReplayFrame> group)
{
int currentCount = -1;
int currentMax = 0;

View File

@ -9,8 +9,8 @@ public class ManiaReplayFrame : ReplayFrame
{
public override bool IsImportant => MouseX > 0;
public ManiaReplayFrame(double time, float? mouseX, float? mouseY, ReplayButtonState buttonState)
: base(time, mouseX, mouseY, buttonState)
public ManiaReplayFrame(double time, int activeColumns)
: base(time, (float)activeColumns, null, ReplayButtonState.None)
{
}
}