1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-23 07:18:45 +08:00

Split slider samples into head + tail + repeats + body (the original HitObject.Samples).

This commit is contained in:
smoogipooo 2017-04-21 18:49:49 +09:00
parent a7afde02bf
commit a999c42d8a
10 changed files with 54 additions and 16 deletions

View File

@ -34,6 +34,8 @@ namespace osu.Game.Rulesets.Osu.Objects
public int RepeatAt(double progress) => CurveObject.RepeatAt(progress);
public List<List<SampleInfo>> RepeatSamples => CurveObject.RepeatSamples;
public List<SampleInfo> HeadSamples => CurveObject.HeadSamples;
public List<SampleInfo> TailSamples => CurveObject.TailSamples;
public List<Vector2> ControlPoints => CurveObject.ControlPoints;
public CurveType CurveType => CurveObject.CurveType;

View File

@ -6,8 +6,6 @@ using osu.Game.Rulesets.Objects.Types;
using System.Collections.Generic;
using osu.Game.Audio;
using System;
using osu.Game.Beatmaps.Timing;
using osu.Game.Database;
namespace osu.Game.Rulesets.Objects
{
@ -40,6 +38,9 @@ namespace osu.Game.Rulesets.Objects
public List<List<SampleInfo>> RepeatSamples { get; set; } = new List<List<SampleInfo>>();
public List<SampleInfo> HeadSamples { get; set; } = new List<SampleInfo>();
public List<SampleInfo> TailSamples { get; set; } = new List<SampleInfo>();
public Vector2 PositionAt(double progress) => Curve.PositionAt(ProgressAt(progress));
public double ProgressAt(double progress)

View File

@ -24,6 +24,10 @@ namespace osu.Game.Rulesets.Objects
/// <summary>
/// The samples to be played when this hit object is hit.
/// <para>
/// In the case of <see cref="CurvedHitObject"/> types, this is the sample of the curve body
/// and can be treated as the default samples for the hit object.
/// </para>
/// </summary>
public List<SampleInfo> Samples = new List<SampleInfo>();
@ -40,12 +44,16 @@ namespace osu.Game.Rulesets.Objects
ControlPoint samplePoint = overridePoint ?? timingPoint;
// Initialize first sample
foreach (SampleInfo sample in Samples)
initializeSampleInfo(sample, samplePoint);
Samples.ForEach(s => initializeSampleInfo(s, samplePoint));
// Initialize any repeat samples
var repeatData = this as IHasRepeats;
repeatData?.RepeatSamples?.ForEach(r => r.ForEach(s => initializeSampleInfo(s, samplePoint)));
// Initialize any curved object samples
var curvedObject = this as CurvedHitObject;
curvedObject?.HeadSamples.ForEach(s => initializeSampleInfo(s, samplePoint));
curvedObject?.TailSamples.ForEach(s => initializeSampleInfo(s, samplePoint));
}
private void initializeSampleInfo(SampleInfo sample, ControlPoint controlPoint)

View File

@ -22,7 +22,8 @@ namespace osu.Game.Rulesets.Objects.Legacy.Catch
};
}
protected override HitObject CreateSlider(Vector2 position, bool newCombo, List<Vector2> controlPoints, double length, CurveType curveType, int repeatCount, List<List<SampleInfo>> repeatSamples)
protected override HitObject CreateSlider(Vector2 position, bool newCombo, List<Vector2> controlPoints, double length, CurveType curveType,
int repeatCount, List<SampleInfo> headSamples, List<SampleInfo> tailSamples, List<List<SampleInfo>> repeatSamples)
{
return new Slider
{
@ -32,6 +33,8 @@ namespace osu.Game.Rulesets.Objects.Legacy.Catch
Distance = length,
CurveType = curveType,
RepeatCount = repeatCount,
HeadSamples = headSamples,
TailSamples = tailSamples,
RepeatSamples = repeatSamples
};
}

View File

@ -26,7 +26,6 @@ namespace osu.Game.Rulesets.Objects.Legacy
var soundType = (LegacySoundType)int.Parse(split[4]);
var bankInfo = new SampleBankInfo();
List<SampleInfo> startSamples = null;
HitObject result;
@ -129,13 +128,14 @@ namespace osu.Game.Rulesets.Objects.Legacy
for (int i = 0; i <= repeatCount; i++)
nodeSamples.Add(convertSoundType(nodeSoundTypes[i], nodeBankInfos[i]));
// Extract the first node as the first sample
startSamples = nodeSamples[0];
// Extract the first and last samples for the head and tail respectively
List<SampleInfo> headSamples = nodeSamples.First();
List<SampleInfo> tailSamples = nodeSamples.Last();
// Repeat samples are all the samples excluding the one from the first node (note this includes the end node)
var repeatSamples = nodeSamples.Skip(1).ToList();
// Repeat samples are all the samples between head and tail
var repeatSamples = nodeSamples.Skip(1).TakeWhile(s => s != tailSamples).ToList();
result = CreateSlider(new Vector2(int.Parse(split[0]), int.Parse(split[1])), combo, points, length, curveType, repeatCount, repeatSamples);
result = CreateSlider(new Vector2(int.Parse(split[0]), int.Parse(split[1])), combo, points, length, curveType, repeatCount, headSamples, tailSamples, repeatSamples);
}
else if ((type & HitObjectType.Spinner) > 0)
{
@ -161,7 +161,7 @@ namespace osu.Game.Rulesets.Objects.Legacy
throw new InvalidOperationException($@"Unknown hit object type {type}");
result.StartTime = Convert.ToDouble(split[2], CultureInfo.InvariantCulture);
result.Samples = startSamples ?? convertSoundType(soundType, bankInfo);
result.Samples = convertSoundType(soundType, bankInfo);
return result;
}
@ -212,7 +212,8 @@ namespace osu.Game.Rulesets.Objects.Legacy
/// <param name="repeatCount">The slider repeat count.</param>
/// <param name="repeatSamples">The slider repeat sounds (this includes the end node, but NOT the start node).</param>
/// <returns>The hit object.</returns>
protected abstract HitObject CreateSlider(Vector2 position, bool newCombo, List<Vector2> controlPoints, double length, CurveType curveType, int repeatCount, List<List<SampleInfo>> repeatSamples);
protected abstract HitObject CreateSlider(Vector2 position, bool newCombo, List<Vector2> controlPoints, double length, CurveType curveType,
int repeatCount, List<SampleInfo> headSamples, List<SampleInfo> tailSamples, List<List<SampleInfo>> repeatSamples);
/// <summary>
/// Creates a legacy Spinner-type hit object.

View File

@ -22,7 +22,8 @@ namespace osu.Game.Rulesets.Objects.Legacy.Mania
};
}
protected override HitObject CreateSlider(Vector2 position, bool newCombo, List<Vector2> controlPoints, double length, CurveType curveType, int repeatCount, List<List<SampleInfo>> repeatSamples)
protected override HitObject CreateSlider(Vector2 position, bool newCombo, List<Vector2> controlPoints, double length, CurveType curveType,
int repeatCount, List<SampleInfo> headSamples, List<SampleInfo> tailSamples, List<List<SampleInfo>> repeatSamples)
{
return new Slider
{
@ -32,6 +33,8 @@ namespace osu.Game.Rulesets.Objects.Legacy.Mania
Distance = length,
CurveType = curveType,
RepeatCount = repeatCount,
HeadSamples = headSamples,
TailSamples = tailSamples,
RepeatSamples = repeatSamples
};
}

View File

@ -22,7 +22,8 @@ namespace osu.Game.Rulesets.Objects.Legacy.Osu
};
}
protected override HitObject CreateSlider(Vector2 position, bool newCombo, List<Vector2> controlPoints, double length, CurveType curveType, int repeatCount, List<List<SampleInfo>> repeatSamples)
protected override HitObject CreateSlider(Vector2 position, bool newCombo, List<Vector2> controlPoints, double length, CurveType curveType,
int repeatCount, List<SampleInfo> headSamples, List<SampleInfo> tailSamples, List<List<SampleInfo>> repeatSamples)
{
return new Slider
{
@ -32,6 +33,8 @@ namespace osu.Game.Rulesets.Objects.Legacy.Osu
Distance = length,
CurveType = curveType,
RepeatCount = repeatCount,
HeadSamples = headSamples,
TailSamples = tailSamples,
RepeatSamples = repeatSamples
};
}

View File

@ -21,7 +21,8 @@ namespace osu.Game.Rulesets.Objects.Legacy.Taiko
};
}
protected override HitObject CreateSlider(Vector2 position, bool newCombo, List<Vector2> controlPoints, double length, CurveType curveType, int repeatCount, List<List<SampleInfo>> repeatSamples)
protected override HitObject CreateSlider(Vector2 position, bool newCombo, List<Vector2> controlPoints, double length, CurveType curveType,
int repeatCount, List<SampleInfo> headSamples, List<SampleInfo> tailSamples, List<List<SampleInfo>> repeatSamples)
{
return new Slider
{
@ -30,6 +31,8 @@ namespace osu.Game.Rulesets.Objects.Legacy.Taiko
Distance = length,
CurveType = curveType,
RepeatCount = repeatCount,
HeadSamples = headSamples,
TailSamples = tailSamples,
RepeatSamples = repeatSamples
};
}

View File

@ -3,6 +3,7 @@
using System.Collections.Generic;
using OpenTK;
using osu.Game.Audio;
namespace osu.Game.Rulesets.Objects.Types
{
@ -26,6 +27,16 @@ namespace osu.Game.Rulesets.Objects.Types
/// </summary>
CurveType CurveType { get; }
/// <summary>
/// The samples to be played when the head of the hit object is hit.
/// </summary>
List<SampleInfo> HeadSamples { get; }
/// <summary>
/// The samples to be played when the tail of the hit object is hit.
/// </summary>
List<SampleInfo> TailSamples { get; }
/// <summary>
/// Computes the position on the curve at a given progress, accounting for repeat logic.
/// <para>

View File

@ -16,6 +16,9 @@ namespace osu.Game.Rulesets.Objects.Types
/// </summary>
int RepeatCount { get; }
/// <summary>
/// The samples to be played when each repeat node is hit (0 -> first repeat node, 1 -> second repeat node, etc).
/// </summary>
List<List<SampleInfo>> RepeatSamples { get; }
}
}