perf: rpc messages are now value types (#997)

This commit is contained in:
Paul Pacheco 2019-07-30 07:33:44 -05:00 committed by vis2k
parent f9ff44399b
commit b5b2f3e1eb

View File

@ -202,8 +202,7 @@ public void Serialize(NetworkWriter writer)
#endregion #endregion
#region System Messages requried for code gen path #region System Messages requried for code gen path
// remote calls like Rpc/Cmd/SyncEvent all use the same message type struct CommandMessage : IMessageBase
class RemoteCallMessage : MessageBase
{ {
public uint netId; public uint netId;
public int componentIndex; public int componentIndex;
@ -212,7 +211,7 @@ class RemoteCallMessage : MessageBase
// -> ArraySegment to avoid unnecessary allocations // -> ArraySegment to avoid unnecessary allocations
public ArraySegment<byte> payload; public ArraySegment<byte> payload;
public override void Deserialize(NetworkReader reader) public void Deserialize(NetworkReader reader)
{ {
netId = reader.ReadPackedUInt32(); netId = reader.ReadPackedUInt32();
componentIndex = (int)reader.ReadPackedUInt32(); componentIndex = (int)reader.ReadPackedUInt32();
@ -220,7 +219,7 @@ public override void Deserialize(NetworkReader reader)
payload = reader.ReadBytesAndSizeSegment(); payload = reader.ReadBytesAndSizeSegment();
} }
public override void Serialize(NetworkWriter writer) public void Serialize(NetworkWriter writer)
{ {
writer.WritePackedUInt32(netId); writer.WritePackedUInt32(netId);
writer.WritePackedUInt32((uint)componentIndex); writer.WritePackedUInt32((uint)componentIndex);
@ -229,11 +228,57 @@ public override void Serialize(NetworkWriter writer)
} }
} }
class CommandMessage : RemoteCallMessage {} struct RpcMessage : IMessageBase
{
public uint netId;
public int componentIndex;
public int functionHash;
// the parameters for the Cmd function
// -> ArraySegment to avoid unnecessary allocations
public ArraySegment<byte> payload;
class RpcMessage : RemoteCallMessage {} public void Deserialize(NetworkReader reader)
{
netId = reader.ReadPackedUInt32();
componentIndex = (int)reader.ReadPackedUInt32();
functionHash = reader.ReadInt32(); // hash is always 4 full bytes, WritePackedInt would send 1 extra byte here
payload = reader.ReadBytesAndSizeSegment();
}
class SyncEventMessage : RemoteCallMessage {} public void Serialize(NetworkWriter writer)
{
writer.WritePackedUInt32(netId);
writer.WritePackedUInt32((uint)componentIndex);
writer.WriteInt32(functionHash);
writer.WriteBytesAndSizeSegment(payload);
}
}
struct SyncEventMessage : IMessageBase
{
public uint netId;
public int componentIndex;
public int functionHash;
// the parameters for the Cmd function
// -> ArraySegment to avoid unnecessary allocations
public ArraySegment<byte> payload;
public void Deserialize(NetworkReader reader)
{
netId = reader.ReadPackedUInt32();
componentIndex = (int)reader.ReadPackedUInt32();
functionHash = reader.ReadInt32(); // hash is always 4 full bytes, WritePackedInt would send 1 extra byte here
payload = reader.ReadBytesAndSizeSegment();
}
public void Serialize(NetworkWriter writer)
{
writer.WritePackedUInt32(netId);
writer.WritePackedUInt32((uint)componentIndex);
writer.WriteInt32(functionHash);
writer.WriteBytesAndSizeSegment(payload);
}
}
#endregion #endregion
#region Internal System Messages #region Internal System Messages