This commit is contained in:
Rian Drake 2026-10-15 14:09:11 +13:00
commit b578433e37

View file

@ -0,0 +1,23 @@
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
}