From 8709c35ff183d396a332a912a3a88152642f81de Mon Sep 17 00:00:00 2001 From: Infi Date: Fri, 3 May 2024 19:37:39 +0200 Subject: [PATCH] Switch to .net method for endian swap --- ChatTwo/MessageManager.cs | 4 ++++ ChatTwo/Util/ColourUtil.cs | 12 ++++-------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/ChatTwo/MessageManager.cs b/ChatTwo/MessageManager.cs index c0a15c0..350b4d7 100644 --- a/ChatTwo/MessageManager.cs +++ b/ChatTwo/MessageManager.cs @@ -92,6 +92,7 @@ internal class MessageManager : IAsyncDisposable while (!token.IsCancellationRequested) { if (Pending.TryDequeue(out var pendingMessage)) + { try { ProcessMessage(pendingMessage); @@ -100,8 +101,11 @@ internal class MessageManager : IAsyncDisposable { Plugin.Log.Error(ex, "Error processing pending message"); } + } else + { Thread.Sleep(1); + } } } diff --git a/ChatTwo/Util/ColourUtil.cs b/ChatTwo/Util/ColourUtil.cs index 145afe6..0a5154d 100755 --- a/ChatTwo/Util/ColourUtil.cs +++ b/ChatTwo/Util/ColourUtil.cs @@ -1,3 +1,4 @@ +using System.Buffers.Binary; using System.Numerics; namespace ChatTwo.Util; @@ -11,10 +12,7 @@ internal static class ColourUtil { return (r, g, b, a); } - internal static uint RgbaToAbgr(uint rgba) { - var tmp = ((rgba << 8) & 0xFF00FF00) | ((rgba >> 8) & 0xFF00FF); - return (tmp << 16) | (tmp >> 16); - } + internal static uint RgbaToAbgr(uint rgba) => BinaryPrimitives.ReverseEndianness(rgba); internal static Vector3 RgbaToVector3(uint rgba) { var (r, g, b, _) = RgbaToComponents(rgba); @@ -45,8 +43,6 @@ internal static class ColourUtil { return x; } - internal static uint ComponentsToRgba(byte red, byte green, byte blue, byte alpha = 0xFF) => alpha - | (uint) (red << 24) - | (uint) (green << 16) - | (uint) (blue << 8); + internal static uint ComponentsToRgba(byte red, byte green, byte blue, byte alpha = 0xFF) + => alpha | (uint) (red << 24) | (uint) (green << 16) | (uint) (blue << 8); }