brutal/Brutal.RakNet/Manual/Utility/Time.cs
Rian Drake b578433e37 first
2026-10-15 17:10:50 +13:00

23 lines
877 B
C#

using System.Diagnostics;
namespace Brutal.RakNetApi.Utility;
/// <summary>
/// Time-based functions for dealing with RakNet timestamps.
/// </summary>
public static class Time
{
/// <summary>
/// Computes the current timestamp in raknet units (milliseconds) based on the system's high-resolution
/// performance counter and its frequency, ensuring precise time measurements.
/// The result is returned in host byte order.
/// </summary>
///
public static long RakNetTimeMs() => (long)(Stopwatch.GetTimestamp() * RakNetTimeUnits / Stopwatch.Frequency);
public static double SecondsFromRakNetTimestamp(long rakNetTimestamp) => rakNetTimestamp / RakNetTimeUnits;
public static double TimestampNowSeconds() => (double)Stopwatch.GetTimestamp() / Stopwatch.Frequency;
private const double RakNetTimeUnits = 1000.0d; // Milliseconds
}