diff --git a/OpenRA.Game/Sync.cs b/OpenRA.Game/Sync.cs index 9492016424..85afe84109 100644 --- a/OpenRA.Game/Sync.cs +++ b/OpenRA.Game/Sync.cs @@ -38,12 +38,11 @@ namespace OpenRA { typeof(int2), ((Func)HashInt2).Method }, { typeof(CPos), ((Func)HashCPos).Method }, { typeof(CVec), ((Func)HashCVec).Method }, - { typeof(WDist), ((Func)Hash).Method }, - { typeof(WPos), ((Func)Hash).Method }, - { typeof(WVec), ((Func)Hash).Method }, - { typeof(WAngle), ((Func)Hash).Method }, - { typeof(WRot), ((Func)Hash).Method }, - { typeof(TypeDictionary), ((Func)HashTDict).Method }, + { typeof(WDist), ((Func)HashUsingHashCode).Method }, + { typeof(WPos), ((Func)HashUsingHashCode).Method }, + { typeof(WVec), ((Func)HashUsingHashCode).Method }, + { typeof(WAngle), ((Func)HashUsingHashCode).Method }, + { typeof(WRot), ((Func)HashUsingHashCode).Method }, { typeof(Actor), ((Func)HashActor).Method }, { typeof(Player), ((Func)HashPlayer).Method }, { typeof(Target), ((Func)HashTarget).Method }, @@ -62,15 +61,13 @@ namespace OpenRA il.Emit(OpCodes.Ldc_I4, 0x555); il.MarkLabel(l); } - else if (type.HasAttribute()) - il.EmitCall(OpCodes.Call, ((Func)CalculateSyncHash).Method, null); else if (type != typeof(int)) throw new NotImplementedException("SyncAttribute on member of unhashable type: {0}".F(type.FullName)); il.Emit(OpCodes.Xor); } - public static Func GenerateHashFunc(Type t) + static Func GenerateHashFunc(Type t) { var d = new DynamicMethod("hash_{0}".F(t.Name), typeof(int), new Type[] { typeof(object) }, t); var il = d.GetILGenerator(); @@ -116,14 +113,6 @@ namespace OpenRA return ((i2.X * 5) ^ (i2.Y * 3)) / 4; } - public static int HashTDict(TypeDictionary d) - { - var ret = 0; - foreach (var o in d) - ret += CalculateSyncHash(o); - return ret; - } - public static int HashActor(Actor a) { if (a != null) @@ -152,7 +141,7 @@ namespace OpenRA return (int)(t.FrozenActor.Actor.ActorID << 16) * 0x567; case TargetType.Terrain: - return Hash(t.CenterPosition); + return HashUsingHashCode(t.CenterPosition); default: case TargetType.Invalid: @@ -160,7 +149,7 @@ namespace OpenRA } } - public static int Hash(T t) + public static int HashUsingHashCode(T t) { return t.GetHashCode(); } diff --git a/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs b/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs index f50eb657cc..54176d24e7 100644 --- a/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs +++ b/OpenRA.Mods.Common/Traits/Player/MissionObjectives.cs @@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits { var hash = 0; foreach (var objective in objectives) - hash ^= Sync.Hash(objective.State); + hash ^= Sync.HashUsingHashCode(objective.State); return hash; } }