fix(core): Adds SkipLocalsInitAttribute support, optimizes broadcasted packets (#363)

- [X] Adds support for `SkipLocalsInitAttribute`. SkipLocalsInitAttribute skips initializing stack variables including `stackalloc`. I don't think it is wired/working yet but should be implemented soon.
- [X] Optimizes broadcasted packets by checking if the first byte (packet ID) is non-zero. If it is already set, it reuses the buffer.
- [X] Removes unnecessary refs to Spans. I don't think the Span struct itself is mutable, so a ref is not helpful.
This commit is contained in:
Kamron Batman 2020-12-26 12:46:06 -08:00 committed by GitHub
parent 9c9591b098
commit 03d0a4664e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
25 changed files with 478 additions and 285 deletions

View file

@ -23,7 +23,7 @@ namespace Server.Network
{
public const int MaxWorldItemPacketLength = 26;
public static int CreateWorldItem(ref Span<byte> buffer, Item item)
public static int CreateWorldItem(Span<byte> buffer, Item item)
{
var itemID = item is BaseMulti ? item.ItemID | 0x4000 : item.ItemID & 0x3FFF;
var hasAmount = item.Amount != 0;
@ -87,13 +87,13 @@ namespace Server.Network
Span<byte> buffer = stackalloc byte[MaxWorldItemPacketLength];
var length = ns.StygianAbyss ?
CreateWorldItemNew(ref buffer, item, ns.HighSeas) :
CreateWorldItem(ref buffer, item);
CreateWorldItemNew(buffer, item, ns.HighSeas) :
CreateWorldItem(buffer, item);
ns.Send(buffer.Slice(0, length));
}
public static int CreateWorldItemNew(ref Span<byte> buffer, Item item, bool isHS)
public static int CreateWorldItemNew(Span<byte> buffer, Item item, bool isHS)
{
var writer = new SpanWriter(buffer);
writer.Write((byte)0xF3); // Packet ID