1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 21:32:55 +08:00

Fix legacy tick handling

This commit is contained in:
Dean Herbert 2019-03-08 19:57:30 +09:00
parent 973f29b765
commit 355705f0a5
3 changed files with 75 additions and 89 deletions

View File

@ -1,7 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Game.Audio; using osu.Game.Audio;
@ -25,6 +24,11 @@ namespace osu.Game.Rulesets.Catch.Objects
public double Velocity; public double Velocity;
public double TickDistance; public double TickDistance;
/// <summary>
/// The length of one span of this <see cref="JuiceStream"/>.
/// </summary>
public double SpanDuration => Duration / this.SpanCount();
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty) protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, BeatmapDifficulty difficulty)
{ {
base.ApplyDefaultsToSelf(controlPointInfo, difficulty); base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
@ -41,19 +45,6 @@ namespace osu.Game.Rulesets.Catch.Objects
protected override void CreateNestedHitObjects() protected override void CreateNestedHitObjects()
{ {
base.CreateNestedHitObjects(); base.CreateNestedHitObjects();
createTicks();
}
private void createTicks()
{
if (TickDistance == 0)
return;
var length = Path.Distance;
var tickDistance = Math.Min(TickDistance, length);
var spanDuration = length / Velocity;
var minDistanceFromEnd = Velocity * 0.01;
var tickSamples = Samples.Select(s => new SampleInfo var tickSamples = Samples.Select(s => new SampleInfo
{ {
@ -62,81 +53,57 @@ namespace osu.Game.Rulesets.Catch.Objects
Volume = s.Volume Volume = s.Volume
}).ToList(); }).ToList();
AddNested(new Fruit SliderEventDescriptor? lastEvent = null;
foreach (var e in SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), LegacyLastTickOffset))
{ {
Samples = Samples, // generate tiny droplets since the last point
StartTime = StartTime, if (lastEvent != null)
X = X
});
double lastTickTime = StartTime;
for (int span = 0; span < this.SpanCount(); span++)
{
var spanStartTime = StartTime + span * spanDuration;
var reversed = span % 2 == 1;
for (double d = tickDistance;; d += tickDistance)
{ {
bool isLastTick = false; double sinceLastTick = e.StartTime - lastEvent.Value.StartTime;
if (d + minDistanceFromEnd >= length)
if (sinceLastTick > 80)
{ {
d = length; double timeBetweenTiny = sinceLastTick;
isLastTick = true; while (timeBetweenTiny > 100)
} timeBetweenTiny /= 2;
var timeProgress = d / length; for (double t = timeBetweenTiny; t < sinceLastTick; t += timeBetweenTiny)
var distanceProgress = reversed ? 1 - timeProgress : timeProgress;
double time = spanStartTime + timeProgress * spanDuration;
if (LegacyLastTickOffset != null)
{
// If we're the last tick, apply the legacy offset
if (span == this.SpanCount() - 1 && isLastTick)
time = Math.Max(StartTime + Duration / 2, time - LegacyLastTickOffset.Value);
}
int tinyTickCount = 1;
double tinyTickInterval = time - lastTickTime;
while (tinyTickInterval > 100 && tinyTickCount < 10000)
{
tinyTickInterval /= 2;
tinyTickCount *= 2;
}
for (int tinyTickIndex = 0; tinyTickIndex < tinyTickCount - 1; tinyTickIndex++)
{
var t = lastTickTime + (tinyTickIndex + 1) * tinyTickInterval;
double progress = reversed ? 1 - (t - spanStartTime) / spanDuration : (t - spanStartTime) / spanDuration;
AddNested(new TinyDroplet
{ {
StartTime = t, AddNested(new TinyDroplet
X = X + Path.PositionAt(progress).X / CatchPlayfield.BASE_WIDTH, {
Samples = tickSamples Samples = tickSamples,
}); StartTime = t + lastEvent.Value.StartTime,
X = X + Path.PositionAt(
lastEvent.Value.PathProgress + (t / sinceLastTick) * (e.PathProgress - lastEvent.Value.PathProgress)).X / CatchPlayfield.BASE_WIDTH,
});
}
} }
lastTickTime = time;
if (isLastTick)
break;
AddNested(new Droplet
{
StartTime = time,
X = X + Path.PositionAt(distanceProgress).X / CatchPlayfield.BASE_WIDTH,
Samples = tickSamples
});
} }
AddNested(new Fruit lastEvent = e;
switch (e.Type)
{ {
Samples = Samples, case SliderEventType.Tick:
StartTime = spanStartTime + spanDuration, AddNested(new Droplet
X = X + Path.PositionAt(reversed ? 0 : 1).X / CatchPlayfield.BASE_WIDTH {
}); Samples = tickSamples,
StartTime = e.StartTime,
X = X + Path.PositionAt(e.PathProgress).X / CatchPlayfield.BASE_WIDTH,
});
break;
case SliderEventType.Head:
case SliderEventType.Tail:
case SliderEventType.Repeat:
AddNested(new Fruit
{
Samples = Samples,
StartTime = e.StartTime,
X = X + Path.PositionAt(e.PathProgress).X / CatchPlayfield.BASE_WIDTH,
});
break;
}
} }
} }

