Files
sbox-public/engine/Sandbox.Engine/Game/GameMenu/LoadingProgress.ETA.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

22 lines
565 B
C#

namespace Sandbox.Menu;
partial struct LoadingProgress
{
public readonly TimeSpan CalculateETA()
{
if ( Mbps <= 0 || Fraction >= 1 || TotalSize <= 0 )
return TimeSpan.MaxValue;
if ( Fraction < 0.25 )
return TimeSpan.MaxValue;
var remainingBytes = TotalSize * (1 - Fraction);
var bytesPerSecond = Mbps * 1_000_000 / 8; // Convert Mbps to bytes per second
var secondsRemaining = remainingBytes / bytesPerSecond;
var roundedSeconds = Math.Max( 1, (int)Math.Round( secondsRemaining ) );
return TimeSpan.FromSeconds( roundedSeconds );
}
}