Remove dead code and encapsulate more in Sync.cs.

This commit is contained in:
RoosterDragon
2016-01-30 00:25:57 +00:00
parent c22281876c
commit eb3be990a6
2 changed files with 9 additions and 20 deletions

View File

@@ -38,12 +38,11 @@ namespace OpenRA
{ typeof(int2), ((Func<int2, int>)HashInt2).Method }, { typeof(int2), ((Func<int2, int>)HashInt2).Method },
{ typeof(CPos), ((Func<CPos, int>)HashCPos).Method }, { typeof(CPos), ((Func<CPos, int>)HashCPos).Method },
{ typeof(CVec), ((Func<CVec, int>)HashCVec).Method }, { typeof(CVec), ((Func<CVec, int>)HashCVec).Method },
{ typeof(WDist), ((Func<WDist, int>)Hash).Method }, { typeof(WDist), ((Func<WDist, int>)HashUsingHashCode).Method },
{ typeof(WPos), ((Func<WPos, int>)Hash).Method }, { typeof(WPos), ((Func<WPos, int>)HashUsingHashCode).Method },
{ typeof(WVec), ((Func<WVec, int>)Hash).Method }, { typeof(WVec), ((Func<WVec, int>)HashUsingHashCode).Method },
{ typeof(WAngle), ((Func<WAngle, int>)Hash).Method }, { typeof(WAngle), ((Func<WAngle, int>)HashUsingHashCode).Method },
{ typeof(WRot), ((Func<WRot, int>)Hash).Method }, { typeof(WRot), ((Func<WRot, int>)HashUsingHashCode).Method },
{ typeof(TypeDictionary), ((Func<TypeDictionary, int>)HashTDict).Method },
{ typeof(Actor), ((Func<Actor, int>)HashActor).Method }, { typeof(Actor), ((Func<Actor, int>)HashActor).Method },
{ typeof(Player), ((Func<Player, int>)HashPlayer).Method }, { typeof(Player), ((Func<Player, int>)HashPlayer).Method },
{ typeof(Target), ((Func<Target, int>)HashTarget).Method }, { typeof(Target), ((Func<Target, int>)HashTarget).Method },
@@ -62,15 +61,13 @@ namespace OpenRA
il.Emit(OpCodes.Ldc_I4, 0x555); il.Emit(OpCodes.Ldc_I4, 0x555);
il.MarkLabel(l); il.MarkLabel(l);
} }
else if (type.HasAttribute<SyncAttribute>())
il.EmitCall(OpCodes.Call, ((Func<object, int>)CalculateSyncHash).Method, null);
else if (type != typeof(int)) else if (type != typeof(int))
throw new NotImplementedException("SyncAttribute on member of unhashable type: {0}".F(type.FullName)); throw new NotImplementedException("SyncAttribute on member of unhashable type: {0}".F(type.FullName));
il.Emit(OpCodes.Xor); il.Emit(OpCodes.Xor);
} }
public static Func<object, int> GenerateHashFunc(Type t) static Func<object, int> GenerateHashFunc(Type t)
{ {
var d = new DynamicMethod("hash_{0}".F(t.Name), typeof(int), new Type[] { typeof(object) }, t); var d = new DynamicMethod("hash_{0}".F(t.Name), typeof(int), new Type[] { typeof(object) }, t);
var il = d.GetILGenerator(); var il = d.GetILGenerator();
@@ -116,14 +113,6 @@ namespace OpenRA
return ((i2.X * 5) ^ (i2.Y * 3)) / 4; 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) public static int HashActor(Actor a)
{ {
if (a != null) if (a != null)
@@ -152,7 +141,7 @@ namespace OpenRA
return (int)(t.FrozenActor.Actor.ActorID << 16) * 0x567; return (int)(t.FrozenActor.Actor.ActorID << 16) * 0x567;
case TargetType.Terrain: case TargetType.Terrain:
return Hash(t.CenterPosition); return HashUsingHashCode(t.CenterPosition);
default: default:
case TargetType.Invalid: case TargetType.Invalid:
@@ -160,7 +149,7 @@ namespace OpenRA
} }
} }
public static int Hash<T>(T t) public static int HashUsingHashCode<T>(T t)
{ {
return t.GetHashCode(); return t.GetHashCode();
} }

View File

@@ -63,7 +63,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
var hash = 0; var hash = 0;
foreach (var objective in objectives) foreach (var objective in objectives)
hash ^= Sync.Hash(objective.State); hash ^= Sync.HashUsingHashCode(objective.State);
return hash; return hash;
} }
} }