2019-01-24 17:43:03 +09:00
|
|
|
|
// 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 18:19:50 +09:00
|
|
|
|
|
2020-10-09 20:50:09 +09:00
|
|
|
|
using System;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
2020-05-15 18:07:41 +09:00
|
|
|
|
using System.Threading;
|
2021-06-22 17:33:32 +09:00
|
|
|
|
using Newtonsoft.Json;
|
2023-04-26 17:55:38 +02:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Game.Audio;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2020-02-23 13:01:30 +09:00
|
|
|
|
using osu.Game.Rulesets.Judgements;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Game.Rulesets.Objects;
|
2023-12-11 14:39:50 +09:00
|
|
|
|
using osu.Game.Rulesets.Objects.Legacy;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
using osu.Game.Rulesets.Objects.Types;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Catch.Objects
|
|
|
|
|
{
|
2023-04-26 17:55:38 +02:00
|
|
|
|
public class JuiceStream : CatchHitObject, IHasPathWithRepeats, IHasSliderVelocity
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Positional distance that results in a duration of one second, before any speed adjustments.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const float base_scoring_distance = 100;
|
|
|
|
|
|
2020-02-23 13:01:30 +09:00
|
|
|
|
public override Judgement CreateJudgement() => new IgnoreJudgement();
|
|
|
|
|
|
2018-04-13 18:19:50 +09:00
|
|
|
|
public int RepeatCount { get; set; }
|
|
|
|
|
|
2023-09-06 18:59:15 +09:00
|
|
|
|
public BindableNumber<double> SliderVelocityMultiplierBindable { get; } = new BindableDouble(1)
|
2023-04-30 19:32:24 +02:00
|
|
|
|
{
|
|
|
|
|
MinValue = 0.1,
|
|
|
|
|
MaxValue = 10
|
|
|
|
|
};
|
2023-04-26 17:55:38 +02:00
|
|
|
|
|
2023-09-06 18:59:15 +09:00
|
|
|
|
public double SliderVelocityMultiplier
|
2023-04-26 17:55:38 +02:00
|
|
|
|
{
|
2023-09-06 18:59:15 +09:00
|
|
|
|
get => SliderVelocityMultiplierBindable.Value;
|
|
|
|
|
set => SliderVelocityMultiplierBindable.Value = value;
|
2023-04-26 17:55:38 +02:00
|
|
|
|
}
|
|
|
|
|
|
2023-12-05 15:09:55 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// An extra multiplier that affects the number of <see cref="Droplet"/>s generated by this <see cref="JuiceStream"/>.
|
|
|
|
|
/// An increase in this value increases <see cref="TickDistance"/>, which reduces the number of ticks generated.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double TickDistanceMultiplier = 1;
|
|
|
|
|
|
2021-06-22 17:33:32 +09:00
|
|
|
|
[JsonIgnore]
|
2023-12-11 14:39:50 +09:00
|
|
|
|
public double Velocity { get; private set; }
|
2021-06-22 17:33:32 +09:00
|
|
|
|
|
|
|
|
|
[JsonIgnore]
|
2023-12-11 14:39:50 +09:00
|
|
|
|
public double TickDistance { get; private set; }
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-03-08 19:57:30 +09:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The length of one span of this <see cref="JuiceStream"/>.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public double SpanDuration => Duration / this.SpanCount();
|
|
|
|
|
|
2021-10-01 14:56:42 +09:00
|
|
|
|
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
|
|
|
|
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
|
|
|
|
|
|
|
|
|
|
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
|
|
|
|
|
|
2023-12-11 14:39:50 +09:00
|
|
|
|
Velocity = base_scoring_distance * difficulty.SliderMultiplier / LegacyRulesetExtensions.GetPrecisionAdjustedBeatLength(this, timingPoint, CatchRuleset.SHORT_NAME);
|
|
|
|
|
|
|
|
|
|
// WARNING: this is intentionally not computed as `BASE_SCORING_DISTANCE * difficulty.SliderMultiplier`
|
|
|
|
|
// for backwards compatibility reasons (intentionally introducing floating point errors to match stable).
|
|
|
|
|
double scoringDistance = Velocity * timingPoint.BeatLength;
|
|
|
|
|
|
|
|
|
|
TickDistance = scoringDistance / difficulty.SliderTickRate * TickDistanceMultiplier;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
|
2020-05-15 18:07:41 +09:00
|
|
|
|
protected override void CreateNestedHitObjects(CancellationToken cancellationToken)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2020-05-15 18:07:41 +09:00
|
|
|
|
base.CreateNestedHitObjects(cancellationToken);
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2023-08-16 20:48:52 +02:00
|
|
|
|
this.PopulateNodeSamples();
|
|
|
|
|
|
2020-12-01 15:37:51 +09:00
|
|
|
|
var dropletSamples = Samples.Select(s => s.With(@"slidertick")).ToList();
|
2019-01-26 16:16:49 +09:00
|
|
|
|
|
2020-10-09 20:50:09 +09:00
|
|
|
|
int nodeIndex = 0;
|
2019-03-08 19:57:30 +09:00
|
|
|
|
SliderEventDescriptor? lastEvent = null;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2023-09-29 14:19:26 +09:00
|
|
|
|
foreach (var e in SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), cancellationToken))
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2019-03-08 19:57:30 +09:00
|
|
|
|
// generate tiny droplets since the last point
|
|
|
|
|
if (lastEvent != null)
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2023-12-05 11:57:51 +09:00
|
|
|
|
double sinceLastTick = (int)e.Time - (int)lastEvent.Value.Time;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-03-08 19:57:30 +09:00
|
|
|
|
if (sinceLastTick > 80)
|
2018-06-13 22:20:34 +09:00
|
|
|
|
{
|
2019-03-08 19:57:30 +09:00
|
|
|
|
double timeBetweenTiny = sinceLastTick;
|
|
|
|
|
while (timeBetweenTiny > 100)
|
|
|
|
|
timeBetweenTiny /= 2;
|
2018-06-13 22:20:34 +09:00
|
|
|
|
|
2019-03-08 19:57:30 +09:00
|
|
|
|
for (double t = timeBetweenTiny; t < sinceLastTick; t += timeBetweenTiny)
|
|
|
|
|
{
|
2020-05-15 18:17:39 +09:00
|
|
|
|
cancellationToken.ThrowIfCancellationRequested();
|
|
|
|
|
|
2019-03-08 19:57:30 +09:00
|
|
|
|
AddNested(new TinyDroplet
|
|
|
|
|
{
|
2019-03-11 14:36:29 +09:00
|
|
|
|
StartTime = t + lastEvent.Value.Time,
|
2023-12-11 21:52:39 +09:00
|
|
|
|
X = EffectiveX + Path.PositionAt(lastEvent.Value.PathProgress + (t / sinceLastTick) * (e.PathProgress - lastEvent.Value.PathProgress)).X,
|
2019-03-08 19:57:30 +09:00
|
|
|
|
});
|
|
|
|
|
}
|
2019-01-26 16:14:37 +09:00
|
|
|
|
}
|
2019-03-08 19:57:30 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2023-09-29 14:40:44 +09:00
|
|
|
|
// this also includes LastTick and this is used for TinyDroplet generation above.
|
|
|
|
|
// this means that the final segment of TinyDroplets are increasingly mistimed where LastTick is being applied.
|
2019-03-08 19:57:30 +09:00
|
|
|
|
lastEvent = e;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-03-08 19:57:30 +09:00
|
|
|
|
switch (e.Type)
|
|
|
|
|
{
|
|
|
|
|
case SliderEventType.Tick:
|
|
|
|
|
AddNested(new Droplet
|
2018-04-13 18:19:50 +09:00
|
|
|
|
{
|
2020-03-10 18:05:44 +09:00
|
|
|
|
Samples = dropletSamples,
|
2019-03-11 14:36:29 +09:00
|
|
|
|
StartTime = e.Time,
|
2023-12-11 21:52:39 +09:00
|
|
|
|
X = EffectiveX + Path.PositionAt(e.PathProgress).X,
|
2019-03-08 19:57:30 +09:00
|
|
|
|
});
|
|
|
|
|
break;
|
2019-04-01 12:44:46 +09:00
|
|
|
|
|
2019-03-08 19:57:30 +09:00
|
|
|
|
case SliderEventType.Head:
|
|
|
|
|
case SliderEventType.Tail:
|
|
|
|
|
case SliderEventType.Repeat:
|
|
|
|
|
AddNested(new Fruit
|
|
|
|
|
{
|
2020-10-09 20:50:09 +09:00
|
|
|
|
Samples = this.GetNodeSamples(nodeIndex++),
|
2019-03-11 14:36:29 +09:00
|
|
|
|
StartTime = e.Time,
|
2023-12-11 21:52:39 +09:00
|
|
|
|
X = EffectiveX + Path.PositionAt(e.PathProgress).X,
|
2018-04-13 18:19:50 +09:00
|
|
|
|
});
|
2019-01-21 17:53:00 +09:00
|
|
|
|
break;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-12-11 21:52:39 +09:00
|
|
|
|
public float EndX => EffectiveX + this.CurvePositionAt(1).X;
|
2020-05-27 12:37:44 +09:00
|
|
|
|
|
2021-06-22 17:33:32 +09:00
|
|
|
|
[JsonIgnore]
|
2020-05-27 12:37:44 +09:00
|
|
|
|
public double Duration
|
2020-02-05 17:12:26 +09:00
|
|
|
|
{
|
2020-05-27 12:37:44 +09:00
|
|
|
|
get => this.SpanCount() * Path.Distance / Velocity;
|
2020-10-09 20:50:09 +09:00
|
|
|
|
set => throw new NotSupportedException($"Adjust via {nameof(RepeatCount)} instead"); // can be implemented if/when needed.
|
2020-02-05 17:12:26 +09:00
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2020-05-27 12:37:44 +09:00
|
|
|
|
public double EndTime => StartTime + Duration;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2019-12-09 17:48:27 +09:00
|
|
|
|
private readonly SliderPath path = new SliderPath();
|
2019-12-06 20:53:40 +09:00
|
|
|
|
|
|
|
|
|
public SliderPath Path
|
|
|
|
|
{
|
|
|
|
|
get => path;
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
path.ControlPoints.Clear();
|
2023-01-15 16:23:45 +09:00
|
|
|
|
path.ControlPoints.AddRange(value.ControlPoints.Select(c => new PathControlPoint(c.Position, c.Type)));
|
|
|
|
|
path.ExpectedDistance.Value = value.ExpectedDistance.Value;
|
2019-12-06 20:53:40 +09:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2018-11-12 14:07:48 +09:00
|
|
|
|
public double Distance => Path.Distance;
|
2018-04-13 18:19:50 +09:00
|
|
|
|
|
2021-10-23 01:59:07 -07:00
|
|
|
|
public IList<IList<HitSampleInfo>> NodeSamples { get; set; } = new List<IList<HitSampleInfo>>();
|
2018-04-13 18:19:50 +09:00
|
|
|
|
}
|
|
|
|
|
}
|