From 07c762068f23b5207bd76ad1ff3b26d95fe8b9cb Mon Sep 17 00:00:00 2001 From: Chris Miles Date: Mon, 27 Jan 2025 15:32:14 -0600 Subject: [PATCH] [Performance] Re-use ClientUpdate packet memory (#4619) --- zone/aura.cpp | 9 +++++---- zone/client_packet.cpp | 28 ++++++++++++---------------- zone/mob_movement_manager.cpp | 8 ++++---- zone/npc.cpp | 7 +++---- 4 files changed, 24 insertions(+), 28 deletions(-) diff --git a/zone/aura.cpp b/zone/aura.cpp index f1285dc5e..692dc9f0f 100644 --- a/zone/aura.cpp +++ b/zone/aura.cpp @@ -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? diff --git a/zone/client_packet.cpp b/zone/client_packet.cpp index 031b51078..03aa87f10 100644 --- a/zone/client_packet.cpp +++ b/zone/client_packet.cpp @@ -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 { diff --git a/zone/mob_movement_manager.cpp b/zone/mob_movement_manager.cpp index 661c046a1..ea0eb5ad2 100644 --- a/zone/mob_movement_manager.cpp +++ b/zone/mob_movement_manager.cpp @@ -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(); } } diff --git a/zone/npc.cpp b/zone/npc.cpp index ba5782c34..16027b8a6 100644 --- a/zone/npc.cpp +++ b/zone/npc.cpp @@ -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()