View File

@ -194,7 +194,7 @@ namespace osu.Game.Rulesets.Osu.Objects
ComboIndex = ComboIndex, ComboIndex = ComboIndex,
}); });
break; break;
case SliderEventType.Tail: case SliderEventType.LegacyFinalTick:
AddNested(TailCircle = new SliderTailCircle(this) AddNested(TailCircle = new SliderTailCircle(this)
{ {
StartTime = e.StartTime, StartTime = e.StartTime,

View File

@ -61,7 +61,7 @@ namespace osu.Game.Rulesets.Objects
Type = SliderEventType.Repeat, Type = SliderEventType.Repeat,
SpanIndex = span, SpanIndex = span,
SpanStartTime = startTime + span * spanDuration, SpanStartTime = startTime + span * spanDuration,
StartTime = spanStartTime + (span + 1) * spanDuration, StartTime = spanStartTime + spanDuration,
PathProgress = (span + 1) % 2, PathProgress = (span + 1) % 2,
}; };
} }
@ -70,19 +70,37 @@ namespace osu.Game.Rulesets.Objects
double totalDuration = spanCount * spanDuration; double totalDuration = spanCount * spanDuration;
var tail = new SliderEventDescriptor // Okay, I'll level with you. I made a mistake. It was 2007.
// Times were simpler. osu! was but in its infancy and sliders were a new concept.
// A hack was made, which has unfortunately lived through until this day.
//
// This legacy tick is used for some calculations and judgements where audio output is not required.
// Generally we are keeping this around just for difficulty compatibility.
// Optimistically we do not want to ever use this for anything user-facing going forwards.
int finalSpanIndex = spanCount - 1;
double finalSpanStartTime = startTime + finalSpanIndex * spanDuration;
double finalSpanTime = Math.Max(startTime + totalDuration / 2, (finalSpanStartTime + spanDuration) - (legacyLastTickOffset ?? 0));
double finalProgress = (finalSpanTime - finalSpanStartTime) / spanDuration;
if (spanCount % 2 == 0) finalProgress = 1 - finalProgress;
yield return new SliderEventDescriptor
{
Type = SliderEventType.LegacyFinalTick,
SpanIndex = finalSpanIndex,
SpanStartTime = finalSpanStartTime,
StartTime = finalSpanTime,
PathProgress = finalProgress,
};
yield return new SliderEventDescriptor
{ {
Type = SliderEventType.Tail, Type = SliderEventType.Tail,
SpanIndex = spanCount - 1, SpanIndex = spanCount - 1,
SpanStartTime = startTime + (spanCount - 1) * spanDuration, SpanStartTime = startTime + (spanCount - 1) * spanDuration,
StartTime = startTime + totalDuration, StartTime = startTime + totalDuration,
PathProgress = 1, PathProgress = spanCount % 2,
}; };
if (legacyLastTickOffset != null)
tail.StartTime = Math.Max(startTime + totalDuration / 2, tail.StartTime - legacyLastTickOffset.Value);
yield return tail;
} }
} }
@ -102,6 +120,7 @@ namespace osu.Game.Rulesets.Objects
public enum SliderEventType public enum SliderEventType
{ {
Tick, Tick,
LegacyFinalTick,
Head, Head,
Tail, Tail,
Repeat Repeat