1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-29 16:02:55 +08:00
osu-lazer/osu.Game.Rulesets.Catch/Objects/JuiceStream.cs

169 lines
6.3 KiB
C#
Raw Normal View History

// 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 17:19:50 +08:00
using System;
2018-04-13 17:19:50 +08:00
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using Newtonsoft.Json;
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
using osu.Game.Audio;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Rulesets.Judgements;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
namespace osu.Game.Rulesets.Catch.Objects
{
public class JuiceStream : CatchHitObject, IHasPathWithRepeats, IHasSliderVelocity
2018-04-13 17:19:50 +08:00
{
/// <summary>
/// Positional distance that results in a duration of one second, before any speed adjustments.
/// </summary>
private const float base_scoring_distance = 100;
public override Judgement CreateJudgement() => new IgnoreJudgement();
2018-04-13 17:19:50 +08:00
public int RepeatCount { get; set; }
public BindableNumber<double> SliderVelocityMultiplierBindable { get; } = new BindableDouble(1)
{
Precision = 0.01,
MinValue = 0.1,
MaxValue = 10
};
public double SliderVelocityMultiplier
{
get => SliderVelocityMultiplierBindable.Value;
set => SliderVelocityMultiplierBindable.Value = value;
}
/// <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;
[JsonIgnore]
private double velocityFactor;
[JsonIgnore]
private double tickDistanceFactor;
[JsonIgnore]
public double Velocity => velocityFactor * SliderVelocityMultiplier;
[JsonIgnore]
public double TickDistance => tickDistanceFactor * TickDistanceMultiplier;
2018-04-13 17:19:50 +08:00
2019-03-08 18:57:30 +08:00
/// <summary>
/// The length of one span of this <see cref="JuiceStream"/>.
/// </summary>
public double SpanDuration => Duration / this.SpanCount();
protected override void ApplyDefaultsToSelf(ControlPointInfo controlPointInfo, IBeatmapDifficultyInfo difficulty)
2018-04-13 17:19:50 +08:00
{
base.ApplyDefaultsToSelf(controlPointInfo, difficulty);
TimingControlPoint timingPoint = controlPointInfo.TimingPointAt(StartTime);
velocityFactor = base_scoring_distance * difficulty.SliderMultiplier / timingPoint.BeatLength;
tickDistanceFactor = base_scoring_distance * difficulty.SliderMultiplier / difficulty.SliderTickRate;
2018-04-13 17:19:50 +08:00
}
protected override void CreateNestedHitObjects(CancellationToken cancellationToken)
2018-04-13 17:19:50 +08:00
{
base.CreateNestedHitObjects(cancellationToken);
2018-04-13 17:19:50 +08:00
2020-12-01 14:37:51 +08:00
var dropletSamples = Samples.Select(s => s.With(@"slidertick")).ToList();
2019-01-26 15:16:49 +08:00
int nodeIndex = 0;
2019-03-08 18:57:30 +08:00
SliderEventDescriptor? lastEvent = null;
2018-04-13 17:19:50 +08:00
foreach (var e in SliderEventGenerator.Generate(StartTime, SpanDuration, Velocity, TickDistance, Path.Distance, this.SpanCount(), cancellationToken))
2018-04-13 17:19:50 +08:00
{
2019-03-08 18:57:30 +08:00
// generate tiny droplets since the last point
if (lastEvent != null)
2018-04-13 17:19:50 +08:00
{
double sinceLastTick = (int)e.Time - (int)lastEvent.Value.Time;
2018-04-13 17:19:50 +08:00
2019-03-08 18:57:30 +08:00
if (sinceLastTick > 80)
2018-06-13 21:20:34 +08:00
{
2019-03-08 18:57:30 +08:00
double timeBetweenTiny = sinceLastTick;
while (timeBetweenTiny > 100)
timeBetweenTiny /= 2;
2018-06-13 21:20:34 +08:00
2019-03-08 18:57:30 +08:00
for (double t = timeBetweenTiny; t < sinceLastTick; t += timeBetweenTiny)
{
2020-05-15 17:17:39 +08:00
cancellationToken.ThrowIfCancellationRequested();
2019-03-08 18:57:30 +08:00
AddNested(new TinyDroplet
{
StartTime = t + lastEvent.Value.Time,
X = EffectiveX + Path.PositionAt(lastEvent.Value.PathProgress + (t / sinceLastTick) * (e.PathProgress - lastEvent.Value.PathProgress)).X,
2019-03-08 18:57:30 +08:00
});
}
}
2019-03-08 18:57:30 +08:00
}
2018-04-13 17:19:50 +08: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 18:57:30 +08:00
lastEvent = e;
2018-04-13 17:19:50 +08:00
2019-03-08 18:57:30 +08:00
switch (e.Type)
{
case SliderEventType.Tick:
AddNested(new Droplet
2018-04-13 17:19:50 +08:00
{
Samples = dropletSamples,
StartTime = e.Time,
X = EffectiveX + Path.PositionAt(e.PathProgress).X,
2019-03-08 18:57:30 +08:00
});
break;
2019-04-01 11:44:46 +08:00
2019-03-08 18:57:30 +08:00
case SliderEventType.Head:
case SliderEventType.Tail:
case SliderEventType.Repeat:
AddNested(new Fruit
{
Samples = this.GetNodeSamples(nodeIndex++),
StartTime = e.Time,
X = EffectiveX + Path.PositionAt(e.PathProgress).X,
2018-04-13 17:19:50 +08:00
});
break;
2018-04-13 17:19:50 +08:00
}
}
}
public float EndX => EffectiveX + this.CurvePositionAt(1).X;
2020-05-27 11:37:44 +08:00
[JsonIgnore]
2020-05-27 11:37:44 +08:00
public double Duration
2020-02-05 16:12:26 +08:00
{
2020-05-27 11:37:44 +08:00
get => this.SpanCount() * Path.Distance / Velocity;
set => throw new NotSupportedException($"Adjust via {nameof(RepeatCount)} instead"); // can be implemented if/when needed.
2020-02-05 16:12:26 +08:00
}
2018-04-13 17:19:50 +08:00
2020-05-27 11:37:44 +08:00
public double EndTime => StartTime + Duration;
2018-04-13 17:19:50 +08:00
private readonly SliderPath path = new SliderPath();
2019-12-06 19:53:40 +08:00
public SliderPath Path
{
get => path;
set
{
path.ControlPoints.Clear();
path.ControlPoints.AddRange(value.ControlPoints.Select(c => new PathControlPoint(c.Position, c.Type)));
path.ExpectedDistance.Value = value.ExpectedDistance.Value;
2019-12-06 19:53:40 +08:00
}
}
2018-04-13 17:19:50 +08:00
2018-11-12 13:07:48 +08:00
public double Distance => Path.Distance;
2018-04-13 17:19:50 +08:00
public IList<IList<HitSampleInfo>> NodeSamples { get; set; } = new List<IList<HitSampleInfo>>();
2018-04-13 17:19:50 +08:00
}
}