Find objects from world packets using both ID and reference number

coverity_scan^2
David Cernat 8 years ago
parent d93e66207e
commit 1f982e4dc7

@ -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)
{

@ -168,30 +168,6 @@ namespace
return true;
}
};
// Added by tes3mp
template <typename PtrType>
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 <typename PtrType>
struct SearchExactVisitor
{
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)
{
SearchByRefNumCustomVisitor<MWWorld::Ptr> searchVisitor(refNum);
SearchExactVisitor<MWWorld::Ptr> searchVisitor;
searchVisitor.mIdToFind = id;
searchVisitor.mRefNumIndexToFind = numIndex;
forEach(searchVisitor);
return searchVisitor.mFound;
}

@ -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;

Loading…
Cancel
Save