Utils.cs 728 B

12345678910111213141516171819202122232425
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. using System.Runtime.InteropServices;
  4. namespace ET
  5. {
  6. public static partial class Utils
  7. {
  8. // Clamp so we don't have to depend on UnityEngine
  9. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  10. public static int Clamp(int value, int min, int max)
  11. {
  12. if (value < min) return min;
  13. if (value > max) return max;
  14. return value;
  15. }
  16. // timediff was a macro in original Kcp. let's inline it if possible.
  17. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  18. public static int TimeDiff(uint later, uint earlier)
  19. {
  20. return (int)(later - earlier);
  21. }
  22. }
  23. }