Files
sbox-public/engine/Sandbox.Engine/Scene/Networking/DeltaSnapshots/SnapshotData.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

44 lines
822 B
C#

namespace Sandbox.Network;
internal class SnapshotData : Dictionary<int, byte[]>, IObjectPoolEvent
{
public static NetworkObjectPool<SnapshotData> Pool { get; } = new();
private int ReferenceCount { get; set; }
/// <summary>
/// Add to reference count for this object.
/// </summary>
public void AddReference()
{
ReferenceCount++;
}
/// <summary>
/// Release a reference for this object, and return it to the pool
/// if nothing else is referencing it.
/// </summary>
public void Release()
{
if ( ReferenceCount == 0 )
throw new InvalidOperationException( "ReferenceCount is already zero" );
ReferenceCount--;
if ( ReferenceCount <= 0 )
{
Pool.Return( this );
}
}
void IObjectPoolEvent.OnRented()
{
ReferenceCount = 1;
}
void IObjectPoolEvent.OnReturned()
{
Clear();
}
}