fix(core): Cleans up uninitialized packets (#397)

- [X] Encapsulates/abstracts buffer cache checking
- [X] Changes mobile moving cache to use Span2D
This commit is contained in:
Kamron Batman 2021-01-09 14:10:29 -08:00 committed by GitHub
parent 0b9fb9c071
commit 8763be8a21
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 417 additions and 529 deletions

View file

@ -72,20 +72,14 @@ namespace Server
if (map != null)
{
Span<byte> buffer = stackalloc byte[OutgoingEffectPackets.SoundPacketLength];
buffer.InitializePacket();
Span<byte> buffer = stackalloc byte[OutgoingEffectPackets.SoundPacketLength].InitializePacket();
var eable = map.GetClientsInRange(new Point3D(p));
foreach (var state in eable)
{
state.Mobile.ProcessDelta();
if (buffer[0] == 0)
{
OutgoingEffectPackets.CreateSoundEffect(buffer, soundID, p);
}
OutgoingEffectPackets.CreateSoundEffect(buffer, soundID, p);
state.Send(buffer);
}
@ -104,16 +98,9 @@ namespace Server
e.ProcessDelta();
Span<byte> preEffect = stackalloc byte[OutgoingEffectPackets.ParticleEffectLength];
preEffect.InitializePacket();
Span<byte> boltEffect = stackalloc byte[OutgoingEffectPackets.BoltEffectLength];
boltEffect.InitializePacket();
Span<byte> soundEffect = sound ? stackalloc byte[OutgoingEffectPackets.SoundPacketLength] : null;
if (sound)
{
soundEffect.InitializePacket();
}
Span<byte> preEffect = stackalloc byte[OutgoingEffectPackets.ParticleEffectLength].InitializePacket();
Span<byte> boltEffect = stackalloc byte[OutgoingEffectPackets.BoltEffectLength].InitializePacket();
Span<byte> soundEffect = sound ? stackalloc byte[OutgoingEffectPackets.SoundPacketLength].InitializePacket() : null;
var eable = map.GetClientsInRange(e.Location);
@ -123,31 +110,19 @@ namespace Server
{
if (SendParticlesTo(state))
{
if (preEffect[0] == 0)
{
OutgoingEffectPackets.CreateTargetParticleEffect(
preEffect,
e, 0, 10, 5, 0, 0, 5031, 3, 0
);
}
OutgoingEffectPackets.CreateTargetParticleEffect(
preEffect,
e, 0, 10, 5, 0, 0, 5031, 3, 0
);
state.Send(preEffect);
}
if (boltEffect[0] == 0)
{
OutgoingEffectPackets.CreateBoltEffect(boltEffect, e, hue);
}
OutgoingEffectPackets.CreateBoltEffect(boltEffect, e, hue);
state.Send(boltEffect);
if (sound)
{
if (soundEffect[0] == 0)
{
OutgoingEffectPackets.CreateSoundEffect(soundEffect, 0x29, e);
}
OutgoingEffectPackets.CreateSoundEffect(soundEffect, 0x29, e);
state.Send(soundEffect);
}
}
@ -164,7 +139,7 @@ namespace Server
Point3D p, Map map, int itemID, int duration, int speed = 10, int hue = 0, int renderMode = 0
)
{
Span<byte> effect = stackalloc byte[OutgoingEffectPackets.HuedEffectLength];
Span<byte> effect = stackalloc byte[OutgoingEffectPackets.HuedEffectLength].InitializePacket();
OutgoingEffectPackets.CreateLocationHuedEffect(
effect,
p, itemID, speed, duration, hue, renderMode
@ -194,14 +169,9 @@ namespace Server
return;
}
Span<byte> particles = stackalloc byte[OutgoingEffectPackets.ParticleEffectLength];
particles.InitializePacket();
Span<byte> particles = stackalloc byte[OutgoingEffectPackets.ParticleEffectLength].InitializePacket();
Span<byte> regular = itemID != 0 ? stackalloc byte[OutgoingEffectPackets.HuedEffectLength] : null;
if (itemID != 0)
{
regular.InitializePacket();
}
Span<byte> regular = itemID != 0 ? stackalloc byte[OutgoingEffectPackets.HuedEffectLength].InitializePacket() : null;
var eable = map.GetClientsInRange(e.Location);
@ -211,26 +181,18 @@ namespace Server
if (SendParticlesTo(state))
{
if (particles[0] == 0)
{
OutgoingEffectPackets.CreateLocationParticleEffect(
particles,
e, itemID, speed, duration, hue, renderMode, effect, unknown
);
}
OutgoingEffectPackets.CreateLocationParticleEffect(
particles,
e, itemID, speed, duration, hue, renderMode, effect, unknown
);
state.Send(particles);
}
else if (itemID != 0)
{
if (regular[0] == 0)
{
OutgoingEffectPackets.CreateLocationHuedEffect(
regular,
e.Location, itemID, speed, duration, hue, renderMode
);
}
OutgoingEffectPackets.CreateLocationHuedEffect(
regular,
e.Location, itemID, speed, duration, hue, renderMode
);
state.Send(regular);
}
}
@ -242,7 +204,7 @@ namespace Server
{
(target as Mobile)?.ProcessDelta();
Span<byte> effect = stackalloc byte[OutgoingEffectPackets.HuedEffectLength];
Span<byte> effect = stackalloc byte[OutgoingEffectPackets.HuedEffectLength].InitializePacket();
OutgoingEffectPackets.CreateTargetHuedEffect(
effect,
target, itemID, speed, duration, hue, renderMode
@ -273,14 +235,8 @@ namespace Server
return;
}
Span<byte> particles = stackalloc byte[OutgoingEffectPackets.ParticleEffectLength];
particles.InitializePacket();
Span<byte> regular = itemID != 0 ? stackalloc byte[OutgoingEffectPackets.HuedEffectLength] : null;
if (itemID != 0)
{
regular.InitializePacket();
}
Span<byte> particles = stackalloc byte[OutgoingEffectPackets.ParticleEffectLength].InitializePacket();
Span<byte> regular = itemID != 0 ? stackalloc byte[OutgoingEffectPackets.HuedEffectLength].InitializePacket() : null;
var eable = map.GetClientsInRange(target.Location);
@ -290,23 +246,15 @@ namespace Server
if (SendParticlesTo(state))
{
if (particles[0] == 0)
{
OutgoingEffectPackets.CreateTargetParticleEffect(
particles,
target, itemID, speed, duration, hue, renderMode, effect, (int)layer, unknown
);
}
OutgoingEffectPackets.CreateTargetParticleEffect(
particles,
target, itemID, speed, duration, hue, renderMode, effect, (int)layer, unknown
);
state.Send(particles);
}
else if (itemID != 0)
{
if (regular[0] == 0)
{
OutgoingEffectPackets.CreateTargetHuedEffect(regular, target, itemID, speed, duration, hue, renderMode);
}
OutgoingEffectPackets.CreateTargetHuedEffect(regular, target, itemID, speed, duration, hue, renderMode);
state.Send(regular);
}
}
@ -503,14 +451,8 @@ namespace Server
return;
}
Span<byte> particles = stackalloc byte[OutgoingEffectPackets.ParticleEffectLength];
particles.InitializePacket();
Span<byte> regular = itemID != 0 ? stackalloc byte[OutgoingEffectPackets.HuedEffectLength] : null;
if (itemID != 0)
{
regular.InitializePacket();
}
Span<byte> particles = stackalloc byte[OutgoingEffectPackets.ParticleEffectLength].InitializePacket();
Span<byte> regular = itemID != 0 ? stackalloc byte[OutgoingEffectPackets.HuedEffectLength].InitializePacket() : null;
var eable = map.GetClientsInRange(from.Location);
@ -520,27 +462,19 @@ namespace Server
if (SendParticlesTo(state))
{
if (particles[0] == 0)
{
OutgoingEffectPackets.CreateMovingParticleEffect(
particles,
from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode, effect,
explodeEffect, explodeSound, layer, unknown
);
}
OutgoingEffectPackets.CreateMovingParticleEffect(
particles,
from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode, effect,
explodeEffect, explodeSound, layer, unknown
);
state.Send(particles);
}
else if (itemID > 1)
{
if (regular[0] == 0)
{
OutgoingEffectPackets.CreateMovingHuedEffect(
regular,
from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode
);
}
OutgoingEffectPackets.CreateMovingHuedEffect(
regular,
from, to, itemID, speed, duration, fixedDirection, explodes, hue, renderMode
);
state.Send(regular);
}
}