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

@ -3844,8 +3844,8 @@ namespace Server.Mobiles
IsDeadPet = false;
Span<byte> buffer = stackalloc byte[OutgoingMobilePackets.BondedStatusPacketLength];
OutgoingMobilePackets.CreateBondedStatus(ref buffer, Serial, false);
Effects.SendPacket(Location, Map, ref buffer);
OutgoingMobilePackets.CreateBondedStatus(buffer, Serial, false);
Effects.SendPacket(Location, Map, buffer);
SendIncomingPacket();
SendIncomingPacket();

View file

@ -2827,20 +2827,7 @@ namespace Server.Mobiles
private static void SendToStaffMessage(Mobile from, string text)
{
Span<byte> buffer = stackalloc byte[OutgoingMessagePackets.GetMaxMessageLength(text)];
var length = OutgoingMessagePackets.CreateMessage(
ref buffer,
from.Serial,
from.Body,
MessageType.Regular,
from.SpeechHue,
3,
false,
from.Language,
from.Name,
text
);
buffer = buffer.Slice(0, length); // Adjust to the actual size
buffer.InitializePacket();
foreach (var ns in from.GetClientsInRange(8))
{
@ -2848,6 +2835,24 @@ namespace Server.Mobiles
if (mob?.AccessLevel >= AccessLevel.GameMaster && mob.AccessLevel > from.AccessLevel)
{
if (buffer[0] == 0)
{
var length = OutgoingMessagePackets.CreateMessage(
buffer,
from.Serial,
from.Body,
MessageType.Regular,
from.SpeechHue,
3,
false,
from.Language,
from.Name,
text
);
buffer = buffer.Slice(0, length); // Adjust to the actual size
}
ns.Send(buffer);
}
}