mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-02 11:28:19 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
53 lines
968 B
C#
53 lines
968 B
C#
namespace Sandbox;
|
|
|
|
public sealed class DecalGameSystem : GameObjectSystem<DecalGameSystem>
|
|
{
|
|
[ConVar( "maxdecals" )]
|
|
public static int MaxDecals { get; internal set; } = 1000;
|
|
|
|
/// <summary>
|
|
/// A list of decals that can be destroyed after a certain time.
|
|
/// </summary>
|
|
LinkedList<Decal> _transients = new();
|
|
|
|
public DecalGameSystem( Scene scene ) : base( scene )
|
|
{
|
|
|
|
}
|
|
|
|
public void ClearDecals()
|
|
{
|
|
while ( _transients.Count > 0 )
|
|
{
|
|
var first = _transients.First;
|
|
first.Value.Destroy();
|
|
|
|
_transients.Remove( first );
|
|
}
|
|
}
|
|
|
|
internal void AddTransient( Decal decal )
|
|
{
|
|
if ( decal is null || !decal.IsValid() )
|
|
return;
|
|
|
|
_transients.AddLast( decal );
|
|
|
|
int max = MaxDecals;
|
|
while ( _transients.Count > max )
|
|
{
|
|
var first = _transients.First;
|
|
first.Value.Destroy();
|
|
|
|
_transients.Remove( first );
|
|
}
|
|
}
|
|
|
|
internal void RemoveTransient( Decal decal )
|
|
{
|
|
if ( decal is null ) return;
|
|
|
|
_transients.Remove( decal );
|
|
}
|
|
}
|