mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-20 22:38:16 -04:00
Fixes timing scopes to more accurately represent a per-frame main thread breakdown, and prevents spikes when GC is executed. - **GcPause** - New separate timing scope showing time spent in GC per frame - GC pause time is subtracted from all other scopes, so each scope now only tracks its own code execution and no longer includes GC overhead - e.g. when GC occurs during the audio scope, the audio scope no longer spikes to 20ms - **AudioMixingThread** removed from the main scopes - Runs on a separate thread, so its timings are effectively meaningless in the main thread view - All other scopes are main thread only - No longer relevant given the audio optimisation work done over the past months - **Scene** scope removed - Didn't make much sense as it was an aggregate wrapping many other timing scopes - Replaced with a finer `Update` scope that tracks `Component.FixedUpdate`/`Update` - **Editor** scope no longer shows in-game - Scopes reschuffled - e.g. verlet rope physics traces are now tracked under the physics scope - Audio occlusion queries are now tracked under the audio scope https://files.facepunch.com/lolleko/2026/March/02_12-59-QuixoticMarten.png
53 lines
1.1 KiB
C#
53 lines
1.1 KiB
C#
namespace Sandbox;
|
|
|
|
/// <summary>
|
|
/// Implements logic for the SoundScape system
|
|
/// </summary>
|
|
[Expose]
|
|
sealed class SceneSoundscapeSystem : GameObjectSystem<SceneSoundscapeSystem>
|
|
{
|
|
public SceneSoundscapeSystem( Scene scene ) : base( scene )
|
|
{
|
|
Listen( Stage.UpdateBones, 0, Update, "TickSoundScapes" );
|
|
}
|
|
|
|
SoundscapeTrigger active;
|
|
RealTimeSince timeSinceUpdate;
|
|
|
|
void Update()
|
|
{
|
|
using var _ = PerformanceStats.Timings.Audio.Scope();
|
|
|
|
if ( Scene.IsEditor )
|
|
return;
|
|
|
|
if ( timeSinceUpdate < 0.2f )
|
|
return;
|
|
|
|
timeSinceUpdate = 0;
|
|
|
|
var head = Sound.Listener;
|
|
|
|
// Find the closest soundscape, sphere and box take priority over point.
|
|
var best = Scene.GetAllComponents<SoundscapeTrigger>()
|
|
.Where( x => x.TestListenerPosition( head.Position ) )
|
|
.MinBy( x => (x.Type == SoundscapeTrigger.TriggerType.Point ? 1 : 0, x.WorldPosition.DistanceSquared( head.Position )) );
|
|
|
|
if ( best == active )
|
|
return;
|
|
|
|
if ( best == null && active.StayActiveOnExit )
|
|
return;
|
|
|
|
if ( active is not null )
|
|
active.Playing = false;
|
|
|
|
active = best;
|
|
|
|
if ( active is not null )
|
|
active.Playing = true;
|
|
|
|
|
|
}
|
|
}
|