1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-12 18:23:04 +08:00

Fix mania crashing on playing samples after skin change

This commit is contained in:
smoogipoo 2021-05-11 16:08:25 +09:00
parent 9c970a9eaf
commit 713c169332
2 changed files with 32 additions and 1 deletions

View File

@ -6,6 +6,7 @@ using JetBrains.Annotations;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Audio;
using osu.Game.Rulesets.Objects.Drawables; using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.UI.Scrolling; using osu.Game.Rulesets.UI.Scrolling;
using osu.Game.Rulesets.Mania.UI; using osu.Game.Rulesets.Mania.UI;
@ -24,6 +25,11 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
[Resolved(canBeNull: true)] [Resolved(canBeNull: true)]
private ManiaPlayfield playfield { get; set; } private ManiaPlayfield playfield { get; set; }
/// <summary>
/// Gets the samples that are played by this object during gameplay.
/// </summary>
public ISampleInfo[] GetGameplaySamples() => Samples.Samples;
protected override float SamplePlaybackPosition protected override float SamplePlaybackPosition
{ {
get get

View File

@ -27,6 +27,15 @@ namespace osu.Game.Rulesets.Mania.UI
public const float COLUMN_WIDTH = 80; public const float COLUMN_WIDTH = 80;
public const float SPECIAL_COLUMN_WIDTH = 70; public const float SPECIAL_COLUMN_WIDTH = 70;
/// <summary>
/// For hitsounds played by this <see cref="Column"/> (i.e. not as a result of hitting a hitobject),
/// a certain number of samples are allowed to be played concurrently so that it feels better when spam-pressing the key.
/// </summary>
/// <remarks>
///
/// </remarks>
private const int max_concurrent_hitsounds = OsuGameBase.SAMPLE_CONCURRENCY;
/// <summary> /// <summary>
/// The index of this column as part of the whole playfield. /// The index of this column as part of the whole playfield.
/// </summary> /// </summary>
@ -38,6 +47,7 @@ namespace osu.Game.Rulesets.Mania.UI
internal readonly Container TopLevelContainer; internal readonly Container TopLevelContainer;
private readonly DrawablePool<PoolableHitExplosion> hitExplosionPool; private readonly DrawablePool<PoolableHitExplosion> hitExplosionPool;
private readonly OrderedHitPolicy hitPolicy; private readonly OrderedHitPolicy hitPolicy;
private readonly SkinnableSound[] hitSounds;
public Container UnderlayElements => HitObjectArea.UnderlayElements; public Container UnderlayElements => HitObjectArea.UnderlayElements;
@ -64,6 +74,11 @@ namespace osu.Game.Rulesets.Mania.UI
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
}, },
background, background,
new Container
{
RelativeSizeAxes = Axes.Both,
ChildrenEnumerable = hitSounds = Enumerable.Range(0, max_concurrent_hitsounds).Select(_ => new SkinnableSound()).ToArray()
},
TopLevelContainer = new Container { RelativeSizeAxes = Axes.Both } TopLevelContainer = new Container { RelativeSizeAxes = Axes.Both }
}; };
@ -120,6 +135,8 @@ namespace osu.Game.Rulesets.Mania.UI
HitObjectArea.Explosions.Add(hitExplosionPool.Get(e => e.Apply(result))); HitObjectArea.Explosions.Add(hitExplosionPool.Get(e => e.Apply(result)));
} }
private int nextHitSound;
public bool OnPressed(ManiaAction action) public bool OnPressed(ManiaAction action)
{ {
if (action != Action.Value) if (action != Action.Value)
@ -131,7 +148,15 @@ namespace osu.Game.Rulesets.Mania.UI
HitObjectContainer.Objects.FirstOrDefault(h => h.HitObject.StartTime > Time.Current) ?? HitObjectContainer.Objects.FirstOrDefault(h => h.HitObject.StartTime > Time.Current) ??
HitObjectContainer.Objects.LastOrDefault(); HitObjectContainer.Objects.LastOrDefault();
nextObject?.PlaySamples(); if (nextObject is DrawableManiaHitObject maniaObject)
{
var hitSound = hitSounds[nextHitSound];
hitSound.Samples = maniaObject.GetGameplaySamples();
hitSound.Play();
nextHitSound = (nextHitSound + 1) % max_concurrent_hitsounds;
}
return true; return true;
} }