Files
sbox-public/engine/Sandbox.Engine/Scene/GameObjectSystems/DebugOverlay/DebugOverlaySystem.cs
Garry Newman d95169d8fa Unit Test Cleanup (#5064)
* Move all unit tests to Engine/Tests
* Fix Margin.EdgeSubtract
* Fix Capsule.Contains
* EnvironmentVariables.Remove if it's null
* Fixed ray trace never returning startedsolid
* Fix HistoryList.Navigate on empty list
* Fix GameObject.WorldPosition accepting NaNs
* Fix flex: initial expanding to the wrong grow/shrink
* Translation.TryConvert shouldn't throw on invalid enum strings
* Skip sound file tests on machines with no audio device
2026-06-12 13:23:50 +01:00

66 lines
1.3 KiB
C#

namespace Sandbox;
public sealed partial class DebugOverlaySystem : GameObjectSystem<DebugOverlaySystem>
{
bool inFixedUpdate;
public DebugOverlaySystem( Scene scene ) : base( scene )
{
Listen( Stage.StartUpdate, -10000, StartUpdate, "BuildDebugOverlays" );
Listen( Stage.StartFixedUpdate, -10000, StartFixedUpdate, "BuildDebugOverlays" );
Listen( Stage.FinishFixedUpdate, 10000, EndFixedUpdate, "BuildDebugOverlays" );
}
void RemoveExpired()
{
for ( int i = 0; i < entries.Count; i++ )
{
if ( entries[i].SingleFrame ) continue;
entries[i].life -= Time.Delta;
if ( entries[i].life < 0 )
{
entries[i].Dispose();
entries.RemoveAt( i ); // move to end and remove?
i--;
}
}
}
void RemoveSingleFrame( bool createdDuringFixed )
{
for ( int i = 0; i < entries.Count; i++ )
{
if ( !entries[i].SingleFrame ) continue;
if ( entries[i].CreatedDuringFixed != createdDuringFixed ) continue;
entries[i].Dispose();
entries.RemoveAt( i );
i--;
}
// don't force the scene world to exist just to flush deletes
if ( Scene.HasSceneWorld )
{
Scene.SceneWorld.DeletePendingObjects();
}
}
void StartUpdate()
{
RemoveExpired();
RemoveSingleFrame( false );
}
void StartFixedUpdate()
{
RemoveSingleFrame( true );
inFixedUpdate = true;
}
void EndFixedUpdate()
{
inFixedUpdate = false;
}
}