Delegates for PacketReader
dogwatch opened this issue · 1 comments
dogwatch commented
Activator.CreateInstance slow. Maybe use delegates?
public delegate IPacket CreatePacket();
private static readonly CreatePacket[] Packets = new CreatePacket[]
{
() => new KeepAlivePacket(), // 0x00
() => new LoginRequestPacket(), // 0x01
() => new HandshakePacket(), // 0x02
...
public static IPacket ReadPacket(MinecraftStream stream)
{
...
var packet = type();
packet.ReadPacket(stream);
return packet;
}
public static void OverridePacket(CreatePacket factory)
{
var instance = factory();
Packets[instance.Id] = factory;
}
ddevault commented
This is a good idea, but one that I don't have time to implement. A pull request is welcome as always.