1
0
mirror of https://github.com/ppy/osu.git synced 2026-06-03 19:24:24 +08:00

Merge pull request #32376 from nekodex/better-kiai-fountain-sfx

Improve SFX playback behaviour of rapid kiai/star fountain activations
This commit is contained in:
Dean Herbert
2025-03-18 17:49:21 +09:00
committed by GitHub
Unverified
5 changed files with 83 additions and 29 deletions
@@ -50,30 +50,17 @@ namespace osu.Game.Tests.Visual.Menus
[Test]
public void TestGameplay()
{
KiaiGameplayFountains fountains = null!;
AddStep("make fountains", () =>
{
Children = new[]
{
new KiaiGameplayFountains.GameplayStarFountain
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
X = 75,
},
new KiaiGameplayFountains.GameplayStarFountain
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
X = -75,
},
fountains = new KiaiGameplayFountains(),
};
});
AddStep("activate fountains", () =>
{
((StarFountain)Children[0]).Shoot(1);
((StarFountain)Children[1]).Shoot(-1);
});
AddStep("activate fountains", () => fountains.Shoot());
}
[Test]
+4 -6
View File
@@ -6,9 +6,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Platform;
using osu.Framework.Utils;
using osu.Game.Audio;
using osu.Game.Graphics.Containers;
using osu.Game.Skinning;
namespace osu.Game.Screens.Menu
{
@@ -20,7 +18,7 @@ namespace osu.Game.Screens.Menu
[Resolved]
private GameHost host { get; set; } = null!;
private SkinnableSound? sample;
private StarFountainSounds sounds = null!;
[BackgroundDependencyLoader]
private void load()
@@ -41,7 +39,7 @@ namespace osu.Game.Screens.Menu
Origin = Anchor.BottomRight,
X = -250,
},
sample = new SkinnableSound(new SampleInfo("Gameplay/fountain-shoot"))
sounds = new StarFountainSounds()
};
}
@@ -83,9 +81,9 @@ namespace osu.Game.Screens.Menu
break;
}
// Don't play SFX when game is in background as it can be a bit noisy.
// Don't play SFX when game is in background, as it can be a bit noisy.
if (host.IsActive.Value)
sample?.Play();
sounds.Play();
}
}
}
@@ -0,0 +1,71 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Threading;
using osu.Game.Audio;
using osu.Game.Skinning;
namespace osu.Game.Screens.Menu
{
public partial class StarFountainSounds : CompositeComponent
{
private const int shoot_retrigger_delay = 500;
private const int loop_fade_duration = 500;
private double? lastPlayback;
private SkinnableSound shootSample = null!;
private PausableSkinnableSound loopSample = null!;
private ScheduledDelegate? loopFadeDelegate;
private ScheduledDelegate? loopStopDelegate;
[BackgroundDependencyLoader]
private void load()
{
InternalChildren = new Drawable[]
{
shootSample = new SkinnableSound(new SampleInfo("Gameplay/fountain-shoot")),
loopSample = new PausableSkinnableSound(new SampleInfo("Gameplay/fountain-loop")) { Looping = true },
};
}
public void Play()
{
loopFadeDelegate?.Cancel();
loopStopDelegate?.Cancel();
try
{
// Only play 'shootSample' if enough time has passed since last `Play()` call.
if (lastPlayback == null || Time.Current - lastPlayback > shoot_retrigger_delay)
{
loopSample.Stop();
shootSample.Play();
return;
}
// Only call `Play()` if `loopSample` is not already playing, to prevent restarting the sample each time.
if (!loopSample.RequestedPlaying)
{
this.TransformBindableTo(loopSample.Volume, 1);
loopSample.Play();
}
// Schedule a volume fadeout, followed by a `Stop()`.
loopFadeDelegate = Scheduler.AddDelayed(() =>
{
this.TransformBindableTo(loopSample.Volume, 0, loop_fade_duration);
loopStopDelegate = Scheduler.AddDelayed(() => loopSample.Stop(), loop_fade_duration);
}, shoot_retrigger_delay);
}
finally
{
lastPlayback = Time.Current;
}
}
}
}
@@ -6,11 +6,9 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Utils;
using osu.Game.Audio;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
using osu.Game.Screens.Menu;
using osu.Game.Skinning;
namespace osu.Game.Screens.Play
{
@@ -21,7 +19,7 @@ namespace osu.Game.Screens.Play
private Bindable<bool> kiaiStarFountains = null!;
private SkinnableSound? sample;
private StarFountainSounds sounds = null!;
[BackgroundDependencyLoader]
private void load(OsuConfigManager config)
@@ -44,7 +42,7 @@ namespace osu.Game.Screens.Play
Origin = Anchor.BottomRight,
X = -75,
},
sample = new SkinnableSound(new SampleInfo("Gameplay/fountain-shoot"))
sounds = new StarFountainSounds(),
};
}
@@ -72,7 +70,7 @@ namespace osu.Game.Screens.Play
leftFountain.Shoot(1);
rightFountain.Shoot(-1);
sample?.Play();
sounds.Play();
}
public partial class GameplayStarFountain : StarFountain
+1 -1
View File
@@ -36,7 +36,7 @@
</PackageReference>
<PackageReference Include="Realm" Version="20.1.0" />
<PackageReference Include="ppy.osu.Framework" Version="2025.313.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2025.313.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2025.318.0" />
<PackageReference Include="Sentry" Version="5.1.1" />
<!-- Held back due to 0.34.0 failing AOT compilation on ZstdSharp.dll dependency. -->
<PackageReference Include="SharpCompress" Version="0.39.0" />