fix: Replaces throttlers and packet callbacks with function pointers (#1063)
Replaces multi-cast delegates with function pointers to gain 25% in performance and lower allocations.
This commit is contained in:
parent
b779d7737f
commit
f24b98f8e2
31 changed files with 189 additions and 172 deletions
|
|
@ -15,15 +15,11 @@
|
|||
|
||||
namespace Server.Network;
|
||||
|
||||
public delegate void OnPacketReceive(NetState state, CircularBufferReader reader, int packetLength);
|
||||
|
||||
public delegate bool ThrottlePacketCallback(int packetId, NetState state, out bool drop);
|
||||
|
||||
public class PacketHandler
|
||||
public unsafe class PacketHandler
|
||||
{
|
||||
private int _length;
|
||||
private readonly int _length;
|
||||
|
||||
public PacketHandler(int packetID, int length, bool ingame, OnPacketReceive onReceive)
|
||||
public PacketHandler(int packetID, int length, bool ingame, delegate*<NetState, CircularBufferReader, int, void> onReceive)
|
||||
{
|
||||
_length = length;
|
||||
PacketID = packetID;
|
||||
|
|
@ -35,9 +31,9 @@ public class PacketHandler
|
|||
|
||||
public virtual int GetLength(NetState ns) => _length;
|
||||
|
||||
public OnPacketReceive OnReceive { get; }
|
||||
public delegate*<NetState, CircularBufferReader, int, void> OnReceive { get; }
|
||||
|
||||
public ThrottlePacketCallback ThrottleCallback { get; set; }
|
||||
public delegate*<int, NetState, out bool, bool> ThrottleCallback { get; set; }
|
||||
|
||||
public bool Ingame { get; }
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue