Skip to content

Commit

Permalink
Use span in LegacyManiaDecoder
Browse files Browse the repository at this point in the history
  • Loading branch information
huoyaoyuan committed Jul 8, 2024
1 parent b51d98e commit bc8fe3d
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions osu.Game/Skinning/LegacyManiaSkinDecoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ protected override void OnBeginNewSection(Section section)
currentConfig = null;
}

protected override void ParseLine(List<LegacyManiaSkinConfiguration> output, Section section, string line)
protected override void ParseLine(List<LegacyManiaSkinConfiguration> output, Section section, ReadOnlySpan<char> line)
{
switch (section)
{
Expand All @@ -52,7 +52,7 @@ protected override void ParseLine(List<LegacyManiaSkinConfiguration> output, Sec
break;

default:
pendingLines.Add(line);
pendingLines.Add(line.ToString());

// Hold all lines until a "Keys" item is found.
if (currentConfig != null)
Expand Down Expand Up @@ -128,34 +128,36 @@ private void flushPendingLines()
currentConfig.LightFramePerSecond = lightFramePerSecond > 0 ? lightFramePerSecond : 24;
break;

case string when pair.Key.StartsWith("Colour", StringComparison.Ordinal):
case { } when pair.Key.StartsWith("Colour", StringComparison.Ordinal):
HandleColours(currentConfig, line, true);
break;

// Custom sprite paths
case string when pair.Key.StartsWith("NoteImage", StringComparison.Ordinal):
case string when pair.Key.StartsWith("KeyImage", StringComparison.Ordinal):
case string when pair.Key.StartsWith("Hit", StringComparison.Ordinal):
case string when pair.Key.StartsWith("Stage", StringComparison.Ordinal):
case string when pair.Key.StartsWith("Lighting", StringComparison.Ordinal):
currentConfig.ImageLookups[pair.Key] = pair.Value;
case { } when pair.Key.StartsWith("NoteImage", StringComparison.Ordinal):
case { } when pair.Key.StartsWith("KeyImage", StringComparison.Ordinal):
case { } when pair.Key.StartsWith("Hit", StringComparison.Ordinal):
case { } when pair.Key.StartsWith("Stage", StringComparison.Ordinal):
case { } when pair.Key.StartsWith("Lighting", StringComparison.Ordinal):
currentConfig.ImageLookups[pair.Key.ToString()] = pair.Value.ToString();
break;
}
}

pendingLines.Clear();
}

private void parseArrayValue(string value, float[] output, bool applyScaleFactor = true)
private void parseArrayValue(ReadOnlySpan<char> value, float[] output, bool applyScaleFactor = true)
{
string[] values = value.Split(',');
int valuesCount = value.Count(',') + 1;
Span<Range> ranges = valuesCount <= 256 ? stackalloc Range[valuesCount] : new Range[valuesCount];
value.Split(ranges, ',');

for (int i = 0; i < values.Length; i++)
for (int i = 0; i < ranges.Length; i++)
{
if (i >= output.Length)
break;

if (!float.TryParse(values[i], NumberStyles.Float, CultureInfo.InvariantCulture, out float parsedValue))
if (!float.TryParse(value[ranges[i]], NumberStyles.Float, CultureInfo.InvariantCulture, out float parsedValue))
// some skins may provide incorrect entries in array values. to match stable behaviour, read such entries as zero.
// see: https://github.com/ppy/osu/issues/26464, stable code: https://github.com/peppy/osu-stable-reference/blob/3ea48705eb67172c430371dcfc8a16a002ed0d3d/osu!/Graphics/Skinning/Components/Section.cs#L134-L137
parsedValue = 0;
Expand Down

0 comments on commit bc8fe3d

Please sign in to comment.