mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-16 18:29:15 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
53 lines
1.0 KiB
C#
53 lines
1.0 KiB
C#
|
|
using System.Threading;
|
|
|
|
namespace Sandbox.UI;
|
|
|
|
public partial class Panel
|
|
{
|
|
internal float TimeNow => PanelRealTime.TimeNow;
|
|
internal float TimeDelta => PanelRealTime.TimeDelta;
|
|
|
|
/// <summary>
|
|
/// Can be used to store random data without sub-classing the panel.
|
|
/// </summary>
|
|
[Hide]
|
|
public object UserData { get; set; }
|
|
|
|
|
|
CancellationTokenSource _deleteTokenSource;
|
|
|
|
/// <summary>
|
|
/// Get a token that is cancelled when the panel is deleted
|
|
/// </summary>
|
|
[Hide]
|
|
public CancellationToken DeletionToken
|
|
{
|
|
get
|
|
{
|
|
if ( IsDeleting || !IsValid )
|
|
return CancellationToken.None;
|
|
|
|
_deleteTokenSource ??= new CancellationTokenSource();
|
|
return _deleteTokenSource.Token;
|
|
}
|
|
}
|
|
}
|
|
|
|
static class PanelRealTime
|
|
{
|
|
public static float TimeNow;
|
|
public static float TimeDelta;
|
|
|
|
public static void Update()
|
|
{
|
|
var delta = RealTime.Delta;
|
|
|
|
// If we're running lower than 30fps, clamp it to avoid weirdness
|
|
delta = delta.Clamp( 0.000f, 1.0f / 30.0f );
|
|
|
|
TimeDelta = delta;
|
|
TimeNow += TimeDelta;
|
|
}
|
|
}
|