mirror of
https://github.com/ahwootech/BRUTAL.git
synced 2026-11-26 13:08:24 +01:00
first
This commit is contained in:
parent
bd62d51ec9
commit
b578433e37
1 changed files with 784842 additions and 0 deletions
23
Brutal.RakNet/Manual/Utility/Time.cs
Normal file
23
Brutal.RakNet/Manual/Utility/Time.cs
Normal 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
|
||||
}
|
||||
Loading…
Reference in a new issue