From be36cc6e19b154daa2a09c0b43fbc13203184423 Mon Sep 17 00:00:00 2001 From: Zach Toogood Date: Thu, 23 Jan 2025 15:04:07 +0000 Subject: [PATCH] Core: Rollback pending packet changes to raw ptr forms --- src/map/entities/charentity.cpp | 28 ++++++++++++++++++---------- src/map/entities/charentity.h | 11 +++++++---- 2 files changed, 25 insertions(+), 14 deletions(-) diff --git a/src/map/entities/charentity.cpp b/src/map/entities/charentity.cpp index 6fc5782a8c1..cadbdbf91c6 100644 --- a/src/map/entities/charentity.cpp +++ b/src/map/entities/charentity.cpp @@ -422,11 +422,11 @@ void CCharEntity::pushPacket(std::unique_ptr&& packet) { if (PendingPositionPacket) { - PendingPositionPacket = packet->copy(); + PendingPositionPacket = packet.get(); } else { - PendingPositionPacket = packet->copy(); + PendingPositionPacket = packet.get(); PacketList.emplace_back(std::move(packet)); } } @@ -442,13 +442,17 @@ void CCharEntity::updateCharPacket(CCharEntity* PChar, ENTITYUPDATE type, uint8 if (existing == PendingCharPackets.end()) { // No existing packet update for the given char, so we push new packet - PacketList.emplace_back(std::make_unique(PChar, type, updatemask)); - PendingCharPackets.emplace(PChar->id, std::make_unique(PChar, type, updatemask)); + auto packet = std::make_unique(PChar, type, updatemask); + PendingCharPackets.emplace(PChar->id, packet.get()); + PacketList.emplace_back(std::move(packet)); } else { - // Found existing packet update for the given char, so we update it instead of pushing new - existing->second->updateWith(PChar, type, updatemask); + if (existing->second != nullptr) + { + // Found existing packet update for the given char, so we update it instead of pushing new + existing->second->updateWith(PChar, type, updatemask); + } } } @@ -458,13 +462,17 @@ void CCharEntity::updateEntityPacket(CBaseEntity* PEntity, ENTITYUPDATE type, ui if (existing == PendingEntityPackets.end()) { // No existing packet update for the given entity, so we push new packet - PacketList.emplace_back(std::make_unique(PEntity, type, updatemask)); - PendingEntityPackets.emplace(PEntity->id, std::make_unique(PEntity, type, updatemask)); + auto packet = std::make_unique(PEntity, type, updatemask); + PendingEntityPackets.emplace(PEntity->id, packet.get()); + PacketList.emplace_back(std::move(packet)); } else { - // Found existing packet update for the given entity, so we update it instead of pushing new - existing->second->updateWith(PEntity, type, updatemask); + if (existing->second != nullptr) + { + // Found existing packet update for the given entity, so we update it instead of pushing new + existing->second->updateWith(PEntity, type, updatemask); + } } } diff --git a/src/map/entities/charentity.h b/src/map/entities/charentity.h index 0763bada951..8afbca6ab94 100644 --- a/src/map/entities/charentity.h +++ b/src/map/entities/charentity.h @@ -542,7 +542,8 @@ class CCharEntity : public CBattleEntity CItemEquipment* getEquip(SLOTTYPE slot); - std::unique_ptr PendingPositionPacket = nullptr; + // TODO: Don't use raw ptrs for this, but don't duplicate whole packets with unique_ptr either. + CBasicPacket* PendingPositionPacket = nullptr; bool requestedInfoSync = false; @@ -663,9 +664,11 @@ class CCharEntity : public CBattleEntity uint8 dataToPersist = 0; time_point nextDataPersistTime; - std::deque> PacketList; // The list of packets to be sent to the character during the next network cycle - std::unordered_map> PendingCharPackets; // Keep track of which char packets are queued up for this char, such that they can be updated - std::unordered_map> PendingEntityPackets; // Keep track of which entity update packets are queued up for this char, such that they can be updated + std::deque> PacketList; // The list of packets to be sent to the character during the next network cycle + + // TODO: Don't use raw ptrs for this, but don't duplicate whole packets with unique_ptr either. + std::unordered_map PendingCharPackets; // Keep track of which char packets are queued up for this char, such that they can be updated + std::unordered_map PendingEntityPackets; // Keep track of which entity update packets are queued up for this char, such that they can be updated }; #endif