Add initial hit sample pooling

This commit is contained in:
smoogipoo
2020-11-19 19:51:09 +09:00
parent 7f3c8ad744
commit 730b14b5bb
10 changed files with 283 additions and 58 deletions

View File

@ -10,7 +10,6 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.TypeExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Primitives;
using osu.Framework.Logging;
using osu.Framework.Threading;
@ -139,8 +138,6 @@ namespace osu.Game.Rulesets.Objects.Drawables
[Resolved(CanBeNull = true)]
private IPooledHitObjectProvider pooledObjectProvider { get; set; }
private Container<PausableSkinnableSound> samplesContainer;
/// <summary>
/// Creates a new <see cref="DrawableHitObject"/>.
/// </summary>
@ -159,7 +156,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
config.BindWith(OsuSetting.PositionalHitSounds, userPositionalHitSounds);
// Explicit non-virtual function call.
base.AddInternal(samplesContainer = new Container<PausableSkinnableSound> { RelativeSizeAxes = Axes.Both });
base.AddInternal(Samples = new PausableSkinnableSound(Array.Empty<ISampleInfo>()));
}
protected override void LoadAsyncComplete()
@ -269,6 +266,8 @@ namespace osu.Game.Rulesets.Objects.Drawables
// In order to stop this needless update, the event is unbound and re-bound as late as possible in Apply().
samplesBindable.CollectionChanged -= onSamplesChanged;
Samples.Samples = Array.Empty<ISampleInfo>();
if (nestedHitObjects.IsValueCreated)
{
foreach (var obj in nestedHitObjects.Value)
@ -335,8 +334,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
/// </summary>
protected virtual void LoadSamples()
{
samplesContainer.Clear();
Samples = null;
Samples.Samples = Array.Empty<ISampleInfo>();
var samples = GetSamples().ToArray();
@ -349,7 +347,7 @@ namespace osu.Game.Rulesets.Objects.Drawables
+ $" This is an indication that {nameof(HitObject.ApplyDefaults)} has not been invoked on {this}.");
}
samplesContainer.Add(Samples = new PausableSkinnableSound(samples.Select(s => HitObject.SampleControlPoint.ApplyTo(s))));
Samples.Samples = samples.Select(s => HitObject.SampleControlPoint.ApplyTo(s)).Cast<ISampleInfo>().ToArray();
}
private void onSamplesChanged(object sender, NotifyCollectionChangedEventArgs e) => LoadSamples();

View File

@ -5,6 +5,7 @@ using osuTK;
using osu.Game.Rulesets.Objects.Types;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using osu.Game.Beatmaps.Formats;
using osu.Game.Audio;
@ -500,7 +501,7 @@ namespace osu.Game.Rulesets.Objects.Legacy
public SampleBankInfo Clone() => (SampleBankInfo)MemberwiseClone();
}
public class LegacyHitSampleInfo : HitSampleInfo
public class LegacyHitSampleInfo : HitSampleInfo, IEquatable<LegacyHitSampleInfo>
{
private int customSampleBank;
@ -524,9 +525,21 @@ namespace osu.Game.Rulesets.Objects.Legacy
/// using the <see cref="LegacySkinConfiguration.LegacySetting.LayeredHitSounds"/> skin config option.
/// </remarks>
public bool IsLayered { get; set; }
public bool Equals(LegacyHitSampleInfo other)
=> other != null && base.Equals(other) && CustomSampleBank == other.CustomSampleBank;
public override bool Equals(object obj)
=> obj is LegacyHitSampleInfo other && Equals(other);
[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")] // This will have to be addressed eventually
public override int GetHashCode()
{
return HashCode.Combine(base.GetHashCode(), customSampleBank);
}
}
private class FileHitSampleInfo : LegacyHitSampleInfo
private class FileHitSampleInfo : LegacyHitSampleInfo, IEquatable<FileHitSampleInfo>
{
public string Filename;
@ -542,6 +555,18 @@ namespace osu.Game.Rulesets.Objects.Legacy
Filename,
Path.ChangeExtension(Filename, null)
};
public bool Equals(FileHitSampleInfo other)
=> other != null && Filename == other.Filename;
public override bool Equals(object obj)
=> obj is FileHitSampleInfo other && Equals(other);
[SuppressMessage("ReSharper", "NonReadonlyMemberInGetHashCode")] // This will have to be addressed eventually
public override int GetHashCode()
{
return HashCode.Combine(Filename);
}
}
}
}