aboutsummaryrefslogtreecommitdiff
path: root/Tools/Hazel-Networking/Hazel/Extensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Tools/Hazel-Networking/Hazel/Extensions.cs')
-rw-r--r--Tools/Hazel-Networking/Hazel/Extensions.cs34
1 files changed, 34 insertions, 0 deletions
diff --git a/Tools/Hazel-Networking/Hazel/Extensions.cs b/Tools/Hazel-Networking/Hazel/Extensions.cs
new file mode 100644
index 0000000..dd3a1bc
--- /dev/null
+++ b/Tools/Hazel-Networking/Hazel/Extensions.cs
@@ -0,0 +1,34 @@
+using System.Collections.Generic;
+
+namespace Hazel
+{
+ public static class Extensions
+ {
+ public static void Swap<T>(this IList<T> self, int idx0, int idx1)
+ {
+ var temp = self[idx0];
+ self[idx0] = self[idx1];
+ self[idx1] = temp;
+ }
+
+ public static int ClampToInt(this float value, int min, int max)
+ {
+ int output = (int)value;
+ if (output < min) output = min;
+ else if (output > max) output = max;
+ return output;
+ }
+
+ public static bool TryDequeue<T>(this Queue<T> self, out T item)
+ {
+ if (self.Count > 0)
+ {
+ item = self.Dequeue();
+ return true;
+ }
+
+ item = default;
+ return false;
+ }
+ }
+}