1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:47:52 +08:00

Initial implementation of the new (old) mania scrolling calculations

This commit is contained in:
smoogipoo 2018-01-05 20:17:02 +09:00
parent d2b135d2a8
commit 5d12682e83
2 changed files with 27 additions and 29 deletions

View File

@ -1,6 +1,7 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Lists;
@ -33,8 +34,8 @@ namespace osu.Game.Rulesets.UI.Scrolling
{
foreach (var obj in Objects)
{
obj.LifetimeStart = obj.HitObject.StartTime - TimeRange - 1000;
obj.LifetimeEnd = ((obj.HitObject as IHasEndTime)?.EndTime ?? obj.HitObject.StartTime + TimeRange) + 1000;
obj.LifetimeStart = obj.HitObject.StartTime - TimeRange * 2;
obj.LifetimeEnd = ((obj.HitObject as IHasEndTime)?.EndTime ?? obj.HitObject.StartTime) + TimeRange * 2;
}
return base.UpdateChildrenLife();
@ -47,27 +48,25 @@ namespace osu.Game.Rulesets.UI.Scrolling
// We need to calculate this as soon as possible after lifetimes so that hitobjects
// get the final say in their positions
var currentMultiplier = controlPointAt(Time.Current);
var timelinePosition = positionAt(Time.Current);
foreach (var obj in AliveObjects)
{
// Todo: We may need to consider scale here
var relativePosition = (Time.Current - obj.HitObject.StartTime) * currentMultiplier.Multiplier / TimeRange;
var finalPosition = (float)relativePosition * DrawSize;
var finalPosition = positionAt(obj.HitObject.StartTime);
switch (direction)
{
case ScrollingDirection.Up:
obj.Y = -finalPosition.Y;
obj.Y = finalPosition.Y - timelinePosition.Y;
break;
case ScrollingDirection.Down:
obj.Y = finalPosition.Y;
obj.Y = -finalPosition.Y + timelinePosition.Y;
break;
case ScrollingDirection.Left:
obj.X = -finalPosition.X;
obj.X = finalPosition.X - timelinePosition.X;
break;
case ScrollingDirection.Right:
obj.X = finalPosition.X;
obj.X = -finalPosition.X + timelinePosition.X;
break;
}
@ -75,8 +74,7 @@ namespace osu.Game.Rulesets.UI.Scrolling
continue;
// Todo: We may need to consider scale here
var relativeEndPosition = (Time.Current - endTime.EndTime) * currentMultiplier.Multiplier / TimeRange;
var finalEndPosition = (float)relativeEndPosition * DrawSize;
var finalEndPosition = positionAt(endTime.EndTime);
float length = Vector2.Distance(finalPosition, finalEndPosition);
@ -94,22 +92,24 @@ namespace osu.Game.Rulesets.UI.Scrolling
}
}
private readonly MultiplierControlPoint searchingPoint = new MultiplierControlPoint();
private MultiplierControlPoint controlPointAt(double time)
private Vector2 positionAt(double time)
{
if (ControlPoints.Count == 0)
return new MultiplierControlPoint(double.MinValue);
float length = 0;
for (int i = 0; i < ControlPoints.Count; i++)
{
var current = ControlPoints[i];
var next = i < ControlPoints.Count - 1 ? ControlPoints[i + 1] : null;
if (time < ControlPoints[0].StartTime)
return ControlPoints[0];
if (i > 0 && current.StartTime > time)
continue;
searchingPoint.StartTime = time;
// Duration of the current control point
var currentDuration = (next?.StartTime ?? double.PositiveInfinity) - current.StartTime;
int index = ControlPoints.BinarySearch(searchingPoint);
if (index < 0)
index = ~index - 1;
length += (float)(Math.Min(currentDuration, time - current.StartTime) * current.Multiplier / TimeRange);
}
return ControlPoints[index];
return length * DrawSize;
}
}
}

View File

@ -70,12 +70,10 @@ namespace osu.Game.Rulesets.UI.Scrolling
// Perform some post processing of the timing changes
timingChanges = timingChanges
// Collapse sections after the last hit object
.Where(s => s.StartTime <= lastObjectTime)
// Collapse sections with the same start time
.GroupBy(s => s.StartTime).Select(g => g.Last()).OrderBy(s => s.StartTime)
// Collapse sections with the same beat length
.GroupBy(s => s.TimingPoint.BeatLength * s.DifficultyPoint.SpeedMultiplier).Select(g => g.First());
// Collapse sections after the last hit object
.Where(s => s.StartTime <= lastObjectTime)
// Collapse sections with the same start time
.GroupBy(s => s.StartTime).Select(g => g.Last()).OrderBy(s => s.StartTime);
DefaultControlPoints.AddRange(timingChanges);