From 765b62c7cc31a43456051cbf6c07f35963ccce54 Mon Sep 17 00:00:00 2001 From: sin365 <353374337@qq.com> Date: Fri, 20 Dec 2024 17:57:29 +0800 Subject: [PATCH] =?UTF-8?q?VirtualNes.Core=E6=A0=B8=E5=BF=83=E4=BD=8E?= =?UTF-8?q?=E7=89=88=E6=9C=ACC#=E5=85=BC=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Supporter/ControllerState.cs | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/AxibugEmuOnline.Client.Transplant/Assets/VirtualNes.Core/Supporter/ControllerState.cs b/AxibugEmuOnline.Client.Transplant/Assets/VirtualNes.Core/Supporter/ControllerState.cs index edb443d..7b0a091 100644 --- a/AxibugEmuOnline.Client.Transplant/Assets/VirtualNes.Core/Supporter/ControllerState.cs +++ b/AxibugEmuOnline.Client.Transplant/Assets/VirtualNes.Core/Supporter/ControllerState.cs @@ -56,11 +56,29 @@ namespace VirtualNes.Core public override int GetHashCode() { //return HashCode.Combine(raw0, raw1, raw2, raw3, valid); - return raw0.GetHashCode()+ raw1.GetHashCode()+ raw2.GetHashCode()+ raw3.GetHashCode(); - + return ComputeHashCode(raw0, raw1, raw2, raw3, valid); } - - public static bool operator ==(ControllerState left, ControllerState right) + + public static int ComputeHashCode(uint raw0, uint raw1, uint raw2, uint raw3, bool valid) + { + unchecked // 允许溢出,使得哈希码计算更加合理 + { + int hash = 17; // 选择一个非零的初始值 + + // 将每个 uint 类型的值转换为 int 并合并到哈希码中 + hash = hash * 31 + (int)raw0; + hash = hash * 31 + (int)raw1; + hash = hash * 31 + (int)raw2; + hash = hash * 31 + (int)raw3; + + // 将 bool 类型的值转换为 int 并合并到哈希码中 + hash = hash * 31 + (valid ? 1 : 0); + + return hash; + } + } + + public static bool operator ==(ControllerState left, ControllerState right) { return left.raw0 == right.raw0 &&