[General] Combine CellStore's exact object searches

0.8.0
David Cernat 3 years ago
parent 6875c3422f
commit cc8c222d18

@ -365,14 +365,7 @@ void ObjectList::activateObjects(MWWorld::CellStore* cellStore)
else
{
LOG_APPEND(TimedLog::LOG_VERBOSE, "-- Activated object is %s %i-%i", baseObject.refId.c_str(), baseObject.refNum, baseObject.mpNum);
if (baseObject.refId.empty())
{
ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum);
}
else
{
ptrFound = cellStore->searchExactPlus(baseObject.refId, baseObject.refNum, baseObject.mpNum);
}
ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum, baseObject.refId);
}
if (ptrFound)
@ -1014,16 +1007,8 @@ void ObjectList::makeDialogueChoices(MWWorld::CellStore* cellStore)
for (const auto& baseObject : baseObjects)
{
LOG_APPEND(TimedLog::LOG_VERBOSE, "- cellRef: %s %i-%i", baseObject.refId.c_str(), baseObject.refNum, baseObject.mpNum);
MWWorld::Ptr ptrFound;
if (baseObject.refId.empty())
{
ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum);
}
else
{
ptrFound = cellStore->searchExactPlus(baseObject.refId, baseObject.refNum, baseObject.mpNum);
}
MWWorld::Ptr ptrFound = cellStore->searchExact(baseObject.refNum, baseObject.mpNum, baseObject.refId);
if (ptrFound)
{

@ -605,47 +605,21 @@ namespace MWWorld
{
const unsigned int mRefNumToFind;
const unsigned int mMpNumToFind;
public:
SearchExactVisitor(const unsigned int refNum, const unsigned int mpNum) : mRefNumToFind(refNum), mMpNumToFind(mpNum) {}
Ptr mFound;
bool operator()(const Ptr& ptr)
{
if (ptr.getCellRef().getRefNum().mIndex == mRefNumToFind && ptr.getCellRef().getMpNum() == mMpNumToFind)
{
mFound = ptr;
return false;
}
return true;
}
};
/*
End of tes3mp addition
*/
/*
Start of tes3mp addition
A custom type of search visitor used to find objects by their reference numbers
while ensuring they have a certain refId
*/
class SearchExactPlusVisitor
{
const std::string mRefIdToFind;
const unsigned int mRefNumToFind;
const unsigned int mMpNumToFind;
public:
SearchExactPlusVisitor(const std::string refId, const unsigned int refNum, const unsigned int mpNum) : mRefIdToFind(refId), mRefNumToFind(refNum), mMpNumToFind(mpNum) {}
SearchExactVisitor(const unsigned int refNum, const unsigned int mpNum, const std::string refId) : mRefNumToFind(refNum), mMpNumToFind(mpNum), mRefIdToFind(refId) {}
Ptr mFound;
bool operator()(const Ptr& ptr)
{
if (ptr.getCellRef().getRefNum().mIndex == mRefNumToFind && ptr.getCellRef().getMpNum() == mMpNumToFind && Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), mRefIdToFind))
if (ptr.getCellRef().getRefNum().mIndex == mRefNumToFind && ptr.getCellRef().getMpNum() == mMpNumToFind)
{
mFound = ptr;
return false;
if (mRefIdToFind.empty() || Misc::StringUtils::ciEqual(ptr.getCellRef().getRefId(), mRefIdToFind))
{
mFound = ptr;
return false;
}
}
return true;
}
@ -659,33 +633,13 @@ namespace MWWorld
Allow the searching of objects by their reference numbers
*/
Ptr CellStore::searchExact (const unsigned int refNum, const unsigned int mpNum)
{
// Ensure that all objects searched for have a valid reference number
if (refNum == 0 && mpNum == 0)
return 0;
SearchExactVisitor searchVisitor(refNum, mpNum);
forEach(searchVisitor);
return searchVisitor.mFound;
}
/*
End of tes3mp addition
*/
/*
Start of tes3mp addition
Allow the searching of objects by their reference numbers while ensuring
they have a certain refId
*/
Ptr CellStore::searchExactPlus(const std::string refId, const unsigned int refNum, const unsigned int mpNum)
Ptr CellStore::searchExact (const unsigned int refNum, const unsigned int mpNum, const std::string refId)
{
// Ensure that all objects searched for have a valid reference number
if (refNum == 0 && mpNum == 0)
return 0;
SearchExactPlusVisitor searchVisitor(refId, refNum, mpNum);
SearchExactVisitor searchVisitor(refNum, mpNum, refId);
forEach(searchVisitor);
return searchVisitor.mFound;
}

@ -262,20 +262,10 @@ namespace MWWorld
/*
Start of tes3mp addition
Allow the searching of objects by their reference numbers
Allow the searching of objects by their reference numbers and, optionally,
their refIds
*/
Ptr searchExact (unsigned int refNum, unsigned int mpNum);
/*
End of tes3mp addition
*/
/*
Start of tes3mp addition
Allow the searching of objects by their reference numbers while ensuring
they have a certain refId
*/
Ptr searchExactPlus (std::string refId, unsigned int refNum, unsigned int mpNum);
Ptr searchExact (unsigned int refNum, unsigned int mpNum, std::string refId = "");
/*
End of tes3mp addition
*/

@ -26,7 +26,7 @@ namespace mwmp
struct BaseObject
{
std::string refId;
std::string refId = "";
unsigned int refNum;
unsigned int mpNum;
int count;

Loading…
Cancel
Save