Add necessary packets to a static hashset for further performance boosts

title
This commit is contained in:
ohayo 2025-02-04 11:28:09 +10:00
parent 52d1840003
commit fa3c144274

View file

@ -2102,15 +2102,10 @@ namespace TShockAPI
SendData(PacketTypes.PlayerAddBuff, number: Index, number2: type, number3: time); SendData(PacketTypes.PlayerAddBuff, number: Index, number2: type, number3: time);
} }
/// <summary> /// <summary>
/// Determines if an outgoing packet is necessary to send to a player before they have finished the connection handshake. /// The list of necessary packets to make sure gets through to the player upon connection (before they finish the handshake).
/// </summary> /// </summary>
/// <param name="msgType">The packet type to check against the necessary list.</param> private static readonly HashSet<PacketTypes> NecessaryPackets = new()
/// <returns></returns>
private bool NecessaryPacket(PacketTypes msgType)
{
List<PacketTypes> ConnectionPackets = new List<PacketTypes>()
{ {
PacketTypes.ContinueConnecting, PacketTypes.ContinueConnecting,
PacketTypes.WorldInfo, PacketTypes.WorldInfo,
@ -2121,8 +2116,12 @@ namespace TShockAPI
PacketTypes.PlayerSpawnSelf PacketTypes.PlayerSpawnSelf
}; };
return ConnectionPackets.Contains(msgType); /// <summary>
} /// Determines if an outgoing packet is necessary to send to a player before they have finished the connection handshake.
/// </summary>
/// <param name="msgType">The packet type to check against the necessary list.</param>
/// <returns>Whether the packet is necessary for connection or not</returns>
private bool NecessaryPacket(PacketTypes msgType) => NecessaryPackets.Contains(msgType);
//Todo: Separate this into a few functions. SendTo, SendToAll, etc //Todo: Separate this into a few functions. SendTo, SendToAll, etc
/// <summary> /// <summary>