Optimize reliable boolean in packets
This commit is contained in:
parent
990438011f
commit
779716b66e
@ -217,7 +217,6 @@ namespace NeonTea.Quakeball.TeaNet.Packets {
|
||||
public void WritePacket(Protocol protocol, Packet p) {
|
||||
int old = Bytes.Count;
|
||||
Write(protocol.GetPacketTypeID(p));
|
||||
p.WriteMeta(this);
|
||||
p.Write(this);
|
||||
p.Size = Bytes.Count - old;
|
||||
}
|
||||
@ -228,7 +227,6 @@ namespace NeonTea.Quakeball.TeaNet.Packets {
|
||||
int packetType = ReadInt();
|
||||
Type t = protocol.GetPacketType(packetType);
|
||||
Packet p = (Packet)Activator.CreateInstance(t);
|
||||
p.ReadMeta(this);
|
||||
p.Read(this);
|
||||
p.Size = pos - old;
|
||||
return p;
|
||||
|
@ -13,16 +13,6 @@ namespace NeonTea.Quakeball.TeaNet.Packets {
|
||||
/// <summary>Read and assign any relevant information about this packet from the buffer.</summary>
|
||||
public abstract void Read(ByteBuffer buffer);
|
||||
|
||||
/// <summary>Reads packet meta-information from the buffer.</summary>
|
||||
public void ReadMeta(ByteBuffer buffer) {
|
||||
PacketIsReliable = buffer.ReadBool();
|
||||
}
|
||||
|
||||
/// <summary>Writes packet meta-information to the buffer.</summary>
|
||||
public void WriteMeta(ByteBuffer buffer) {
|
||||
buffer.Write(PacketIsReliable);
|
||||
}
|
||||
|
||||
/// <summary>Make a shallow copy for this packet, copying any primitives but retaining any references to instances.</summary>
|
||||
public Packet ShallowCopy() {
|
||||
return (Packet)this.MemberwiseClone();
|
||||
|
@ -37,7 +37,7 @@ namespace NeonTea.Quakeball.TeaNet.Packets {
|
||||
return id;
|
||||
}
|
||||
|
||||
public ByteBuffer BuildMessage(Connection connection, int firstId) {
|
||||
public ByteBuffer BuildMessage(Connection connection, int firstId, bool reliable) {
|
||||
ByteBuffer buffer = new ByteBuffer();
|
||||
foreach (byte b in Peer.Fingerprint) {
|
||||
buffer.Write(b);
|
||||
@ -55,6 +55,7 @@ namespace NeonTea.Quakeball.TeaNet.Packets {
|
||||
buffer.Write((byte)PacketStage.Ready);
|
||||
buffer.Write(connection.Internal.LatestInwardReliable);
|
||||
buffer.Write(firstId);
|
||||
buffer.Write(reliable);
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
|
@ -97,7 +97,7 @@ namespace NeonTea.Quakeball.TeaNet.Peers {
|
||||
if (list.Length > 0) {
|
||||
firstId = list[0].PacketId;
|
||||
}
|
||||
ByteBuffer buffer = protocol.BuildMessage(conn, firstId);
|
||||
ByteBuffer buffer = protocol.BuildMessage(conn, firstId, true);
|
||||
buffer.Write(list.Length);
|
||||
foreach (Packet p in list) {
|
||||
buffer.WritePacket(protocol, p);
|
||||
@ -122,7 +122,7 @@ namespace NeonTea.Quakeball.TeaNet.Peers {
|
||||
p.PacketIsReliable = false;
|
||||
Protocol protocol = Peer.GetProtocol(conn.Internal.AssignedProtocol);
|
||||
if (protocol != null && conn.IsReady()) {
|
||||
ByteBuffer buffer = protocol.BuildMessage(conn, p.PacketId);
|
||||
ByteBuffer buffer = protocol.BuildMessage(conn, p.PacketId, false);
|
||||
buffer.Write(1);
|
||||
buffer.WritePacket(protocol, p);
|
||||
Send(conn, buffer);
|
||||
@ -174,7 +174,7 @@ namespace NeonTea.Quakeball.TeaNet.Peers {
|
||||
private void SendPlain(Connection conn) {
|
||||
Protocol protocol = Peer.GetProtocol(conn.Internal.AssignedProtocol);
|
||||
if (protocol != null) {
|
||||
ByteBuffer buffer = protocol.BuildMessage(conn, Int32.MaxValue);
|
||||
ByteBuffer buffer = protocol.BuildMessage(conn, Int32.MaxValue, false);
|
||||
Send(conn, buffer);
|
||||
}
|
||||
}
|
||||
@ -244,6 +244,7 @@ namespace NeonTea.Quakeball.TeaNet.Peers {
|
||||
|
||||
conn.Internal.LatestOutwardReliable = buffer.ReadInt();
|
||||
int FirstPacketId = buffer.ReadInt();
|
||||
bool Reliable = buffer.ReadBool();
|
||||
|
||||
ConcurrentQueue<Packet> queue = PacketQueue[conn.uid];
|
||||
Packet peeked;
|
||||
@ -261,6 +262,7 @@ namespace NeonTea.Quakeball.TeaNet.Peers {
|
||||
for (int i = 0; i < PacketAmount; i++) {
|
||||
Packet p = buffer.ReadPacket(protocol);
|
||||
p.PacketId = FirstPacketId + i;
|
||||
p.PacketIsReliable = Reliable;
|
||||
if (p.PacketIsReliable) {
|
||||
if (p.PacketId > conn.Internal.LatestInwardReliable) {
|
||||
conn.Internal.LatestInwardReliable = p.PacketId;
|
||||
|
Loading…
Reference in New Issue
Block a user