mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
Merge pull request #12748 from smoogipoo/fix-mania-sample-crash
Fix mania crashing on playing samples after skin change
This commit is contained in:
commit
87dfd9672d
@ -6,6 +6,7 @@ using JetBrains.Annotations;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Audio;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.UI.Scrolling;
|
||||
using osu.Game.Rulesets.Mania.UI;
|
||||
@ -24,6 +25,11 @@ namespace osu.Game.Rulesets.Mania.Objects.Drawables
|
||||
[Resolved(canBeNull: true)]
|
||||
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
|
||||
{
|
||||
get
|
||||
|
@ -27,6 +27,12 @@ namespace osu.Game.Rulesets.Mania.UI
|
||||
public const float COLUMN_WIDTH = 80;
|
||||
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>
|
||||
private const int max_concurrent_hitsounds = OsuGameBase.SAMPLE_CONCURRENCY;
|
||||
|
||||
/// <summary>
|
||||
/// The index of this column as part of the whole playfield.
|
||||
/// </summary>
|
||||
@ -38,6 +44,7 @@ namespace osu.Game.Rulesets.Mania.UI
|
||||
internal readonly Container TopLevelContainer;
|
||||
private readonly DrawablePool<PoolableHitExplosion> hitExplosionPool;
|
||||
private readonly OrderedHitPolicy hitPolicy;
|
||||
private readonly Container<SkinnableSound> hitSounds;
|
||||
|
||||
public Container UnderlayElements => HitObjectArea.UnderlayElements;
|
||||
|
||||
@ -64,6 +71,12 @@ namespace osu.Game.Rulesets.Mania.UI
|
||||
RelativeSizeAxes = Axes.Both
|
||||
},
|
||||
background,
|
||||
hitSounds = new Container<SkinnableSound>
|
||||
{
|
||||
Name = "Column samples pool",
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Children = Enumerable.Range(0, max_concurrent_hitsounds).Select(_ => new SkinnableSound()).ToArray()
|
||||
},
|
||||
TopLevelContainer = new Container { RelativeSizeAxes = Axes.Both }
|
||||
};
|
||||
|
||||
@ -120,6 +133,8 @@ namespace osu.Game.Rulesets.Mania.UI
|
||||
HitObjectArea.Explosions.Add(hitExplosionPool.Get(e => e.Apply(result)));
|
||||
}
|
||||
|
||||
private int nextHitSoundIndex;
|
||||
|
||||
public bool OnPressed(ManiaAction action)
|
||||
{
|
||||
if (action != Action.Value)
|
||||
@ -131,7 +146,15 @@ namespace osu.Game.Rulesets.Mania.UI
|
||||
HitObjectContainer.Objects.FirstOrDefault(h => h.HitObject.StartTime > Time.Current) ??
|
||||
HitObjectContainer.Objects.LastOrDefault();
|
||||
|
||||
nextObject?.PlaySamples();
|
||||
if (nextObject is DrawableManiaHitObject maniaObject)
|
||||
{
|
||||
var hitSound = hitSounds[nextHitSoundIndex];
|
||||
|
||||
hitSound.Samples = maniaObject.GetGameplaySamples();
|
||||
hitSound.Play();
|
||||
|
||||
nextHitSoundIndex = (nextHitSoundIndex + 1) % max_concurrent_hitsounds;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user