MessagePacker: remove reundant GetId version. GetId<T> is enough.

This commit is contained in:
vis2k 2020-10-08 10:42:32 +02:00
parent c709682344
commit 7363de93ba
2 changed files with 3 additions and 8 deletions

View File

@ -18,16 +18,11 @@ public static class MessagePacker
{
public static int GetId<T>()
where T : struct, NetworkMessage
{
return GetId(typeof(T));
}
public static int GetId(Type type)
{
// paul: 16 bits is enough to avoid collisions
// - keeps the message size small because it gets varinted
// - in case of collisions, Mirror will display an error
return type.FullName.GetStableHashCode() & 0xFFFF;
return typeof(T).FullName.GetStableHashCode() & 0xFFFF;
}
// pack message before sending
@ -40,7 +35,7 @@ public static void Pack<T>(T message, NetworkWriter writer)
// this works because value types cannot be derived
// if it is a reference type (for example NetworkMessage),
// ask the message for the real type
int msgType = GetId(typeof(T));
int msgType = GetId<T>();
writer.WriteUInt16((ushort)msgType);
// serialize message into writer

View File

@ -190,7 +190,7 @@ public bool InvokeHandler<T>(T msg)
// this works because value types cannot be derived
// if it is a reference type (for example IMessageBase),
// ask the message for the real type
int msgType = MessagePacker.GetId(typeof(T));
int msgType = MessagePacker.GetId<T>();
MessagePacker.Pack(msg, writer);
ArraySegment<byte> segment = writer.ToArraySegment();