From 1f982e4dc7494fbe8f2c34a39ac6e457226136c7 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Fri, 28 Oct 2016 21:31:41 +0300 Subject: [PATCH] Find objects from world packets using both ID and reference number --- apps/openmw/mwmp/Networking.cpp | 20 ++++++------ apps/openmw/mwworld/cellstore.cpp | 52 +++++++++++++++---------------- apps/openmw/mwworld/cellstore.hpp | 4 +-- 3 files changed, 38 insertions(+), 38 deletions(-) diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index 0cb5ca1f5..2b3539c15 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -723,7 +723,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) event->cellRef.mRefNum.mIndex, event->cell.getDescription().c_str()); - MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + MWWorld::Ptr ptrFound = ptrCellStore->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex); if (ptrFound) { @@ -744,7 +744,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) event->cellRef.mRefNum.mIndex, event->cell.getDescription().c_str()); - MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + MWWorld::Ptr ptrFound = ptrCellStore->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex); if (ptrFound) { @@ -765,7 +765,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) event->cellRef.mRefNum.mIndex, event->cell.getDescription().c_str()); - MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + MWWorld::Ptr ptrFound = ptrCellStore->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex); if (ptrFound) { @@ -786,7 +786,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) event->cellRef.mRefNum.mIndex, event->cell.getDescription().c_str()); - MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + MWWorld::Ptr ptrFound = ptrCellStore->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex); if (ptrFound) { @@ -807,7 +807,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) event->cellRef.mRefNum.mIndex, event->cell.getDescription().c_str()); - MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + MWWorld::Ptr ptrFound = ptrCellStore->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex); if (ptrFound) { @@ -829,7 +829,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) event->cellRef.mRefNum.mIndex, event->cell.getDescription().c_str()); - MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + MWWorld::Ptr ptrFound = ptrCellStore->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex); if (ptrFound) { @@ -851,7 +851,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) event->cellRef.mRefNum.mIndex, event->cell.getDescription().c_str()); - MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + MWWorld::Ptr ptrFound = ptrCellStore->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex); if (ptrFound) { @@ -873,7 +873,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) event->cellRef.mRefNum.mIndex, event->cell.getDescription().c_str()); - MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + MWWorld::Ptr ptrFound = ptrCellStore->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex); if (ptrFound) { @@ -908,7 +908,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) event->index, event->shortVal); - MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + MWWorld::Ptr ptrFound = ptrCellStore->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex); if (ptrFound) { @@ -931,7 +931,7 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) event->index, event->floatVal); - MWWorld::Ptr ptrFound = ptrCellStore->searchByRefNum(event->cellRef.mRefNum); + MWWorld::Ptr ptrFound = ptrCellStore->searchExact(event->cellRef.mRefID, event->cellRef.mRefNum.mIndex); if (ptrFound) { diff --git a/apps/openmw/mwworld/cellstore.cpp b/apps/openmw/mwworld/cellstore.cpp index 7fdf8c71d..b833ea821 100644 --- a/apps/openmw/mwworld/cellstore.cpp +++ b/apps/openmw/mwworld/cellstore.cpp @@ -168,30 +168,6 @@ namespace return true; } }; - - // Added by tes3mp - template - struct SearchByRefNumCustomVisitor - { - PtrType mFound; - ESM::RefNum mRefNumToFind; - - SearchByRefNumCustomVisitor(const ESM::RefNum& toFind) - : mFound(NULL) - , mRefNumToFind(toFind) - { - } - - bool operator()(const PtrType& ptr) - { - if (ptr.getCellRef().getRefNum().mIndex == mRefNumToFind.mIndex) - { - mFound = ptr; - return false; - } - return true; - } - }; } namespace MWWorld @@ -466,9 +442,33 @@ namespace MWWorld } // Added by tes3mp - Ptr CellStore::searchByRefNum (ESM::RefNum refNum) + template + struct SearchExactVisitor { - SearchByRefNumCustomVisitor searchVisitor(refNum); + PtrType mFound; + std::string mIdToFind; + int mRefNumIndexToFind; + + bool operator()(const PtrType& ptr) + { + if (ptr.getCellRef().getRefNum().mIndex == mRefNumIndexToFind) + { + if (ptr.getCellRef().getRefId() == mIdToFind) + { + mFound = ptr; + return false; + } + } + return true; + } + }; + + ///< Added by tes3mp and used to find an object by both its ID and its reference number + Ptr CellStore::searchExact (const std::string& id, int numIndex) + { + SearchExactVisitor searchVisitor; + searchVisitor.mIdToFind = id; + searchVisitor.mRefNumIndexToFind = numIndex; forEach(searchVisitor); return searchVisitor.mFound; } diff --git a/apps/openmw/mwworld/cellstore.hpp b/apps/openmw/mwworld/cellstore.hpp index 2cffa4c54..be672665f 100644 --- a/apps/openmw/mwworld/cellstore.hpp +++ b/apps/openmw/mwworld/cellstore.hpp @@ -231,8 +231,8 @@ namespace MWWorld Ptr searchViaActorId (int id); ///< Will return an empty Ptr if cell is not loaded. - Ptr searchByRefNum (ESM::RefNum refNum); - ///< Added by tes3mp + Ptr searchExact (const std::string& id, int numIndex); + ///< Added by tes3mp and used to find an object by both its ID and its reference number float getWaterLevel() const;