ddevault / Craft.Net

(Unmaintained, see TrueCraft) Minecraft server, client, and etc for .NET
MIT License
228 stars 64 forks source link

Delegates for PacketReader #178

Closed dogwatch closed 10 years ago

dogwatch commented 10 years ago

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 10 years ago

This is a good idea, but one that I don't have time to implement. A pull request is welcome as always.