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

View File

@ -73,9 +73,7 @@ namespace osu.Game.Rulesets.UI.Scrolling
// Collapse sections after the last hit object // Collapse sections after the last hit object
.Where(s => s.StartTime <= lastObjectTime) .Where(s => s.StartTime <= lastObjectTime)
// Collapse sections with the same start time // Collapse sections with the same start time
.GroupBy(s => s.StartTime).Select(g => g.Last()).OrderBy(s => s.StartTime) .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());
DefaultControlPoints.AddRange(timingChanges); DefaultControlPoints.AddRange(timingChanges);