mirror of
https://github.com/osukey/osukey.git
synced 2025-05-09 23:57:18 +09:00
Refactor base class to allow correct usage in taiko drum
This commit is contained in:
parent
681215e5b5
commit
a1936b141b
@ -49,7 +49,29 @@ namespace osu.Game.Rulesets.UI
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Play the most appropriate hit sound for the current point in time.
|
/// Play the most appropriate hit sound for the current point in time.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void Play()
|
public virtual void Play()
|
||||||
|
{
|
||||||
|
var nextObject = GetMostValidObject();
|
||||||
|
|
||||||
|
if (nextObject == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
var samples = nextObject.Samples
|
||||||
|
.Select(s => nextObject.SampleControlPoint.ApplyTo(s))
|
||||||
|
.Cast<ISampleInfo>()
|
||||||
|
.ToArray();
|
||||||
|
|
||||||
|
PlaySamples(samples);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void PlaySamples(ISampleInfo[] samples)
|
||||||
|
{
|
||||||
|
var hitSound = getNextSample();
|
||||||
|
hitSound.Samples = samples;
|
||||||
|
hitSound.Play();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected HitObject GetMostValidObject()
|
||||||
{
|
{
|
||||||
// The most optimal lookup case we have is when an object is alive. There are usually very few alive objects so there's no drawbacks in attempting this lookup each time.
|
// The most optimal lookup case we have is when an object is alive. There are usually very few alive objects so there's no drawbacks in attempting this lookup each time.
|
||||||
var nextObject = hitObjectContainer.AliveObjects.FirstOrDefault(h => h.HitObject.StartTime > Time.Current)?.HitObject;
|
var nextObject = hitObjectContainer.AliveObjects.FirstOrDefault(h => h.HitObject.StartTime > Time.Current)?.HitObject;
|
||||||
@ -58,7 +80,7 @@ namespace osu.Game.Rulesets.UI
|
|||||||
if (nextObject == null)
|
if (nextObject == null)
|
||||||
{
|
{
|
||||||
// This lookup can be skipped if the last entry is still valid (in the future and not yet hit).
|
// This lookup can be skipped if the last entry is still valid (in the future and not yet hit).
|
||||||
if (fallbackObject == null || fallbackObject.HitObject.StartTime < Time.Current || fallbackObject.Result.IsHit)
|
if (fallbackObject == null || fallbackObject.HitObject.StartTime < Time.Current || fallbackObject.Result?.IsHit == true)
|
||||||
{
|
{
|
||||||
// We need to use lifetime entries to find the next object (we can't just use `hitObjectContainer.Objects` due to pooling - it may even be empty).
|
// We need to use lifetime entries to find the next object (we can't just use `hitObjectContainer.Objects` due to pooling - it may even be empty).
|
||||||
// If required, we can make this lookup more efficient by adding support to get next-future-entry in LifetimeEntryManager.
|
// If required, we can make this lookup more efficient by adding support to get next-future-entry in LifetimeEntryManager.
|
||||||
@ -78,17 +100,9 @@ namespace osu.Game.Rulesets.UI
|
|||||||
nextObject = fallbackObject?.HitObject;
|
nextObject = fallbackObject?.HitObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nextObject != null)
|
return nextObject;
|
||||||
{
|
|
||||||
var hitSound = getNextSample();
|
|
||||||
hitSound.Samples = GetPlayableSampleInfo(nextObject).Select(s => nextObject.SampleControlPoint.ApplyTo(s)).Cast<ISampleInfo>().ToArray();
|
|
||||||
hitSound.Play();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual HitSampleInfo[] GetPlayableSampleInfo(HitObject nextObject) =>
|
|
||||||
nextObject.Samples.ToArray();
|
|
||||||
|
|
||||||
private SkinnableSound getNextSample()
|
private SkinnableSound getNextSample()
|
||||||
{
|
{
|
||||||
var hitSound = hitSounds[nextHitSoundIndex];
|
var hitSound = hitSounds[nextHitSoundIndex];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user