[Performance] Re-use ClientUpdate packet memory (#4619)

This commit is contained in:
Chris Miles 2025-01-27 15:32:14 -06:00 committed by GitHub
parent 6525051d2d
commit 07c762068f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 24 additions and 28 deletions

View File

@ -735,21 +735,22 @@ bool Aura::Process()
if (movement_type == AuraMovement::Follow && GetPosition() != owner->GetPosition() && movement_timer.Check()) {
m_Position = owner->GetPosition();
auto app = new EQApplicationPacket(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
auto spu = (PlayerPositionUpdateServer_Struct *) app->pBuffer;
static EQApplicationPacket packet(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
auto spu = (PlayerPositionUpdateServer_Struct *) packet.pBuffer;
MakeSpawnUpdate(spu);
auto it = spawned_for.begin();
while (it != spawned_for.end()) {
auto client = entity_list.GetClientByID(*it);
if (client) {
client->QueuePacket(app);
client->QueuePacket(&packet);
++it;
}
else {
it = spawned_for.erase(it);
}
}
safe_delete(app);
}
// TODO: waypoints?

View File

@ -4842,11 +4842,10 @@ void Client::Handle_OP_ClientUpdate(const EQApplicationPacket *app) {
auto boat_delta = glm::vec4(ppu->delta_x, ppu->delta_y, ppu->delta_z, EQ10toFloat(ppu->delta_heading));
cmob->SetDelta(boat_delta);
auto outapp = new EQApplicationPacket(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
PlayerPositionUpdateServer_Struct *ppus = (PlayerPositionUpdateServer_Struct *) outapp->pBuffer;
static EQApplicationPacket outapp(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
auto *ppus = (PlayerPositionUpdateServer_Struct *) outapp.pBuffer;
cmob->MakeSpawnUpdate(ppus);
entity_list.QueueCloseClients(cmob, outapp, true, 300, this, false);
safe_delete(outapp);
entity_list.QueueCloseClients(cmob, &outapp, true, 300, this, false);
/* Update the boat's position on the server, without sending an update */
cmob->GMMove(ppu->x_pos, ppu->y_pos, ppu->z_pos, EQ12toFloat(ppu->heading));
@ -5020,15 +5019,15 @@ void Client::Handle_OP_ClientUpdate(const EQApplicationPacket *app) {
m_Position.w = new_heading;
/* Broadcast update to other clients */
auto outapp = new EQApplicationPacket(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
PlayerPositionUpdateServer_Struct *position_update = (PlayerPositionUpdateServer_Struct *) outapp->pBuffer;
static EQApplicationPacket outapp(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
PlayerPositionUpdateServer_Struct *position_update = (PlayerPositionUpdateServer_Struct *) outapp.pBuffer;
MakeSpawnUpdate(position_update);
if (gm_hide_me) {
entity_list.QueueClientsStatus(this, outapp, true, Admin(), AccountStatus::Max);
entity_list.QueueClientsStatus(this, &outapp, true, Admin(), AccountStatus::Max);
} else {
entity_list.QueueCloseClients(this, outapp, true, RuleI(Range, ClientPositionUpdates), nullptr, true);
entity_list.QueueCloseClients(this, &outapp, true, RuleI(Range, ClientPositionUpdates), nullptr, true);
}
@ -5037,12 +5036,10 @@ void Client::Handle_OP_ClientUpdate(const EQApplicationPacket *app) {
Raid *raid = GetRaid();
if (raid) {
raid->QueueClients(this, outapp, true, true, (RuleI(Range, ClientPositionUpdates) * -1));
raid->QueueClients(this, &outapp, true, true, (RuleI(Range, ClientPositionUpdates) * -1));
} else if (group) {
group->QueueClients(this, outapp, true, true, (RuleI(Range, ClientPositionUpdates) * -1));
group->QueueClients(this, &outapp, true, true, (RuleI(Range, ClientPositionUpdates) * -1));
}
safe_delete(outapp);
}
if (zone->watermap) {
@ -16747,13 +16744,12 @@ bool Client::CanTradeFVNoDropItem()
void Client::SendMobPositions()
{
auto p = new EQApplicationPacket(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
auto *s = (PlayerPositionUpdateServer_Struct *) p->pBuffer;
static EQApplicationPacket p(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
auto *s = (PlayerPositionUpdateServer_Struct *) p.pBuffer;
for (auto &m: entity_list.GetMobList()) {
m.second->MakeSpawnUpdate(s);
QueuePacket(p, false);
QueuePacket(&p, false);
}
safe_delete(p);
}
struct RecordKillCheck {

View File

@ -824,8 +824,8 @@ void MobMovementManager::SendCommandToClients(
return;
}
EQApplicationPacket outapp(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
auto *spu = (PlayerPositionUpdateServer_Struct *) outapp.pBuffer;
static EQApplicationPacket p(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
auto *spu = (PlayerPositionUpdateServer_Struct *) p.pBuffer;
FillCommandStruct(spu, mob, delta_x, delta_y, delta_z, delta_heading, anim);
@ -862,7 +862,7 @@ void MobMovementManager::SendCommandToClients(
}
}
c->QueuePacket(&outapp, false);
c->QueuePacket(&p, false);
c->m_last_seen_mob_position[mob->GetID()] = mob->GetPosition();
}
}
@ -924,7 +924,7 @@ void MobMovementManager::SendCommandToClients(
}
}
c->QueuePacket(&outapp, false);
c->QueuePacket(&p, false);
c->m_last_seen_mob_position[mob->GetID()] = mob->GetPosition();
}
}

View File

@ -3824,13 +3824,12 @@ int NPC::GetRolledItemCount(uint32 item_id)
void NPC::SendPositionToClients()
{
auto p = new EQApplicationPacket(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
auto *s = (PlayerPositionUpdateServer_Struct *) p->pBuffer;
static EQApplicationPacket p(OP_ClientUpdate, sizeof(PlayerPositionUpdateServer_Struct));
auto *s = (PlayerPositionUpdateServer_Struct *) p.pBuffer;
for (auto &c: entity_list.GetClientList()) {
MakeSpawnUpdate(s);
c.second->QueuePacket(p, false);
c.second->QueuePacket(&p, false);
}
safe_delete(p);
}
void NPC::HandleRoambox()